idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
30,600
public void debug ( String format , Object ... extra ) { if ( shouldLog ( DEBUG ) ) { Log . d ( tag , String . format ( format , extra ) ) ; } }
Log a debug message .
30,601
public AnalyticsContext unmodifiableCopy ( ) { LinkedHashMap < String , Object > map = new LinkedHashMap < > ( this ) ; return new AnalyticsContext ( unmodifiableMap ( map ) ) ; }
Returns an unmodifiable shallow copy of the values in this map .
30,602
void putLibrary ( ) { Map < String , Object > library = createMap ( ) ; library . put ( LIBRARY_NAME_KEY , "analytics-android" ) ; library . put ( LIBRARY_VERSION_KEY , BuildConfig . VERSION_NAME ) ; put ( LIBRARY_KEY , library ) ; }
Fill this instance with library information .
30,603
void putOs ( ) { Map < String , Object > os = createMap ( ) ; os . put ( OS_NAME_KEY , "Android" ) ; os . put ( OS_VERSION_KEY , Build . VERSION . RELEASE ) ; put ( OS_KEY , os ) ; }
Fill this instance with operating system information .
30,604
public synchronized void add ( byte [ ] data , int offset , int count ) throws IOException { if ( data == null ) { throw new NullPointerException ( "data == null" ) ; } if ( ( offset | count ) < 0 || count > data . length - offset ) { throw new IndexOutOfBoundsException ( ) ; } expandIfNecessary ( count ) ; boolean wasEmpty = isEmpty ( ) ; int position = wasEmpty ? HEADER_LENGTH : wrapPosition ( last . position + Element . HEADER_LENGTH + last . length ) ; Element newLast = new Element ( position , count ) ; writeInt ( buffer , 0 , count ) ; ringWrite ( newLast . position , buffer , 0 , Element . HEADER_LENGTH ) ; ringWrite ( newLast . position + Element . HEADER_LENGTH , data , offset , count ) ; int firstPosition = wasEmpty ? newLast . position : first . position ; writeHeader ( fileLength , elementCount + 1 , firstPosition , newLast . position ) ; last = newLast ; elementCount ++ ; if ( wasEmpty ) first = last ; }
Adds an element to the end of the queue .
30,605
public void group ( final String groupId , final Traits groupTraits , final Options options ) { assertNotShutdown ( ) ; if ( isNullOrEmpty ( groupId ) ) { throw new IllegalArgumentException ( "groupId must not be null or empty." ) ; } analyticsExecutor . submit ( new Runnable ( ) { public void run ( ) { final Traits finalGroupTraits ; if ( groupTraits == null ) { finalGroupTraits = new Traits ( ) ; } else { finalGroupTraits = groupTraits ; } final Options finalOptions ; if ( options == null ) { finalOptions = defaultOptions ; } else { finalOptions = options ; } GroupPayload . Builder builder = new GroupPayload . Builder ( ) . groupId ( groupId ) . traits ( finalGroupTraits ) ; fillAndEnqueue ( builder , finalOptions ) ; } } ) ; }
The group method lets you associate a user with a group . It also lets you record custom traits about the group like industry or number of employees .
30,606
public void screen ( final String category , final String name , final Properties properties , final Options options ) { assertNotShutdown ( ) ; if ( isNullOrEmpty ( category ) && isNullOrEmpty ( name ) ) { throw new IllegalArgumentException ( "either category or name must be provided." ) ; } analyticsExecutor . submit ( new Runnable ( ) { public void run ( ) { final Options finalOptions ; if ( options == null ) { finalOptions = defaultOptions ; } else { finalOptions = options ; } final Properties finalProperties ; if ( properties == null ) { finalProperties = EMPTY_PROPERTIES ; } else { finalProperties = properties ; } ScreenPayload . Builder builder = new ScreenPayload . Builder ( ) . name ( name ) . category ( category ) . properties ( finalProperties ) ; fillAndEnqueue ( builder , finalOptions ) ; } } ) ; }
The screen methods let your record whenever a user sees a screen of your mobile app and attach a name category or properties to the screen . Either category or name must be provided .
30,607
public void alias ( final String newId , final Options options ) { assertNotShutdown ( ) ; if ( isNullOrEmpty ( newId ) ) { throw new IllegalArgumentException ( "newId must not be null or empty." ) ; } analyticsExecutor . submit ( new Runnable ( ) { public void run ( ) { final Options finalOptions ; if ( options == null ) { finalOptions = defaultOptions ; } else { finalOptions = options ; } AliasPayload . Builder builder = new AliasPayload . Builder ( ) . userId ( newId ) . previousId ( analyticsContext . traits ( ) . currentId ( ) ) ; fillAndEnqueue ( builder , finalOptions ) ; } } ) ; }
The alias method is used to merge two user identities effectively connecting two sets of user data as one . This is an advanced method but it is required to manage user identities successfully in some of our integrations .
30,608
public void reset ( ) { Utils . getSegmentSharedPreferences ( application , tag ) . edit ( ) . clear ( ) . apply ( ) ; traitsCache . delete ( ) ; traitsCache . set ( Traits . create ( ) ) ; analyticsContext . setTraits ( traitsCache . get ( ) ) ; runOnMainThread ( IntegrationOperation . RESET ) ; }
Resets the analytics client by clearing any stored information about the user . Events queued on disk are not cleared and will be uploaded at a later time .
30,609
public < T > void onIntegrationReady ( final String key , final Callback < T > callback ) { if ( isNullOrEmpty ( key ) ) { throw new IllegalArgumentException ( "key cannot be null or empty." ) ; } analyticsExecutor . submit ( new Runnable ( ) { public void run ( ) { HANDLER . post ( new Runnable ( ) { public void run ( ) { performCallback ( key , callback ) ; } } ) ; } } ) ; }
Register to be notified when a bundled integration is ready .
30,610
void performRun ( IntegrationOperation operation ) { for ( Map . Entry < String , Integration < ? > > entry : integrations . entrySet ( ) ) { String key = entry . getKey ( ) ; long startTime = System . nanoTime ( ) ; operation . run ( key , entry . getValue ( ) , projectSettings ) ; long endTime = System . nanoTime ( ) ; long durationInMillis = TimeUnit . NANOSECONDS . toMillis ( endTime - startTime ) ; stats . dispatchIntegrationOperation ( key , durationInMillis ) ; logger . debug ( "Ran %s on integration %s in %d ns." , operation , key , endTime - startTime ) ; } }
Runs the given operation on all integrations .
30,611
public Properties putProducts ( Product ... products ) { if ( isNullOrEmpty ( products ) ) { throw new IllegalArgumentException ( "products cannot be null or empty." ) ; } List < Product > productList = new ArrayList < > ( products . length ) ; Collections . addAll ( productList , products ) ; return putValue ( PRODUCTS_KEY , Collections . unmodifiableList ( productList ) ) ; }
Set the individual products for an order associated with an event .
30,612
static boolean parseAvailableResult ( List < String > stdout , boolean checkForRoot ) { if ( stdout == null ) { return false ; } boolean echoSeen = false ; for ( String line : stdout ) { if ( line . contains ( "uid=" ) ) { return ! checkForRoot || line . contains ( "uid=0" ) ; } else if ( line . contains ( "-BOC-" ) ) { echoSeen = true ; } } return echoSeen ; }
See if the shell is alive and if so check the UID
30,613
public static < E , C extends Collection < E > > SynchronizedMutableCollection < E > of ( C collection ) { return new SynchronizedMutableCollection < E > ( CollectionAdapter . adapt ( collection ) ) ; }
This method will take a MutableCollection and wrap it directly in a SynchronizedMutableCollection . It will take any other non - GS - collection and first adapt it will a CollectionAdapter and then return a SynchronizedMutableCollection that wraps the adapter .
30,614
protected void defaultSort ( Comparator < ? super E > comparator ) { FastList < E > list = comparator == null ? ( FastList < E > ) this . toSortedList ( ) : ( FastList < E > ) this . toSortedList ( comparator ) ; this . lists . clear ( ) ; this . lists . add ( list ) ; }
Override in subclasses where it can be optimized .
30,615
public static < T , V > Function < T , V > cast ( Function < T , V > function ) { return function ; }
Allows a Java 8 lambda and method reference to be used in a method taking a Function as a parameter without any ambiguity .
30,616
public static < S , T > Function < Pair < S , T > , Pair < T , S > > swappedPair ( ) { return ( Function < Pair < S , T > , Pair < T , S > > ) ( Function < ? , ? > ) SWAPPED_PAIR_FUNCTION ; }
Swap the input pair and return the swapped pair .
30,617
public static < T , P , R > Function < T , R > bind ( Function2 < ? super T , ? super P , ? extends R > function , P parameter ) { return new BindFunction2 < T , P , R > ( function , parameter ) ; }
Bind the parameter passed to a Function2 into a new Function .
30,618
public static < T1 , T2 > Procedure < T1 > bind ( Procedure < ? super T2 > delegate , Function < ? super T1 , T2 > function ) { return new BindProcedure < T1 , T2 > ( delegate , function ) ; }
Bind the input of a Procedure to the result of an function returning a new Procedure .
30,619
public static < T1 , T2 > ObjectIntProcedure < T1 > bind ( ObjectIntProcedure < ? super T2 > delegate , Function < ? super T1 , T2 > function ) { return new BindObjectIntProcedure < T1 , T2 > ( delegate , function ) ; }
Bind the input of a ObjectIntProcedure to the result of an function returning a new ObjectIntProcedure .
30,620
public static < T1 , T2 , T3 > Procedure2 < T1 , T3 > bind ( Procedure2 < ? super T2 , T3 > delegate , Function < ? super T1 , T2 > function ) { return new BindProcedure2 < T1 , T2 , T3 > ( delegate , function ) ; }
Bind the input of the first argument of a Procedure2 to the result of an function returning a new Procedure2 .
30,621
public static < T > T getFirst ( T [ ] objectArray ) { if ( ArrayIterate . notEmpty ( objectArray ) ) { return objectArray [ 0 ] ; } return null ; }
Returns the first element of an array . This method is null safe .
30,622
public static < T > T getLast ( T [ ] objectArray ) { if ( ArrayIterate . notEmpty ( objectArray ) ) { return objectArray [ objectArray . length - 1 ] ; } return null ; }
Returns the last element of an Array . This method is null safe .
30,623
public static < T , IV > int detectIndexWith ( T [ ] objectArray , Predicate2 < ? super T , IV > predicate , IV injectedValue ) { if ( objectArray == null ) { throw new IllegalArgumentException ( "Cannot perform a detectIndexWith on null" ) ; } for ( int i = 0 ; i < objectArray . length ; i ++ ) { if ( predicate . accept ( objectArray [ i ] , injectedValue ) ) { return i ; } } return - 1 ; }
Searches for the first index where the predicate evaluates to true . Returns - 1 for no matches .
30,624
public static < T , K , V > MutableMap < K , V > toMap ( T [ ] objectArray , Function < ? super T , ? extends K > keyFunction , Function < ? super T , ? extends V > valueFunction ) { MutableMap < K , V > map = UnifiedMap . newMap ( ) ; Procedure < T > procedure = new MapCollectProcedure < T , K , V > ( map , keyFunction , valueFunction ) ; ArrayIterate . forEach ( objectArray , procedure ) ; return map ; }
Iterate over the specified array applying the specified Functions to each element to calculate a key and value and return the results as a Map .
30,625
public int generateFiles ( ) { List < URL > allTemplateFilesFromClassPath = FileUtils . getAllTemplateFilesFromClasspath ( this . templateDirectory , this . classPathURLs ) ; for ( URL url : allTemplateFilesFromClassPath ) { this . url = url ; this . templateFile = new STGroupFile ( this . url , "UTF-8" , '<' , '>' ) ; this . templateFile . setListener ( this . stErrorListener ) ; this . templateFile . registerRenderer ( String . class , new IntegerOrStringRenderer ( ) ) ; if ( this . templateFile . isDefined ( "fileName" ) ) { this . setTest ( ) ; File targetPath = this . constructTargetPath ( ) ; FileUtils . createDirectory ( targetPath ) ; boolean hasTwoPrimitives = this . templateFile . isDefined ( "hasTwoPrimitives" ) && Boolean . valueOf ( this . templateFile . getInstanceOf ( "hasTwoPrimitives" ) . render ( ) ) ; boolean skipBoolean = this . templateFile . isDefined ( "skipBoolean" ) && Boolean . valueOf ( this . templateFile . getInstanceOf ( "skipBoolean" ) . render ( ) ) ; boolean skipBooleanKeys = this . templateFile . isDefined ( "skipBooleanKeys" ) && Boolean . valueOf ( this . templateFile . getInstanceOf ( "skipBooleanKeys" ) . render ( ) ) ; if ( hasTwoPrimitives ) { for ( Primitive primitive1 : Primitive . values ( ) ) { if ( primitive1 == Primitive . BOOLEAN && ( skipBoolean || skipBooleanKeys ) ) { continue ; } for ( Primitive primitive2 : Primitive . values ( ) ) { if ( primitive2 == Primitive . BOOLEAN && skipBoolean ) { continue ; } String sourceFileName = this . executeTemplate ( primitive1 , primitive2 , "fileName" ) ; File outputFile = new File ( targetPath , sourceFileName + ".java" ) ; if ( ! GsCollectionsCodeGenerator . sourceFileExists ( outputFile ) ) { String classContents = this . executeTemplate ( primitive1 , primitive2 , "class" ) ; this . checkSumClassContentsAndWrite ( classContents , targetPath , sourceFileName ) ; } } } } else { for ( Primitive primitive : Primitive . values ( ) ) { if ( primitive == Primitive . BOOLEAN && skipBoolean ) { continue ; } String sourceFileName = this . executeTemplate ( primitive , "fileName" ) ; File outputFile = new File ( targetPath , sourceFileName + ".java" ) ; if ( ! GsCollectionsCodeGenerator . sourceFileExists ( outputFile ) ) { String classContents = this . executeTemplate ( primitive , "class" ) ; this . checkSumClassContentsAndWrite ( classContents , targetPath , sourceFileName ) ; } } } } } return this . numFileWritten ; }
Generates code and only write contents to disk which differ from the current file contents .
30,626
public static < E , B extends MutableBag < E > > SynchronizedBag < E > of ( B bag ) { return new SynchronizedBag < E > ( bag ) ; }
This method will take a MutableBag and wrap it directly in a SynchronizedBag .
30,627
public static < K , V , M extends SortedMap < K , V > > UnmodifiableTreeMap < K , V > of ( M map ) { if ( map == null ) { throw new IllegalArgumentException ( "cannot create a UnmodifiableSortedMap for null" ) ; } return new UnmodifiableTreeMap < K , V > ( SortedMapAdapter . adapt ( map ) ) ; }
This method will take a MutableSortedMap and wrap it directly in a UnmodifiableMutableMap . It will take any other non - GS - SortedMap and first adapt it will a SortedMapAdapter and then return a UnmodifiableSortedMap that wraps the adapter .
30,628
public static < T1 , T2 > void forEachInBoth ( List < T1 > list1 , List < T2 > list2 , Procedure2 < ? super T1 , ? super T2 > procedure ) { if ( list1 != null && list2 != null ) { int size1 = list1 . size ( ) ; int size2 = list2 . size ( ) ; if ( size1 == size2 ) { for ( int i = 0 ; i < size1 ; i ++ ) { procedure . value ( list1 . get ( i ) , list2 . get ( i ) ) ; } } else { throw new IllegalArgumentException ( "Attempt to call forEachInBoth with two Lists of different sizes :" + size1 + ':' + size2 ) ; } } }
For each element in both of the Lists operation is evaluated with both elements as parameters .
30,629
public static < T > void forEachWithIndex ( List < T > list , ObjectIntProcedure < ? super T > objectIntProcedure ) { int size = list . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) { objectIntProcedure . value ( list . get ( i ) , i ) ; } }
Iterates over a collection passing each element and the current relative int index to the specified instance of ObjectIntProcedure .
30,630
public static < T , IV > int detectIndexWith ( List < T > list , Predicate2 < ? super T , ? super IV > predicate , IV injectedValue ) { int size = list . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) { if ( predicate . accept ( list . get ( i ) , injectedValue ) ) { return i ; } } return - 1 ; }
Searches for the first occurrence where the predicate evaluates to true .
30,631
public static < E , C extends Collection < E > > UnmodifiableMutableCollection < E > of ( C collection ) { if ( collection == null ) { throw new IllegalArgumentException ( "cannot create a UnmodifiableMutableCollection for null" ) ; } return new UnmodifiableMutableCollection < E > ( CollectionAdapter . adapt ( collection ) ) ; }
This method will take a MutableCollection and wrap it directly in a UnmodifiableMutableCollection . It will take any other non - GS - collection and first adapt it will a CollectionAdapter and then return a UnmodifiableMutableCollection that wraps the adapter .
30,632
public static < E > SynchronizedRichIterable < E > of ( RichIterable < E > iterable ) { return new SynchronizedRichIterable < E > ( iterable ) ; }
This method will take a RichIterable and wrap it directly in a SynchronizedRichIterable .
30,633
public static < E > SynchronizedRichIterable < E > of ( RichIterable < E > iterable , Object lock ) { return new SynchronizedRichIterable < E > ( iterable , lock ) ; }
This method will take a RichIterable and wrap it directly in a SynchronizedRichIterable . Additionally a developer specifies which lock to use with the collection .
30,634
private void createAndExecuteTasks ( Executor executor , ProcedureFactory < BT > procedureFactory , T [ ] array ) { this . procedures = new ArrayProcedureFJTask [ this . taskCount ] ; int sectionSize = array . length / this . taskCount ; int size = this . taskCount ; for ( int index = 0 ; index < size ; index ++ ) { ArrayProcedureFJTask < T , BT > procedureFJTask = new ArrayProcedureFJTask < T , BT > ( this , procedureFactory , array , index , sectionSize , index == this . taskCount - 1 ) ; this . procedures [ index ] = procedureFJTask ; executor . execute ( procedureFJTask ) ; } }
Creates an array of ProcedureFJTasks wrapping Procedures created by the specified ProcedureFactory .
30,635
public static < E , B extends MutableBag < E > > UnmodifiableBag < E > of ( B bag ) { if ( bag == null ) { throw new IllegalArgumentException ( "cannot create an UnmodifiableBag for null" ) ; } return new UnmodifiableBag < E > ( bag ) ; }
This method will take a MutableBag and wrap it directly in a UnmodifiableBag .
30,636
public static ExecutorService newPooledExecutor ( String poolName , boolean useDaemonThreads ) { return ParallelIterate . newPooledExecutor ( ParallelIterate . getDefaultMaxThreadPoolSize ( ) , poolName , useDaemonThreads ) ; }
Returns a brand new ExecutorService using the specified poolName and uses the optional property named to set the maximum thread pool size . The same poolName may be used more than once resulting in multiple pools with the same name .
30,637
public static < E , L extends List < E > > SynchronizedMutableList < E > of ( L list , Object lock ) { MutableList < E > mutableList = list instanceof MutableList ? ( MutableList < E > ) list : ListAdapter . adapt ( list ) ; return new SynchronizedMutableList < E > ( mutableList , lock ) ; }
This method will take a MutableList and wrap it directly in a SynchronizedMutableList . It will take any other non - GS - collection and first adapt it will a ListAdapter and then return a SynchronizedMutableList that wraps the adapter . Additionally a developer specifies which lock to use with the collection .
30,638
public static < E > FastList < E > newWithNValues ( int size , Function0 < E > factory ) { FastList < E > newFastList = FastList . newList ( size ) ; for ( int i = 0 ; i < size ; i ++ ) { newFastList . add ( factory . value ( ) ) ; } return newFastList ; }
Creates a new FastList pre - sized to the specified size filled with default values generated by the specified function .
30,639
public boolean trimToSizeIfGreaterThanPercent ( double loadFactor ) { double excessCapacity = 1.0 - ( double ) this . size / ( double ) this . items . length ; if ( excessCapacity > loadFactor ) { this . trimToSize ( ) ; return true ; } return false ; }
Express load factor as 0 . 25 to trim a collection with more than 25% excess capacity
30,640
public static < T > T getFirst ( List < T > collection ) { return Iterate . isEmpty ( collection ) ? null : collection . get ( 0 ) ; }
Returns the first element of a list .
30,641
public static < T > void reverseForEach ( List < T > list , Procedure < ? super T > procedure ) { if ( ! list . isEmpty ( ) ) { ListIterate . forEach ( list , list . size ( ) - 1 , 0 , procedure ) ; } }
Iterates over the List in reverse order executing the Procedure for each element
30,642
public static < T > void reverseForEachWithIndex ( List < T > list , ObjectIntProcedure < ? super T > objectIntProcedure ) { if ( ! list . isEmpty ( ) ) { ListIterate . forEachWithIndex ( list , list . size ( ) - 1 , 0 , objectIntProcedure ) ; } }
Iterates over the List in reverse order executing the Procedure for each element . The index passed into the ObjectIntProcedure is the actual index of the range .
30,643
public static < T1 , T2 > void forEachInBoth ( List < T1 > list1 , List < T2 > list2 , Procedure2 < ? super T1 , ? super T2 > procedure ) { if ( list1 != null && list2 != null ) { if ( list1 . size ( ) == list2 . size ( ) ) { if ( list1 instanceof RandomAccess && list2 instanceof RandomAccess ) { RandomAccessListIterate . forEachInBoth ( list1 , list2 , procedure ) ; } else { Iterator < T1 > iterator1 = list1 . iterator ( ) ; Iterator < T2 > iterator2 = list2 . iterator ( ) ; int size = list2 . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) { procedure . value ( iterator1 . next ( ) , iterator2 . next ( ) ) ; } } } else { throw new RuntimeException ( "Attempt to call forEachInBoth with two Lists of different sizes :" + list1 . size ( ) + ':' + list2 . size ( ) ) ; } } }
Iterates over both lists together evaluating Procedure2 with the current element from each list .
30,644
public static < T > int detectLastIndex ( List < T > list , Predicate < ? super T > predicate ) { if ( list instanceof RandomAccess ) { return RandomAccessListIterate . detectLastIndex ( list , predicate ) ; } int size = list . size ( ) ; int i = size - 1 ; ListIterator < T > reverseIterator = list . listIterator ( size ) ; while ( reverseIterator . hasPrevious ( ) ) { if ( predicate . accept ( reverseIterator . previous ( ) ) ) { return i ; } i -- ; } return - 1 ; }
Returns the last index where the predicate evaluates to true . Returns - 1 for no matches .
30,645
public static void forEachToken ( String string , String separator , Procedure < String > procedure ) { for ( StringTokenizer stringTokenizer = new StringTokenizer ( string , separator ) ; stringTokenizer . hasMoreTokens ( ) ; ) { String token = stringTokenizer . nextToken ( ) ; procedure . value ( token ) ; } }
For each token in a string separated by the specified separator execute the specified StringProcedure by calling the valueOfString method .
30,646
public static int occurrencesOfChar ( String string , final char value ) { return StringIterate . countChar ( string , new CharPredicate ( ) { public boolean accept ( char character ) { return value == character ; } } ) ; }
Count the number of occurrences of the specified char .
30,647
public static int occurrencesOfCodePoint ( String string , final int value ) { return StringIterate . countCodePoint ( string , new CodePointPredicate ( ) { public boolean accept ( int codePoint ) { return value == codePoint ; } } ) ; }
Count the number of occurrences of the specified int code point .
30,648
public static MutableList < String > chunk ( String string , int size ) { if ( size <= 0 ) { throw new IllegalArgumentException ( "Size for groups must be positive but was: " + size ) ; } int length = string . length ( ) ; if ( length == 0 ) { return FastList . newList ( ) ; } MutableList < String > result = FastList . newList ( ( length + size - 1 ) / size ) ; int startOffset = 0 ; while ( startOffset < length ) { result . add ( string . substring ( startOffset , Math . min ( startOffset + size , length ) ) ) ; startOffset += size ; } return result ; }
Partitions String in fixed size chunks .
30,649
public static < T , P , R extends Collection < T > > R selectWith ( Iterable < T > iterable , Predicate2 < ? super T , ? super P > predicate , P parameter , R targetCollection ) { if ( iterable instanceof RichIterable ) { return ( ( RichIterable < T > ) iterable ) . selectWith ( predicate , parameter , targetCollection ) ; } if ( iterable instanceof ArrayList ) { return ArrayListIterate . selectWith ( ( ArrayList < T > ) iterable , predicate , parameter , targetCollection ) ; } if ( iterable instanceof List ) { return ListIterate . selectWith ( ( List < T > ) iterable , predicate , parameter , targetCollection ) ; } if ( iterable != null ) { return IterableIterate . selectWith ( iterable , predicate , parameter , targetCollection ) ; } throw new IllegalArgumentException ( "Cannot perform a selectWith on null" ) ; }
Same as the selectWith method with two parameters but uses the specified target collection .
30,650
public static < T , V extends Comparable < ? super V > , L extends List < T > > L sortThisBy ( L list , Function < ? super T , ? extends V > function ) { return Iterate . sortThis ( list , Comparators . byFunction ( function ) ) ; }
Sort the list by comparing an attribute defined by the function . SortThisBy is a mutating method . The List passed in is also returned .
30,651
public static < T > boolean removeIf ( Iterable < T > iterable , Predicate < ? super T > predicate ) { if ( iterable instanceof MutableCollection ) { return ( ( MutableCollection < T > ) iterable ) . removeIf ( predicate ) ; } if ( iterable instanceof ArrayList ) { return ArrayListIterate . removeIf ( ( ArrayList < T > ) iterable , predicate ) ; } if ( iterable instanceof List ) { return ListIterate . removeIf ( ( List < T > ) iterable , predicate ) ; } if ( iterable != null ) { return IterableIterate . removeIf ( iterable , predicate ) ; } throw new IllegalArgumentException ( "Cannot perform a remove on null" ) ; }
Removes all elements from the iterable that evaluate to true for the specified predicate .
30,652
public static < T , P > boolean removeIfWith ( Iterable < T > iterable , Predicate2 < ? super T , ? super P > predicate , P parameter ) { if ( iterable instanceof MutableCollection ) { return ( ( MutableCollection < T > ) iterable ) . removeIfWith ( predicate , parameter ) ; } if ( iterable instanceof ArrayList ) { return ArrayListIterate . removeIfWith ( ( ArrayList < T > ) iterable , predicate , parameter ) ; } if ( iterable instanceof List ) { return ListIterate . removeIfWith ( ( List < T > ) iterable , predicate , parameter ) ; } if ( iterable != null ) { return IterableIterate . removeIfWith ( iterable , predicate , parameter ) ; } throw new IllegalArgumentException ( "Cannot perform a remove on null" ) ; }
Removes all elements of the iterable that evaluate to true for the specified predicate2 and parameter .
30,653
public static < T , P , R extends Collection < T > > R rejectWith ( Iterable < T > iterable , Predicate2 < ? super T , ? super P > predicate , P parameter , R targetCollection ) { if ( iterable instanceof RichIterable ) { return ( ( RichIterable < T > ) iterable ) . rejectWith ( predicate , parameter , targetCollection ) ; } if ( iterable instanceof ArrayList ) { return ArrayListIterate . rejectWith ( ( ArrayList < T > ) iterable , predicate , parameter , targetCollection ) ; } if ( iterable instanceof RandomAccess ) { return RandomAccessListIterate . rejectWith ( ( List < T > ) iterable , predicate , parameter , targetCollection ) ; } if ( iterable != null ) { return IterableIterate . rejectWith ( iterable , predicate , parameter , targetCollection ) ; } throw new IllegalArgumentException ( "Cannot perform a rejectWith on null" ) ; }
Same as the reject method with two parameters but uses the specified target collection .
30,654
public static < T , R extends Collection < T > > R addAllTo ( Iterable < ? extends T > iterable , R targetCollection ) { Iterate . addAllIterable ( iterable , targetCollection ) ; return targetCollection ; }
Add all elements from the source Iterable to the target collection return the target collection .
30,655
public static < T > boolean addAllIterable ( Iterable < ? extends T > iterable , Collection < T > targetCollection ) { if ( iterable == null ) { throw new NullPointerException ( ) ; } if ( iterable instanceof Collection < ? > ) { return targetCollection . addAll ( ( Collection < T > ) iterable ) ; } int oldSize = targetCollection . size ( ) ; Iterate . forEachWith ( iterable , Procedures2 . < T > addToCollection ( ) , targetCollection ) ; return targetCollection . size ( ) != oldSize ; }
Add all elements from the source Iterable to the target collection returns true if any element was added .
30,656
public static < T , R extends Collection < T > > R removeAllFrom ( Iterable < ? extends T > iterable , R targetCollection ) { Iterate . removeAllIterable ( iterable , targetCollection ) ; return targetCollection ; }
Remove all elements present in Iterable from the target collection return the target collection .
30,657
public static < T > boolean removeAllIterable ( Iterable < ? extends T > iterable , Collection < T > targetCollection ) { if ( iterable == null ) { throw new NullPointerException ( ) ; } if ( iterable instanceof Collection < ? > ) { return targetCollection . removeAll ( ( Collection < T > ) iterable ) ; } int oldSize = targetCollection . size ( ) ; Iterate . forEachWith ( iterable , Procedures2 . < T > removeFromCollection ( ) , targetCollection ) ; return targetCollection . size ( ) != oldSize ; }
Remove all elements present in Iterable from the target collection returns true if any element was removed .
30,658
public static < T , P , A > Collection < A > collectWith ( Iterable < T > iterable , Function2 < ? super T , ? super P , ? extends A > function , P parameter ) { if ( iterable instanceof MutableCollection ) { return ( ( MutableCollection < T > ) iterable ) . collectWith ( function , parameter ) ; } if ( iterable instanceof ArrayList ) { return ArrayListIterate . collectWith ( ( ArrayList < T > ) iterable , function , parameter ) ; } if ( iterable instanceof List < ? > ) { return ListIterate . collectWith ( ( List < T > ) iterable , function , parameter ) ; } if ( iterable instanceof Collection ) { return IterableIterate . collectWith ( iterable , function , parameter , DefaultSpeciesNewStrategy . INSTANCE . < A > speciesNew ( ( Collection < T > ) iterable , ( ( Collection < T > ) iterable ) . size ( ) ) ) ; } if ( iterable != null ) { return IterableIterate . collectWith ( iterable , function , parameter ) ; } throw new IllegalArgumentException ( "Cannot perform a collectWith on null" ) ; }
Same as collect with a Function2 and specified parameter which is passed to the function .
30,659
public static < T , P , A , R extends Collection < A > > R collectWith ( Iterable < T > iterable , Function2 < ? super T , ? super P , ? extends A > function , P parameter , R targetCollection ) { if ( iterable instanceof RichIterable ) { return ( ( RichIterable < T > ) iterable ) . collectWith ( function , parameter , targetCollection ) ; } if ( iterable instanceof ArrayList ) { return ArrayListIterate . collectWith ( ( ArrayList < T > ) iterable , function , parameter , targetCollection ) ; } if ( iterable instanceof RandomAccess ) { return RandomAccessListIterate . collectWith ( ( List < T > ) iterable , function , parameter , targetCollection ) ; } if ( iterable != null ) { return IterableIterate . collectWith ( iterable , function , parameter , targetCollection ) ; } throw new IllegalArgumentException ( "Cannot perform a collectWith on null" ) ; }
Same as collectWith but with a targetCollection parameter to gather the results .
30,660
public static < T > Collection < T > flatten ( Iterable < ? extends Iterable < T > > iterable ) { return Iterate . flatCollect ( iterable , Functions . < Iterable < T > > identity ( ) ) ; }
Flattens a collection of collections into one flat collection .
30,661
public static boolean isEmpty ( Iterable < ? > iterable ) { if ( iterable == null ) { return true ; } if ( iterable instanceof RichIterable ) { return ( ( RichIterable < ? > ) iterable ) . isEmpty ( ) ; } if ( iterable instanceof Collection ) { return ( ( Collection < ? > ) iterable ) . isEmpty ( ) ; } return IterableIterate . isEmpty ( iterable ) ; }
A null - safe check on a collection to see if it isEmpty . A null collection results in a true .
30,662
public static < T > T detectIfNone ( Iterable < T > iterable , Predicate < ? super T > predicate , T ifNone ) { T result = Iterate . detect ( iterable , predicate ) ; return result == null ? ifNone : result ; }
Returns the first element of the iterable that evaluates to true for the specified predicate or returns the result ifNone if no element evaluates to true .
30,663
public static < T , P > T detectWithIfNone ( Iterable < T > iterable , Predicate2 < ? super T , ? super P > predicate , P parameter , T ifNone ) { T result = Iterate . detectWith ( iterable , predicate , parameter ) ; return result == null ? ifNone : result ; }
Returns the first element of the iterable that evaluates to true for the specified predicate2 and parameter or returns the result ifNone if no element evaluates to true .
30,664
public static < T > int detectIndex ( Iterable < T > iterable , Predicate < ? super T > predicate ) { if ( iterable instanceof ArrayList < ? > ) { return ArrayListIterate . detectIndex ( ( ArrayList < T > ) iterable , predicate ) ; } if ( iterable instanceof List < ? > ) { return ListIterate . detectIndex ( ( List < T > ) iterable , predicate ) ; } if ( iterable != null ) { return IterableIterate . detectIndex ( iterable , predicate ) ; } throw new IllegalArgumentException ( "Cannot perform detectIndex on null" ) ; }
Searches for the first occurrence where the predicate evaluates to true returns - 1 if the predicate does not evaluate to true .
30,665
public static < T , P > int detectIndexWith ( Iterable < T > iterable , Predicate2 < ? super T , ? super P > predicate , P parameter ) { if ( iterable instanceof ArrayList < ? > ) { return ArrayListIterate . detectIndexWith ( ( ArrayList < T > ) iterable , predicate , parameter ) ; } if ( iterable instanceof List < ? > ) { return ListIterate . detectIndexWith ( ( List < T > ) iterable , predicate , parameter ) ; } if ( iterable != null ) { return IterableIterate . detectIndexWith ( iterable , predicate , parameter ) ; } throw new IllegalArgumentException ( "Cannot perform detectIndexWith on null" ) ; }
Searches for the first occurrence where the predicate2 and parameter evaluates to true returns - 1 if the predicate2 and parameter do not evaluate to true .
30,666
public static < T > BigDecimal sumOfBigDecimal ( Iterable < T > iterable , Function < ? super T , BigDecimal > function ) { if ( iterable instanceof List ) { return ListIterate . sumOfBigDecimal ( ( List < T > ) iterable , function ) ; } if ( iterable != null ) { return IterableIterate . sumOfBigDecimal ( iterable , function ) ; } throw new IllegalArgumentException ( "Cannot perform an sumOfBigDecimal on null" ) ; }
Returns the BigDecimal sum of the result of applying the function to each element of the iterable .
30,667
public static < T > BigInteger sumOfBigInteger ( Iterable < T > iterable , Function < ? super T , BigInteger > function ) { if ( iterable instanceof List ) { return ListIterate . sumOfBigInteger ( ( List < T > ) iterable , function ) ; } if ( iterable != null ) { return IterableIterate . sumOfBigInteger ( iterable , function ) ; } throw new IllegalArgumentException ( "Cannot perform an sumOfBigDecimal on null" ) ; }
Returns the BigInteger sum of the result of applying the function to each element of the iterable .
30,668
public static < T > boolean anySatisfy ( Iterable < T > iterable , Predicate < ? super T > predicate ) { if ( iterable instanceof RichIterable ) { return ( ( RichIterable < T > ) iterable ) . anySatisfy ( predicate ) ; } if ( iterable instanceof ArrayList ) { return ArrayListIterate . anySatisfy ( ( ArrayList < T > ) iterable , predicate ) ; } if ( iterable instanceof RandomAccess ) { return RandomAccessListIterate . anySatisfy ( ( List < T > ) iterable , predicate ) ; } if ( iterable != null ) { return IterableIterate . anySatisfy ( iterable , predicate ) ; } throw new IllegalArgumentException ( "Cannot perform an anySatisfy on null" ) ; }
Returns true if the predicate evaluates to true for any element of the iterable . Returns false if the iterable is empty or if no elements return true for the predicate .
30,669
public static < T , K > MutableMap < K , T > toMap ( Iterable < T > iterable , Function < ? super T , ? extends K > keyFunction ) { MutableMap < K , T > map = UnifiedMap . newMap ( ) ; Iterate . forEach ( iterable , new MapCollectProcedure < T , K , T > ( map , keyFunction ) ) ; return map ; }
Iterate over the specified collection applying the specified Function to each element to calculate a key and return the results as a Map .
30,670
public static < T , K , V > MutableMap < K , V > toMap ( Iterable < T > iterable , Function < ? super T , ? extends K > keyFunction , Function < ? super T , ? extends V > valueFunction ) { return Iterate . addToMap ( iterable , keyFunction , valueFunction , UnifiedMap . < K , V > newMap ( ) ) ; }
Iterate over the specified collection applying the specified Functions to each element to calculate a key and value and return the results as a Map .
30,671
public static < T , K , V , M extends Map < K , V > > M addToMap ( Iterable < T > iterable , Function < ? super T , ? extends K > keyFunction , M map ) { Iterate . forEach ( iterable , new MapCollectProcedure < T , K , V > ( map , keyFunction ) ) ; return map ; }
Iterate over the specified collection applying a specific Function to each element to calculate a key and add the results to input Map . This method will mutate the input Map .
30,672
public static < T extends Comparable < ? super T > > MutableList < T > toSortedList ( Iterable < T > iterable ) { return Iterate . toSortedList ( iterable , Comparators . naturalOrder ( ) ) ; }
Return the specified collection as a sorted List .
30,673
public static < T > MutableList < T > toSortedList ( Iterable < T > iterable , Comparator < ? super T > comparator ) { return FastList . newList ( iterable ) . sortThis ( comparator ) ; }
Return the specified collection as a sorted List using the specified Comparator .
30,674
public static int sizeOf ( Iterable < ? > iterable ) { if ( iterable instanceof Collection ) { return ( ( Collection < ? > ) iterable ) . size ( ) ; } if ( iterable instanceof RichIterable ) { return ( ( RichIterable < ? > ) iterable ) . size ( ) ; } return Iterate . count ( iterable , Predicates . alwaysTrue ( ) ) ; }
Returns the size of an iterable . In the case of Collections and RichIterables the method size is called . All other iterables will force a complete iteration to happen which can be unnecessarily costly .
30,675
public static boolean contains ( Iterable < ? > iterable , Object value ) { if ( iterable instanceof Collection ) { return ( ( Collection < ? > ) iterable ) . contains ( value ) ; } if ( iterable instanceof RichIterable ) { return ( ( RichIterable < ? > ) iterable ) . contains ( value ) ; } return IterableIterate . detectIndex ( iterable , Predicates . equal ( value ) ) > - 1 ; }
Returns true if the iterable contains the value . In the case of Collections and RichIterables the method contains is called . All other iterables will force a complete iteration to happen which can be unnecessarily costly .
30,676
public static < T > Object [ ] toArray ( Iterable < T > iterable ) { if ( iterable == null ) { throw new NullPointerException ( ) ; } if ( iterable instanceof Collection ) { return ( ( Collection < T > ) iterable ) . toArray ( ) ; } if ( iterable instanceof RichIterable ) { return ( ( RichIterable < T > ) iterable ) . toArray ( ) ; } MutableList < T > result = Lists . mutable . empty ( ) ; Iterate . addAllTo ( iterable , result ) ; return result . toArray ( ) ; }
Converts the specified iterable to an array .
30,677
public static < T > T [ ] toArray ( Iterable < ? extends T > iterable , T [ ] target ) { if ( iterable instanceof Collection ) { return ( ( Collection < T > ) iterable ) . toArray ( target ) ; } if ( iterable instanceof RichIterable ) { return ( ( RichIterable < T > ) iterable ) . toArray ( target ) ; } MutableList < T > result = Lists . mutable . empty ( ) ; Iterate . addAllTo ( iterable , result ) ; return result . toArray ( target ) ; }
Copies the specified iterable into the specified array .
30,678
public static < T , V extends Comparable < ? super V > > T maxBy ( Iterable < T > iterable , Function < ? super T , ? extends V > function ) { if ( iterable instanceof RichIterable ) { return ( ( RichIterable < T > ) iterable ) . maxBy ( function ) ; } if ( iterable instanceof RandomAccess ) { return RandomAccessListIterate . maxBy ( ( List < T > ) iterable , function ) ; } if ( iterable != null ) { return IterableIterate . maxBy ( iterable , function ) ; } throw new IllegalArgumentException ( "Cannot perform a maxBy on null" ) ; }
Returns the maximum element out of the iterable based on the natural order of the attribute returned by the function .
30,679
public static < T > Constructor < T > getConstructor ( Class < T > instantiable , Class < ? > ... constructorParameterTypes ) { try { return instantiable . getConstructor ( constructorParameterTypes ) ; } catch ( NoSuchMethodException ignored ) { return ReflectionHelper . searchForConstructor ( instantiable , constructorParameterTypes ) ; } }
These are special methods that will not produce error messages if the getter method is not found
30,680
public static Interval oneToBy ( int count , int step ) { if ( count < 1 ) { throw new IllegalArgumentException ( "Only positive ranges allowed using oneToBy" ) ; } return Interval . fromToBy ( 1 , count , step ) ; }
Returns an Interval starting from 1 to the specified count value with a step value of step .
30,681
public static Interval fromTo ( int from , int to ) { if ( from <= to ) { return Interval . fromToBy ( from , to , 1 ) ; } return Interval . fromToBy ( from , to , - 1 ) ; }
Returns an Interval starting from the value from to the specified value to with a step value of 1 .
30,682
public static Interval evensFromTo ( int from , int to ) { if ( from % 2 != 0 ) { if ( from < to ) { from ++ ; } else { from -- ; } } if ( to % 2 != 0 ) { if ( to > from ) { to -- ; } else { to ++ ; } } return Interval . fromToBy ( from , to , to > from ? 2 : - 2 ) ; }
Returns an Interval representing the even values from the value from to the value to .
30,683
public static Interval oddsFromTo ( int from , int to ) { if ( from % 2 == 0 ) { if ( from < to ) { from ++ ; } else { from -- ; } } if ( to % 2 == 0 ) { if ( to > from ) { to -- ; } else { to ++ ; } } return Interval . fromToBy ( from , to , to > from ? 2 : - 2 ) ; }
Returns an Interval representing the odd values from the value from to the value to .
30,684
public static MutableSet < Integer > toSet ( int from , int to ) { MutableSet < Integer > targetCollection = UnifiedSet . newSet ( ) ; Interval . fromTo ( from , to ) . forEach ( CollectionAddProcedure . on ( targetCollection ) ) ; return targetCollection ; }
Returns an Set representing the Integer values from the value from to the value to .
30,685
public static MutableList < Integer > toReverseList ( int from , int to ) { return Interval . fromTo ( from , to ) . reverseThis ( ) . toList ( ) ; }
Returns a MutableList representing the Integer values from the value from to the value to in reverse .
30,686
public static Interval fromToBy ( int from , int to , int stepBy ) { if ( stepBy == 0 ) { throw new IllegalArgumentException ( "Cannot use a step by of 0" ) ; } if ( from > to && stepBy > 0 || from < to && stepBy < 0 ) { throw new IllegalArgumentException ( "Step by is incorrect for the range" ) ; } return new Interval ( from , to , stepBy ) ; }
Returns an Interval for the range of integers inclusively between from and to with the specified stepBy value .
30,687
private BigInteger bigIntegerProduct ( ) { return this . injectInto ( BigInteger . valueOf ( 1L ) , new Function2 < BigInteger , Integer , BigInteger > ( ) { public BigInteger value ( BigInteger result , Integer each ) { return result . multiply ( BigInteger . valueOf ( each . longValue ( ) ) ) ; } } ) ; }
Returns the BigInteger result of calculating product for the range .
30,688
public void forEach ( Procedure < ? super Integer > procedure , Executor executor ) { CountDownLatch latch = new CountDownLatch ( this . size ( ) ) ; if ( this . goForward ( ) ) { for ( int i = this . from ; i <= this . to ; i += this . step ) { this . executeAndCountdown ( procedure , executor , latch , i ) ; } } else { for ( int i = this . from ; i >= this . to ; i += this . step ) { this . executeAndCountdown ( procedure , executor , latch , i ) ; } } try { latch . await ( ) ; } catch ( InterruptedException e ) { } }
This method executes a void procedure against an executor passing the current index of the interval .
30,689
public void run ( Runnable runnable ) { if ( this . goForward ( ) ) { for ( int i = this . from ; i <= this . to ; i += this . step ) { runnable . run ( ) ; } } else { for ( int i = this . from ; i >= this . to ; i += this . step ) { runnable . run ( ) ; } } }
This method runs a runnable a specified number of times against on the current thread .
30,690
public void run ( Runnable runnable , Executor executor ) { if ( this . goForward ( ) ) { for ( int i = this . from ; i <= this . to ; i += this . step ) { executor . execute ( runnable ) ; } } else { for ( int i = this . from ; i >= this . to ; i += this . step ) { executor . execute ( runnable ) ; } } }
This method runs a runnable a specified number of times against an executor . The method is effectively asynchronous because it does not wait for all of the runnables to finish .
30,691
public int [ ] toIntArray ( ) { final int [ ] result = new int [ this . size ( ) ] ; this . forEachWithIndex ( new IntIntProcedure ( ) { public void value ( int each , int index ) { result [ index ] = each ; } } ) ; return result ; }
Converts the interval to an Integer array
30,692
public static < K , V , A > A ifPresentApply ( Map < K , V > map , K key , Function < ? super V , ? extends A > function ) { if ( map instanceof UnsortedMapIterable ) { return ( ( MapIterable < K , V > ) map ) . ifPresentApply ( key , function ) ; } V result = map . get ( key ) ; return MapIterate . isAbsent ( result , map , key ) ? null : function . valueOf ( result ) ; }
If there is a value in the Map tat the specified key return the result of applying the specified Function on the value otherwise return null .
30,693
public static < K , V , K2 , V2 > MutableMap < K2 , V2 > collect ( Map < K , V > map , Function2 < ? super K , ? super V , Pair < K2 , V2 > > function ) { return MapIterate . collect ( map , function , UnifiedMap . < K2 , V2 > newMap ( map . size ( ) ) ) ; }
For each value of the map the function is evaluated with the key and value as the parameter . The results of these evaluations are collected into a new UnifiedMap .
30,694
public static < K1 , V1 , K2 , V2 , R extends Map < K2 , V2 > > R collect ( Map < K1 , V1 > map , final Function2 < ? super K1 , ? super V1 , Pair < K2 , V2 > > function , final R target ) { MapIterate . forEachKeyValue ( map , new Procedure2 < K1 , V1 > ( ) { public void value ( K1 key , V1 value ) { Pair < K2 , V2 > pair = function . value ( key , value ) ; target . put ( pair . getOne ( ) , pair . getTwo ( ) ) ; } } ) ; return target ; }
For each value of the map the function is evaluated with the key and value as the parameter . The results of these evaluations are collected into the target map .
30,695
public static < K1 , V1 , K2 , V2 > MutableMap < K2 , V2 > collect ( Map < K1 , V1 > map , Function < ? super K1 , ? extends K2 > keyFunction , Function < ? super V1 , ? extends V2 > valueFunction ) { return MapIterate . collect ( map , keyFunction , valueFunction , UnifiedMap . < K2 , V2 > newMap ( ) ) ; }
For each key - value entry of a map applies a function to each and adds the transformed entry to a new Map .
30,696
public static < K1 , V1 , K2 , V2 > MutableMap < K2 , V2 > collect ( Map < K1 , V1 > map , final Function < ? super K1 , ? extends K2 > keyFunction , final Function < ? super V1 , ? extends V2 > valueFunction , Map < K2 , V2 > target ) { return MapIterate . collect ( map , new Function2 < K1 , V1 , Pair < K2 , V2 > > ( ) { public Pair < K2 , V2 > value ( K1 key , V1 value ) { return Tuples . pair ( keyFunction . valueOf ( key ) , valueFunction . valueOf ( value ) ) ; } } , MapAdapter . adapt ( target ) ) ; }
For each key - value entry of a map applies a function to each and adds the transformed entry to the target Map .
30,697
public static < K , V > MutableList < Pair < K , V > > toListOfPairs ( Map < K , V > map ) { final MutableList < Pair < K , V > > pairs = FastList . newList ( map . size ( ) ) ; MapIterate . forEachKeyValue ( map , new Procedure2 < K , V > ( ) { public void value ( K key , V value ) { pairs . add ( Tuples . pair ( key , value ) ) ; } } ) ; return pairs ; }
Iterate over the specified map applying the specified Function to each value and return the results as a List .
30,698
public static < K , V > MutableList < V > toSortedList ( Map < K , V > map , Comparator < ? super V > comparator ) { return Iterate . toSortedList ( map . values ( ) , comparator ) ; }
Iterate over the specified map applying the specified Function to each value and return the results as a sorted List using the specified Comparator .
30,699
public static < K , V > int occurrencesOf ( Map < K , V > map , V object ) { return Iterate . count ( map . values ( ) , Predicates . equal ( object ) ) ; }
Return the number of occurrences of object in the specified map .