idx int64 0 41.2k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
27,600 | public OptionalDouble average ( ) { long count = 0 ; double sum = 0d ; while ( iterator . hasNext ( ) ) { sum += iterator . nextDouble ( ) ; count ++ ; } if ( count == 0 ) return OptionalDouble . empty ( ) ; return OptionalDouble . of ( sum / ( double ) count ) ; } | Returns the average of elements in this stream . |
27,601 | public void close ( ) { if ( params != null && params . closeHandler != null ) { params . closeHandler . run ( ) ; params . closeHandler = null ; } } | Causes close handler to be invoked if it exists . Since most of the stream providers are lists or arrays it is not necessary to close the stream . |
27,602 | public static IntStream of ( final int ... values ) { Objects . requireNonNull ( values ) ; if ( values . length == 0 ) { return IntStream . empty ( ) ; } return new IntStream ( new IntArray ( values ) ) ; } | Returns stream whose elements are the specified values . |
27,603 | public static IntStream concat ( final IntStream a , final IntStream b ) { Objects . requireNonNull ( a ) ; Objects . requireNonNull ( b ) ; IntStream result = new IntStream ( new IntConcat ( a . iterator , b . iterator ) ) ; return result . onClose ( Compose . closeables ( a , b ) ) ; } | Creates a lazily concatenated stream whose elements are all the elements of the first stream followed by all the elements of the second stream . |
27,604 | public < R > R custom ( final Function < IntStream , R > function ) { Objects . requireNonNull ( function ) ; return function . apply ( this ) ; } | Applies custom operator on stream . |
27,605 | public IntStream filterNot ( final IntPredicate predicate ) { return filter ( IntPredicate . Util . negate ( predicate ) ) ; } | Returns a stream consisting of the elements of this stream that don t match the given predicate . |
27,606 | public IntStream peek ( final IntConsumer action ) { return new IntStream ( params , new IntPeek ( iterator , action ) ) ; } | Returns a stream consisting of the elements of this stream additionally performing the provided action on each element as elements are consumed from the resulting stream . Handy method for debugging purposes . |
27,607 | public static < F , S , R > Stream < R > zip ( final Iterator < ? extends F > iterator1 , final Iterator < ? extends S > iterator2 , final BiFunction < ? super F , ? super S , ? extends R > combiner ) { Objects . requireNonNull ( iterator1 ) ; Objects . requireNonNull ( iterator2 ) ; return new Stream < R > ( new ObjZi... | Combines two iterators to a stream by applying specified combiner function to each element at same position . |
27,608 | public Stream < T > dropWhile ( final Predicate < ? super T > predicate ) { return new Stream < T > ( params , new ObjDropWhile < T > ( iterator , predicate ) ) ; } | Drops elements while the predicate is true then returns the rest . |
27,609 | public void forEach ( final Consumer < ? super T > action ) { while ( iterator . hasNext ( ) ) { action . accept ( iterator . next ( ) ) ; } } | Performs the given action on each element . |
27,610 | public Object [ ] toArray ( ) { return toArray ( new IntFunction < Object [ ] > ( ) { public Object [ ] apply ( int value ) { return new Object [ value ] ; } } ) ; } | Collects elements to an array . |
27,611 | private static int [ ] getHijrahDateInfo ( long gregorianDays ) { int era , year , month , date , dayOfWeek , dayOfYear ; int cycleNumber , yearInCycle , dayOfCycle ; long epochDay = gregorianDays - HIJRAH_JAN_1_1_GREGORIAN_DAY ; if ( epochDay >= 0 ) { cycleNumber = getCycleNumber ( epochDay ) ; dayOfCycle = getDayOfCy... | Returns the int array containing the following field from the julian day . |
27,612 | private static long getGregorianEpochDay ( int prolepticYear , int monthOfYear , int dayOfMonth ) { long day = yearToGregorianEpochDay ( prolepticYear ) ; day += getMonthDays ( monthOfYear - 1 , prolepticYear ) ; day += dayOfMonth ; return day ; } | Return Gregorian epoch day from Hijrah year month and day . |
27,613 | private static long yearToGregorianEpochDay ( int prolepticYear ) { int cycleNumber = ( prolepticYear - 1 ) / 30 ; int yearInCycle = ( prolepticYear - 1 ) % 30 ; int dayInCycle = getAdjustedCycle ( cycleNumber ) [ Math . abs ( yearInCycle ) ] . intValue ( ) ; if ( yearInCycle < 0 ) { dayInCycle = - dayInCycle ; } Long ... | Returns the Gregorian epoch day from the proleptic year |
27,614 | private static int getCycleNumber ( long epochDay ) { Long [ ] days = ADJUSTED_CYCLES ; int cycleNumber ; try { for ( int i = 0 ; i < days . length ; i ++ ) { if ( epochDay < days [ i ] . longValue ( ) ) { return i - 1 ; } } cycleNumber = ( int ) epochDay / 10631 ; } catch ( ArrayIndexOutOfBoundsException e ) { cycleNu... | Returns the 30 year cycle number from the epoch day . |
27,615 | private static int getDayOfCycle ( long epochDay , int cycleNumber ) { Long day ; try { day = ADJUSTED_CYCLES [ cycleNumber ] ; } catch ( ArrayIndexOutOfBoundsException e ) { day = null ; } if ( day == null ) { day = Long . valueOf ( cycleNumber * 10631 ) ; } return ( int ) ( epochDay - day . longValue ( ) ) ; } | Returns day of cycle from the epoch day and cycle number . |
27,616 | private static int getYearInCycle ( int cycleNumber , long dayOfCycle ) { Integer [ ] cycles = getAdjustedCycle ( cycleNumber ) ; if ( dayOfCycle == 0 ) { return 0 ; } if ( dayOfCycle > 0 ) { for ( int i = 0 ; i < cycles . length ; i ++ ) { if ( dayOfCycle < cycles [ i ] . intValue ( ) ) { return i - 1 ; } } return 29 ... | Returns the year in cycle from the cycle number and day of cycle . |
27,617 | private static Integer [ ] getAdjustedCycle ( int cycleNumber ) { Integer [ ] cycles ; try { cycles = ADJUSTED_CYCLE_YEARS . get ( Integer . valueOf ( cycleNumber ) ) ; } catch ( ArrayIndexOutOfBoundsException e ) { cycles = null ; } if ( cycles == null ) { cycles = DEFAULT_CYCLE_YEARS ; } return cycles ; } | Returns adjusted 30 year cycle startind day as Integer array from the cycle number specified . |
27,618 | private static Integer [ ] getAdjustedMonthDays ( int year ) { Integer [ ] newMonths ; try { newMonths = ADJUSTED_MONTH_DAYS . get ( Integer . valueOf ( year ) ) ; } catch ( ArrayIndexOutOfBoundsException e ) { newMonths = null ; } if ( newMonths == null ) { if ( isLeapYear ( year ) ) { newMonths = DEFAULT_LEAP_MONTH_D... | Returns adjusted month days as Integer array form the year specified . |
27,619 | private static Integer [ ] getAdjustedMonthLength ( int year ) { Integer [ ] newMonths ; try { newMonths = ADJUSTED_MONTH_LENGTHS . get ( Integer . valueOf ( year ) ) ; } catch ( ArrayIndexOutOfBoundsException e ) { newMonths = null ; } if ( newMonths == null ) { if ( isLeapYear ( year ) ) { newMonths = DEFAULT_LEAP_MO... | Returns adjusted month length as Integer array form the year specified . |
27,620 | private static int getDayOfYear ( int cycleNumber , int dayOfCycle , int yearInCycle ) { Integer [ ] cycles = getAdjustedCycle ( cycleNumber ) ; if ( dayOfCycle > 0 ) { return dayOfCycle - cycles [ yearInCycle ] . intValue ( ) ; } else { return cycles [ yearInCycle ] . intValue ( ) + dayOfCycle ; } } | Returns day - of - year . |
27,621 | private static int getMonthOfYear ( int dayOfYear , int year ) { Integer [ ] newMonths = getAdjustedMonthDays ( year ) ; if ( dayOfYear >= 0 ) { for ( int i = 0 ; i < newMonths . length ; i ++ ) { if ( dayOfYear < newMonths [ i ] . intValue ( ) ) { return i - 1 ; } } return 11 ; } else { dayOfYear = ( isLeapYear ( year... | Returns month - of - year . 0 - based . |
27,622 | private static int getDayOfMonth ( int dayOfYear , int month , int year ) { Integer [ ] newMonths = getAdjustedMonthDays ( year ) ; if ( dayOfYear >= 0 ) { if ( month > 0 ) { return dayOfYear - newMonths [ month ] . intValue ( ) ; } else { return dayOfYear ; } } else { dayOfYear = ( isLeapYear ( year ) ? ( dayOfYear + ... | Returns day - of - month . |
27,623 | private static int getMonthDays ( int month , int year ) { Integer [ ] newMonths = getAdjustedMonthDays ( year ) ; return newMonths [ month ] . intValue ( ) ; } | Returns month days from the beginning of year . |
27,624 | static int getMonthLength ( int month , int year ) { Integer [ ] newMonths = getAdjustedMonthLength ( year ) ; return newMonths [ month ] . intValue ( ) ; } | Returns month length . |
27,625 | static int getYearLength ( int year ) { int cycleNumber = ( year - 1 ) / 30 ; Integer [ ] cycleYears ; try { cycleYears = ADJUSTED_CYCLE_YEARS . get ( cycleNumber ) ; } catch ( ArrayIndexOutOfBoundsException e ) { cycleYears = null ; } if ( cycleYears != null ) { int yearInCycle = ( year - 1 ) % 30 ; if ( yearInCycle =... | Returns year length . |
27,626 | private static void readDeviationConfig ( ) throws IOException , ParseException { InputStream is = getConfigFileInputStream ( ) ; if ( is != null ) { BufferedReader br = null ; try { br = new BufferedReader ( new InputStreamReader ( is ) ) ; String line = "" ; int num = 0 ; while ( ( line = br . readLine ( ) ) != null ... | Read hijrah_deviation . cfg file . The config file contains the deviation data with following format . |
27,627 | private boolean load ( ClassLoader classLoader ) { boolean updated = false ; URL url = null ; try { Enumeration < URL > en = classLoader . getResources ( "org/threeten/bp/TZDB.dat" ) ; while ( en . hasMoreElements ( ) ) { url = en . nextElement ( ) ; updated |= load ( url ) ; } } catch ( Exception ex ) { throw new Zone... | Loads the rules . |
27,628 | private boolean load ( URL url ) throws ClassNotFoundException , IOException , ZoneRulesException { boolean updated = false ; if ( loadedUrls . add ( url . toExternalForm ( ) ) ) { InputStream in = null ; try { in = url . openStream ( ) ; updated |= load ( in ) ; } finally { if ( in != null ) { in . close ( ) ; } } } r... | Loads the rules from a URL often in a jar file . |
27,629 | static void initialize ( ) { if ( INITIALIZED . getAndSet ( true ) ) { throw new IllegalStateException ( "Already initialized" ) ; } INITIALIZER . compareAndSet ( null , new ServiceLoaderZoneRulesInitializer ( ) ) ; INITIALIZER . get ( ) . initializeProviders ( ) ; } | initialize the providers |
27,630 | private static void outputHelp ( ) { System . out . println ( "Usage: TzdbZoneRulesCompiler <options> <tzdb source filenames>" ) ; System . out . println ( "where options include:" ) ; System . out . println ( " -srcdir <directory> Where to find source directories (required)" ) ; System . out . println ( " -dstdi... | Output usage text for the command line . |
27,631 | private static void outputFilesDat ( File dstDir , Map < String , SortedMap < String , ZoneRules > > allBuiltZones , Set < String > allRegionIds , Set < ZoneRules > allRules , SortedMap < LocalDate , Byte > leapSeconds ) { File tzdbFile = new File ( dstDir , "TZDB.dat" ) ; tzdbFile . delete ( ) ; try { FileOutputStream... | Outputs the DAT files . |
27,632 | private static void outputTzdbEntry ( JarOutputStream jos , Map < String , SortedMap < String , ZoneRules > > allBuiltZones , Set < String > allRegionIds , Set < ZoneRules > allRules ) { try { jos . putNextEntry ( new ZipEntry ( "org/threeten/bp/TZDB.dat" ) ) ; outputTzdbDat ( jos , allBuiltZones , allRegionIds , allRu... | Outputs the timezone entry in the JAR file . |
27,633 | private static void outputTzdbDat ( OutputStream jos , Map < String , SortedMap < String , ZoneRules > > allBuiltZones , Set < String > allRegionIds , Set < ZoneRules > allRules ) throws IOException { DataOutputStream out = new DataOutputStream ( jos ) ; out . writeByte ( 1 ) ; out . writeUTF ( "TZDB" ) ; String [ ] ve... | Outputs the timezone DAT file . |
27,634 | private void parseLeapSecondsFile ( ) throws Exception { printVerbose ( "Parsing leap second file: " + leapSecondsFile ) ; int lineNumber = 1 ; String line = null ; BufferedReader in = null ; try { in = new BufferedReader ( new FileReader ( leapSecondsFile ) ) ; for ( ; ( line = in . readLine ( ) ) != null ; lineNumber... | Parses the leap seconds file . |
27,635 | private void parseFile ( File file ) throws Exception { int lineNumber = 1 ; String line = null ; BufferedReader in = null ; try { in = new BufferedReader ( new FileReader ( file ) ) ; List < TZDBZone > openZone = null ; for ( ; ( line = in . readLine ( ) ) != null ; lineNumber ++ ) { int index = line . indexOf ( '#' )... | Parses a source file . |
27,636 | private boolean parseZoneLine ( StringTokenizer st , List < TZDBZone > zoneList ) { TZDBZone zone = new TZDBZone ( ) ; zoneList . add ( zone ) ; zone . standardOffset = parseOffset ( st . nextToken ( ) ) ; String savingsRule = parseOptional ( st . nextToken ( ) ) ; if ( savingsRule == null ) { zone . fixedSavingsSecs =... | Parses a Zone line . |
27,637 | private void buildZoneRules ( ) throws Exception { for ( String zoneId : zones . keySet ( ) ) { printVerbose ( "Building zone " + zoneId ) ; zoneId = deduplicate ( zoneId ) ; List < TZDBZone > tzdbZones = zones . get ( zoneId ) ; ZoneRulesBuilder bld = new ZoneRulesBuilder ( ) ; for ( TZDBZone tzdbZone : tzdbZones ) { ... | Build the rules zones and links into real zones . |
27,638 | @ SuppressWarnings ( "unchecked" ) < T > T deduplicate ( T object ) { if ( deduplicateMap . containsKey ( object ) == false ) { deduplicateMap . put ( object , object ) ; } return ( T ) deduplicateMap . get ( object ) ; } | Deduplicates an object instance . |
27,639 | static < R extends ChronoLocalDate > ChronoZonedDateTime < R > ofBest ( ChronoLocalDateTimeImpl < R > localDateTime , ZoneId zone , ZoneOffset preferredOffset ) { Jdk8Methods . requireNonNull ( localDateTime , "localDateTime" ) ; Jdk8Methods . requireNonNull ( zone , "zone" ) ; if ( zone instanceof ZoneOffset ) { retur... | Obtains an instance from a local date - time using the preferred offset if possible . |
27,640 | static < R extends ChronoLocalDate > ChronoZonedDateTimeImpl < R > ofInstant ( Chronology chrono , Instant instant , ZoneId zone ) { ZoneRules rules = zone . getRules ( ) ; ZoneOffset offset = rules . getOffset ( instant ) ; Jdk8Methods . requireNonNull ( offset , "offset" ) ; LocalDateTime ldt = LocalDateTime . ofEpoc... | Obtains an instance from an instant using the specified time - zone . |
27,641 | public ChronoLocalDate date ( Era era , int yearOfEra , int month , int dayOfMonth ) { return date ( prolepticYear ( era , yearOfEra ) , month , dayOfMonth ) ; } | Obtains a local date in this chronology from the era year - of - era month - of - year and day - of - month fields . |
27,642 | public ChronoLocalDate dateYearDay ( Era era , int yearOfEra , int dayOfYear ) { return dateYearDay ( prolepticYear ( era , yearOfEra ) , dayOfYear ) ; } | Obtains a local date in this chronology from the era year - of - era and day - of - year fields . |
27,643 | void updateResolveMap ( Map < TemporalField , Long > fieldValues , ChronoField field , long value ) { Long current = fieldValues . get ( field ) ; if ( current != null && current . longValue ( ) != value ) { throw new DateTimeException ( "Invalid state, field: " + field + " " + current + " conflicts with " + field + " ... | Updates the map of field - values during resolution . |
27,644 | private DateTimeFormatterBuilder appendValue ( NumberPrinterParser pp ) { if ( active . valueParserIndex >= 0 && active . printerParsers . get ( active . valueParserIndex ) instanceof NumberPrinterParser ) { final int activeValueParser = active . valueParserIndex ; NumberPrinterParser basePP = ( NumberPrinterParser ) a... | Appends a fixed width printer - parser . |
27,645 | private static void registerProvider0 ( ZoneRulesProvider provider ) { for ( String zoneId : provider . provideZoneIds ( ) ) { Jdk8Methods . requireNonNull ( zoneId , "zoneId" ) ; ZoneRulesProvider old = ZONES . putIfAbsent ( zoneId , provider ) ; if ( old != null ) { throw new ZoneRulesException ( "Unable to register ... | Registers the provider . |
27,646 | private void readObject ( ObjectInputStream stream ) throws IOException , ClassNotFoundException { stream . defaultReadObject ( ) ; this . era = JapaneseEra . from ( isoDate ) ; int yearOffset = this . era . startDate ( ) . getYear ( ) - 1 ; this . yearOfEra = isoDate . getYear ( ) - yearOffset ; } | Reconstitutes this object from a stream . |
27,647 | private static LocalDate resolvePreviousValid ( int year , int month , int day ) { switch ( month ) { case 2 : day = Math . min ( day , IsoChronology . INSTANCE . isLeapYear ( year ) ? 29 : 28 ) ; break ; case 4 : case 6 : case 9 : case 11 : day = Math . min ( day , 30 ) ; break ; } return LocalDate . of ( year , month... | Resolves the date resolving days past the end of month . |
27,648 | LocalDate endDate ( ) { int ordinal = ordinal ( eraValue ) ; JapaneseEra [ ] eras = values ( ) ; if ( ordinal >= eras . length - 1 ) { return LocalDate . MAX ; } return eras [ ordinal + 1 ] . startDate ( ) . minusDays ( 1 ) ; } | Returns the end date of the era . |
27,649 | public static < T > T requireNonNull ( T value , String parameterName ) { if ( value == null ) { throw new NullPointerException ( parameterName + " must not be null" ) ; } return value ; } | Ensures that the argument is non - null . |
27,650 | public static int safeAdd ( int a , int b ) { int sum = a + b ; if ( ( a ^ sum ) < 0 && ( a ^ b ) >= 0 ) { throw new ArithmeticException ( "Addition overflows an int: " + a + " + " + b ) ; } return sum ; } | Safely adds two int values . |
27,651 | public static int safeSubtract ( int a , int b ) { int result = a - b ; if ( ( a ^ result ) < 0 && ( a ^ b ) < 0 ) { throw new ArithmeticException ( "Subtraction overflows an int: " + a + " - " + b ) ; } return result ; } | Safely subtracts one int from another . |
27,652 | public static int safeMultiply ( int a , int b ) { long total = ( long ) a * ( long ) b ; if ( total < Integer . MIN_VALUE || total > Integer . MAX_VALUE ) { throw new ArithmeticException ( "Multiplication overflows an int: " + a + " * " + b ) ; } return ( int ) total ; } | Safely multiply one int by another . |
27,653 | public static long safeMultiply ( long a , int b ) { switch ( b ) { case - 1 : if ( a == Long . MIN_VALUE ) { throw new ArithmeticException ( "Multiplication overflows a long: " + a + " * " + b ) ; } return - a ; case 0 : return 0L ; case 1 : return a ; } long total = a * b ; if ( total / b != a ) { throw new Arithmeti... | Safely multiply a long by an int . |
27,654 | public static int safeToInt ( long value ) { if ( value > Integer . MAX_VALUE || value < Integer . MIN_VALUE ) { throw new ArithmeticException ( "Calculation overflows an int: " + value ) ; } return ( int ) value ; } | Safely convert a long to an int . |
27,655 | public AqlQueryOptions shardIds ( final String ... shardIds ) { getOptions ( ) . getShardIds ( ) . addAll ( Arrays . asList ( shardIds ) ) ; return this ; } | Restrict query to shards by given ids . This is an internal option . Use at your own risk . |
27,656 | public static boolean verifySignature ( byte [ ] publicKey , byte [ ] message , byte [ ] signature ) { return curve_sigs . curve25519_verify ( SHA512Provider , signature , publicKey , message , message . length ) == 0 ; } | Verification of signature |
27,657 | @ ObjectiveCName ( "isLargeDialogMessage:" ) public boolean isLargeDialogMessage ( ContentType contentType ) { switch ( contentType ) { case SERVICE : case SERVICE_AVATAR : case SERVICE_AVATAR_REMOVED : case SERVICE_CREATED : case SERVICE_TITLE : case SERVICE_LEAVE : case SERVICE_REGISTERED : case SERVICE_KICK : case S... | If Dialog List message need to be wide in group chat as it is already includes performer in it s body . |
27,658 | @ ObjectiveCName ( "formatNotificationText:" ) public String formatNotificationText ( Notification pendingNotification ) { return formatContentText ( pendingNotification . getSender ( ) , pendingNotification . getContentDescription ( ) . getContentType ( ) , pendingNotification . getContentDescription ( ) . getText ( )... | Formatting Pending notification text |
27,659 | @ ObjectiveCName ( "formatContentTextWithSenderId:withContentType:withText:withRelatedUid:withIsChannel:" ) public String formatContentText ( int senderId , ContentType contentType , String text , int relatedUid , boolean isChannel ) { String groupKey = isChannel ? "channels" : "groups" ; switch ( contentType ) { case ... | Formatting content for Dialog List and Notifications |
27,660 | @ ObjectiveCName ( "formatFullServiceMessageWithSenderId:withContent:withIsChannel:" ) public String formatFullServiceMessage ( int senderId , ServiceContent content , boolean isChannel ) { String groupKey = isChannel ? "channels" : "groups" ; if ( content instanceof ServiceUserRegistered ) { return getTemplateNamed ( ... | Formatting Service Content |
27,661 | @ ObjectiveCName ( "formatMessagesExport:" ) public String formatMessagesExport ( Message [ ] messages ) { String text = "" ; Arrays . sort ( messages , new Comparator < Message > ( ) { int compare ( long lhs , long rhs ) { return lhs < rhs ? - 1 : ( lhs == rhs ? 0 : 1 ) ; } public int compare ( Message lhs , Message r... | Formatting messages for exporting |
27,662 | public boolean moveToFirst ( ) { try { return resultSet . first ( ) ; } catch ( SQLException e ) { logger . error ( e . getMessage ( ) , e ) ; } return false ; } | We can t use this method in sqlite jdbc driver |
27,663 | public Promise < Void > replaceOwnStream ( CountedReference < WebRTCMediaStream > stream ) { return ask ( new PeerNodeActor . ReplaceOwnStream ( stream . acquire ( ) ) ) ; } | Call this method to set own stream |
27,664 | public void onCandidate ( long sessionId , int index , String id , String sdp ) { send ( new RTCCandidate ( deviceId , sessionId , index , id , sdp ) ) ; } | Call this method when new candidate is received |
27,665 | public Promise < Void > replaceStream ( CountedReference < WebRTCMediaStream > mediaStream ) { return ask ( new PeerConnectionActor . ReplaceStream ( mediaStream . acquire ( ) ) ) ; } | Replace Current outgoing stream |
27,666 | public void onCandidate ( long sessionId , int index , String id , String sdp ) { send ( new PeerConnectionActor . OnCandidate ( sessionId , index , id , sdp ) ) ; } | Call this method when new candidate arrived from other peer |
27,667 | public void reset ( ) { super . reset ( ) ; H1 = 0x67452301 ; H2 = 0xefcdab89 ; H3 = 0x98badcfe ; H4 = 0x10325476 ; xOff = 0 ; for ( int i = 0 ; i != X . length ; i ++ ) { X [ i ] = 0 ; } } | reset the chaining variables to the IV values . |
27,668 | @ SuppressWarnings ( "unchecked" ) public static < T > PromisesArray < T > of ( Collection < T > collection ) { final ArrayList < Promise < T > > res = new ArrayList < > ( ) ; for ( T t : collection ) { res . add ( Promise . success ( t ) ) ; } final Promise [ ] promises = res . toArray ( new Promise [ res . size ( ) ]... | Create PromisesArray from collection |
27,669 | public static < T > PromisesArray < T > of ( T ... items ) { ArrayList < Promise < T > > res = new ArrayList < > ( ) ; for ( T t : items ) { res . add ( Promise . success ( t ) ) ; } final Promise [ ] promises = res . toArray ( new Promise [ res . size ( ) ] ) ; return new PromisesArray < > ( ( PromiseFunc < Promise < ... | Create PromisesArray from values |
27,670 | public static < T > PromisesArray < T > ofPromises ( Promise < T > ... items ) { ArrayList < Promise < T > > res = new ArrayList < > ( ) ; Collections . addAll ( res , items ) ; final Promise [ ] promises = res . toArray ( new Promise [ res . size ( ) ] ) ; return new PromisesArray < > ( ( PromiseFunc < Promise < T > [... | Create PromisesArray from multiple Promise |
27,671 | public < R > PromisesArray < R > map ( final Function < T , Promise < R > > fun ) { return mapSourcePromises ( srcPromise -> new Promise < R > ( resolver -> { srcPromise . then ( t -> { Promise < R > mapped = fun . apply ( t ) ; mapped . then ( t2 -> resolver . result ( t2 ) ) ; mapped . failure ( e -> resolver . error... | Map promises results to new promises |
27,672 | public < R > Promise < R > zipPromise ( final ListFunction < T , Promise < R > > fuc ) { return new Promise < > ( resolver -> { promises . then ( promises1 -> { final ArrayList < T > res = new ArrayList < T > ( ) ; for ( int i = 0 ; i < promises1 . length ; i ++ ) { res . add ( null ) ; } final Boolean [ ] ended = new ... | Zip array to single promise |
27,673 | @ ObjectiveCName ( "subscribeWithListener:notify:" ) public void subscribe ( ValueChangedListener < T > listener , boolean notify ) { if ( listeners . contains ( listener ) ) { return ; } listeners . add ( listener ) ; if ( notify ) { listener . onChanged ( get ( ) , this ) ; } } | Subscribe to value updates |
27,674 | protected void notifyInMainThread ( final T value ) { for ( ValueChangedListener < T > listener : listeners ) { listener . onChanged ( value , Value . this ) ; } } | Performing notification to subscribers if we know that we are on mainthread Useful for chainging updates from chain of values |
27,675 | private static void applyOpenSSLFix ( ) throws SecurityException { if ( ( Build . VERSION . SDK_INT < VERSION_CODE_JELLY_BEAN ) || ( Build . VERSION . SDK_INT > VERSION_CODE_JELLY_BEAN_MR2 ) ) { return ; } try { Class . forName ( "org.apache.harmony.xnet.provider.jsse.NativeCrypto" ) . getMethod ( "RAND_seed" , byte [ ... | Applies the fix for OpenSSL PRNG having low entropy . Does nothing if the fix is not needed . |
27,676 | private static byte [ ] generateSeed ( ) { try { ByteArrayOutputStream seedBuffer = new ByteArrayOutputStream ( ) ; DataOutputStream seedBufferOut = new DataOutputStream ( seedBuffer ) ; seedBufferOut . writeLong ( System . currentTimeMillis ( ) ) ; seedBufferOut . writeLong ( System . nanoTime ( ) ) ; seedBufferOut . ... | Generates a device - and invocation - specific seed to be mixed into the Linux PRNG . |
27,677 | private static String getDeviceSerialNumber ( ) { try { return ( String ) Build . class . getField ( "SERIAL" ) . get ( null ) ; } catch ( Exception ignored ) { return null ; } } | Gets the hardware serial number of this device . |
27,678 | public void performPersistCursorRequest ( String name , long key , Request request ) { persistentRequests . send ( new PersistentRequestsActor . PerformCursorRequest ( name , key , request ) ) ; } | Perform cursor persist request . Request is performed only if key is bigger than previous request with same name |
27,679 | public static void fill ( byte [ ] a , byte val ) { for ( int i = 0 , len = a . length ; i < len ; i ++ ) a [ i ] = val ; } | Assigns the specified byte value to each element of the specified array of bytes . |
27,680 | public void scheduleFirst ( Envelope envelope ) { if ( envelope . getMailbox ( ) != this ) { throw new RuntimeException ( "envelope.mailbox != this mailbox" ) ; } queueCollection . post ( queueId , envelope , true ) ; } | Send envelope first |
27,681 | private static int [ ] make_crc_table ( ) { int [ ] crc_table = new int [ 256 ] ; for ( int n = 0 ; n < 256 ; n ++ ) { int c = n ; for ( int k = 8 ; -- k >= 0 ; ) { if ( ( c & 1 ) != 0 ) c = 0xedb88320 ^ ( c >>> 1 ) ; else c = c >>> 1 ; } crc_table [ n ] = c ; } return crc_table ; } | Make the table for a fast CRC . |
27,682 | public void update ( int bval ) { int c = ~ crc ; c = crc_table [ ( c ^ bval ) & 0xff ] ^ ( c >>> 8 ) ; crc = ~ c ; } | Updates the checksum with the int bval . |
27,683 | public void update ( byte [ ] buf , int off , int len ) { int c = ~ crc ; while ( -- len >= 0 ) c = crc_table [ ( c ^ buf [ off ++ ] ) & 0xff ] ^ ( c >>> 8 ) ; crc = ~ c ; } | Adds the byte array to the data checksum . |
27,684 | public void end ( ) { if ( this . sectionName != null ) { Log . d ( TAG , "" + this . sectionName + " loaded in " + ( ActorTime . currentTime ( ) - sectionStart ) + " ms" ) ; this . sectionName = null ; } } | Mark section end |
27,685 | public static void startProfileActivity ( Context context , int uid ) { if ( context == null ) { return ; } Bundle b = new Bundle ( ) ; b . putInt ( Intents . EXTRA_UID , uid ) ; startActivity ( context , b , ProfileActivity . class ) ; } | Launch User Profile Activity |
27,686 | private View findFirstVisibleChildClosestToStart ( boolean completelyVisible , boolean acceptPartiallyVisible ) { if ( mShouldReverseLayout ) { return findOneVisibleChild ( getChildCount ( ) - 1 , - 1 , completelyVisible , acceptPartiallyVisible ) ; } else { return findOneVisibleChild ( 0 , getChildCount ( ) , complete... | Convenience method to find the visible child closes to start . Caller should check if it has enough children . |
27,687 | private View findFirstVisibleChildClosestToEnd ( boolean completelyVisible , boolean acceptPartiallyVisible ) { if ( mShouldReverseLayout ) { return findOneVisibleChild ( 0 , getChildCount ( ) , completelyVisible , acceptPartiallyVisible ) ; } else { return findOneVisibleChild ( getChildCount ( ) - 1 , - 1 , completely... | Convenience method to find the visible child closes to end . Caller should check if it has enough children . |
27,688 | private VideoCapturer getVideoCapturer ( ) { String [ ] cameraFacing = { "front" , "back" } ; int [ ] cameraIndex = { 0 , 1 } ; int [ ] cameraOrientation = { 0 , 90 , 180 , 270 } ; for ( String facing : cameraFacing ) { for ( int index : cameraIndex ) { for ( int orientation : cameraOrientation ) { String name = "Camer... | capturer that works or crash if none do . |
27,689 | public void onInitialDataDownloaded ( ) { Log . d ( TAG , "Initial Data Loaded" ) ; context ( ) . getContactsModule ( ) . startImport ( ) ; if ( appStateVM . isBookImported ( ) ) { onAppLoaded ( ) ; } } | Called after dialogs contacts and settings are downloaded from server |
27,690 | public void detach ( ) { super . detach ( ) ; modules . getFilesModule ( ) . unbindFile ( location . getFileId ( ) , callback , false ) ; } | Detach FileVM from Messenger . Don t use object after detaching . |
27,691 | public MDDocument processDocument ( String text ) { TextCursor cursor = new TextCursor ( text ) ; ArrayList < MDSection > sections = new ArrayList < MDSection > ( ) ; while ( handleCodeBlock ( cursor , sections ) ) ; return new MDDocument ( sections . toArray ( new MDSection [ sections . size ( ) ] ) ) ; } | Parsing markdown document |
27,692 | private void handleTextBlock ( TextCursor cursor , int blockEnd , ArrayList < MDSection > paragraphs ) { MDText [ ] spans = handleSpans ( cursor , blockEnd ) ; paragraphs . add ( new MDSection ( spans ) ) ; cursor . currentOffset = blockEnd ; } | Processing text blocks between code blocks |
27,693 | private MDText [ ] handleSpans ( TextCursor cursor , int blockEnd ) { ArrayList < MDText > elements = new ArrayList < MDText > ( ) ; while ( handleSpan ( cursor , blockEnd , elements ) ) ; return elements . toArray ( new MDText [ elements . size ( ) ] ) ; } | Processing formatting spans |
27,694 | private void handleRawText ( TextCursor cursor , int limit , ArrayList < MDText > elements ) { while ( true ) { BasicUrl url = findUrl ( cursor , limit ) ; if ( url != null ) { String link = cursor . text . substring ( url . getStart ( ) , url . getEnd ( ) ) ; addText ( cursor , url . getStart ( ) , elements ) ; elemen... | Handling raw text block |
27,695 | private void addText ( TextCursor cursor , int limit , ArrayList < MDText > elements ) { if ( cursor . currentOffset < limit ) { elements . add ( new MDRawText ( cursor . text . substring ( cursor . currentOffset , limit ) ) ) ; cursor . currentOffset = limit ; } } | Adding raw simple text |
27,696 | private int findCodeBlockStart ( TextCursor cursor ) { int offset = cursor . currentOffset ; int index ; while ( ( index = cursor . text . indexOf ( CODE_BLOCK , offset ) ) >= 0 ) { if ( isGoodAnchor ( cursor . text , index - 1 ) ) { return index ; } offset = index + 3 ; } return - 1 ; } | Searching for valid code block begin |
27,697 | private int findCodeBlockEnd ( TextCursor cursor , int blockStart ) { int offset = blockStart + 3 ; int index ; while ( ( index = cursor . text . indexOf ( CODE_BLOCK , offset ) ) >= 0 ) { if ( isGoodAnchor ( cursor . text , index + 3 ) ) { return index + 3 ; } offset = index + 1 ; } return - 1 ; } | Searching for valid code block end |
27,698 | private int findSpanStart ( TextCursor cursor , int limit ) { for ( int i = cursor . currentOffset ; i < limit ; i ++ ) { char c = cursor . text . charAt ( i ) ; if ( c == '*' || c == '_' ) { if ( isGoodAnchor ( cursor . text , i - 1 ) && isNotSymbol ( cursor . text , i + 1 , c ) ) { return i ; } } } return - 1 ; } | Searching for valid formatting span start |
27,699 | private int findSpanEnd ( TextCursor cursor , int spanStart , int limit , char span ) { for ( int i = spanStart + 1 ; i < limit ; i ++ ) { char c = cursor . text . charAt ( i ) ; if ( c == span ) { if ( isGoodAnchor ( cursor . text , i + 1 ) && isNotSymbol ( cursor . text , i - 1 , span ) ) { return i + 1 ; } } } retur... | Searching for valid formatting span end |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.