public final class Iterate extends Object
Modifier and Type | Method and Description |
---|---|
static <T> boolean |
addAllIterable(Iterable<? extends T> iterable,
Collection<T> targetCollection)
Add all elements from the source Iterable to the target collection, returns true if any element was added.
|
static <T,R extends Collection<T>> |
addAllTo(Iterable<? extends T> iterable,
R targetCollection)
Add all elements from the source Iterable to the target collection, return the target collection.
|
static <T,K,V,M extends Map<K,V>> |
addToMap(Iterable<T> iterable,
Function<? super T,? extends K> keyFunction,
Function<? super T,? extends V> valueFunction,
M map)
Iterate over the specified collection applying the specified Functions to each element to calculate
a key and value, and add the results to input Map.
|
static <T,K,V,M extends Map<K,V>> |
addToMap(Iterable<T> iterable,
Function<? super T,? extends K> keyFunction,
M map)
Iterate over the specified collection applying a specific Function to each element to calculate a
key, and add the results to input Map.
|
static <T,K,V> MutableMap<K,V> |
aggregateBy(Iterable<T> iterable,
Function<? super T,? extends K> groupBy,
Function0<? extends V> zeroValueFactory,
Function2<? super V,? super T,? extends V> nonMutatingAggregator) |
static <T,K,V> MutableMap<K,V> |
aggregateInPlaceBy(Iterable<T> iterable,
Function<? super T,? extends K> groupBy,
Function0<? extends V> zeroValueFactory,
Procedure2<? super V,? super T> mutatingAggregator) |
static <T> boolean |
allSatisfy(Iterable<T> iterable,
Predicate<? super T> predicate)
Returns true if the predicate evaluates to true for every element of the iterable, or returns false.
|
static <T,P> boolean |
allSatisfyWith(Iterable<T> iterable,
Predicate2<? super T,? super P> predicate,
P parameter)
Returns true if the predicate evaluates to true for every element of the iterable, or returns false.
|
static <T> boolean |
anySatisfy(Iterable<T> iterable,
Predicate<? super T> predicate)
Returns true if the predicate evaluates to true for any element of the iterable.
|
static <T,P> boolean |
anySatisfyWith(Iterable<T> iterable,
Predicate2<? super T,? super P> predicate,
P parameter)
Returns true if the predicate2 and parameter evaluates to true for any element of the iterable.
|
static <T> void |
appendString(Iterable<T> iterable,
Appendable appendable) |
static <T> void |
appendString(Iterable<T> iterable,
Appendable appendable,
String separator) |
static <T> void |
appendString(Iterable<T> iterable,
Appendable appendable,
String start,
String separator,
String end) |
static <T> RichIterable<RichIterable<T>> |
chunk(Iterable<T> iterable,
int size) |
static <T,A,R extends Collection<A>> |
collect(Iterable<T> iterable,
Function<? super T,? extends A> function,
R targetCollection)
Same as the
collect(Iterable, Function) method with two parameters, except that the results are gathered into the specified
targetCollection |
static <T,V> Collection<V> |
collect(Iterable<T> iterable,
Function<? super T,? extends V> function)
Returns a new collection with the results of applying the specified function for each element of the iterable.
|
static <T> MutableBooleanCollection |
collectBoolean(Iterable<T> iterable,
BooleanFunction<? super T> booleanFunction)
Returns a new primitive
boolean collection with the results of applying the specified booleanFunction for each element of the iterable. |
static <T,R extends MutableBooleanCollection> |
collectBoolean(Iterable<T> iterable,
BooleanFunction<? super T> booleanFunction,
R target)
Same as
collectBoolean(Iterable, BooleanFunction) , except that the results are gathered into the specified target
collection. |
static <T> MutableByteCollection |
collectByte(Iterable<T> iterable,
ByteFunction<? super T> byteFunction)
Returns a new
byte collection with the results of applying the specified byteFunction for each element of the iterable. |
static <T,R extends MutableByteCollection> |
collectByte(Iterable<T> iterable,
ByteFunction<? super T> byteFunction,
R target)
Same as
collectByte(Iterable, ByteFunction) , except that the results are gathered into the specified target
collection. |
static <T> MutableCharCollection |
collectChar(Iterable<T> iterable,
CharFunction<? super T> charFunction)
Returns a new
char collection with the results of applying the specified charFunction for each element of the iterable. |
static <T,R extends MutableCharCollection> |
collectChar(Iterable<T> iterable,
CharFunction<? super T> charFunction,
R target)
Same as
collectChar(Iterable, CharFunction) , except that the results are gathered into the specified target
collection. |
static <T> MutableDoubleCollection |
collectDouble(Iterable<T> iterable,
DoubleFunction<? super T> doubleFunction)
Returns a new
double collection with the results of applying the specified doubleFunction for each element of the iterable. |
static <T,R extends MutableDoubleCollection> |
collectDouble(Iterable<T> iterable,
DoubleFunction<? super T> doubleFunction,
R target)
Same as
collectDouble(Iterable, DoubleFunction) , except that the results are gathered into the specified target
collection. |
static <T> MutableFloatCollection |
collectFloat(Iterable<T> iterable,
FloatFunction<? super T> floatFunction)
Returns a new
float collection with the results of applying the specified floatFunction for each element of the iterable. |
static <T,R extends MutableFloatCollection> |
collectFloat(Iterable<T> iterable,
FloatFunction<? super T> floatFunction,
R target)
Same as
collectFloat(Iterable, FloatFunction) , except that the results are gathered into the specified target
collection. |
static <T,V> Collection<V> |
collectIf(Iterable<T> iterable,
Predicate<? super T> predicate,
Function<? super T,? extends V> function) |
static <T,V,R extends Collection<V>> |
collectIf(Iterable<T> iterable,
Predicate<? super T> predicate,
Function<? super T,? extends V> function,
R target) |
static <T> MutableIntCollection |
collectInt(Iterable<T> iterable,
IntFunction<? super T> intFunction)
Returns a new
int collection with the results of applying the specified intFunction for each element of the iterable. |
static <T,R extends MutableIntCollection> |
collectInt(Iterable<T> iterable,
IntFunction<? super T> intFunction,
R target)
Same as
collectInt(Iterable, IntFunction) , except that the results are gathered into the specified target
collection. |
static <T> MutableLongCollection |
collectLong(Iterable<T> iterable,
LongFunction<? super T> longFunction)
Returns a new
long collection with the results of applying the specified longFunction for each element of the iterable. |
static <T,R extends MutableLongCollection> |
collectLong(Iterable<T> iterable,
LongFunction<? super T> longFunction,
R target)
Same as
collectLong(Iterable, LongFunction) , except that the results are gathered into the specified target
collection. |
static <T> MutableShortCollection |
collectShort(Iterable<T> iterable,
ShortFunction<? super T> shortFunction)
Returns a new
short collection with the results of applying the specified shortFunction for each element of the iterable. |
static <T,R extends MutableShortCollection> |
collectShort(Iterable<T> iterable,
ShortFunction<? super T> shortFunction,
R target)
Same as
collectShort(Iterable, ShortFunction) , except that the results are gathered into the specified target
collection. |
static <T,P,A> Collection<A> |
collectWith(Iterable<T> iterable,
Function2<? super T,? super P,? extends A> function,
P parameter)
Same as collect with a Function2 and specified parameter which is passed to the function.
|
static <T,P,A,R extends Collection<A>> |
collectWith(Iterable<T> iterable,
Function2<? super T,? super P,? extends A> function,
P parameter,
R targetCollection)
Same as collectWith but with a targetCollection parameter to gather the results.
|
static boolean |
contains(Iterable<?> iterable,
Object value)
Returns true if the iterable contains the value.
|
static <T> int |
count(Iterable<T> iterable,
Predicate<? super T> predicate)
Returns the total number of elements that evaluate to true for the specified predicate.
|
static <T,IV> int |
countWith(Iterable<T> iterable,
Predicate2<? super T,? super IV> predicate,
IV injectedValue)
Returns the total number of elements that evaluate to true for the specified predicate2 and parameter.
|
static <T> T |
detect(Iterable<T> iterable,
Predicate<? super T> predicate)
Returns the first element of the iterable that evaluates to true for the specified predicate, or null if
no element evaluates to true.
|
static <T> T |
detectIfNone(Iterable<T> iterable,
Predicate<? super T> predicate,
T ifNone)
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.
|
static <T> int |
detectIndex(Iterable<T> iterable,
Predicate<? super T> predicate)
Searches for the first occurrence where the predicate evaluates to true, returns -1 if the predicate does not evaluate to true.
|
static <T,P> int |
detectIndexWith(Iterable<T> iterable,
Predicate2<? super T,? super P> predicate,
P parameter)
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.
|
static <T> Optional<T> |
detectOptional(Iterable<T> iterable,
Predicate<? super T> predicate)
Returns the first element of the iterable that evaluates to true for the specified predicate as an Optional.
|
static <T,P> T |
detectWith(Iterable<T> iterable,
Predicate2<? super T,? super P> predicate,
P parameter)
Returns the first element of the iterable that evaluates to true for the specified predicate2 and parameter,
or null if no element evaluates to true.
|
static <T,P> T |
detectWithIfNone(Iterable<T> iterable,
Predicate2<? super T,? super P> predicate,
P parameter,
T ifNone)
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.
|
static <T,P> Optional<T> |
detectWithOptional(Iterable<T> iterable,
Predicate2<? super T,? super P> predicate,
P parameter)
Returns the first element of the iterable that evaluates to true for the specified predicate2 and parameter as
an Optional.
|
static <T> Collection<T> |
drop(Iterable<T> iterable,
int count)
Returns a collection without the first
count elements of the iterable
or an empty iterable if the count is greater than the length of the iterable. |
static <T,A,R extends Collection<A>> |
flatCollect(Iterable<T> iterable,
Function<? super T,? extends Iterable<A>> function,
R targetCollection) |
static <T,V> Collection<V> |
flatCollect(Iterable<T> iterable,
Function<? super T,? extends Iterable<V>> function) |
static <T> Collection<T> |
flatten(Iterable<? extends Iterable<T>> iterable)
Flattens a collection of collections into one "flat" collection.
|
static <T,R extends Collection<T>> |
flatten(Iterable<? extends Iterable<T>> iterable,
R targetCollection)
Same as
flatten(Iterable) except that the results are gathered into the specified targetCollection. |
static <K,V> HashBagMultimap<V,K> |
flip(BagMultimap<K,V> bagMultimap)
Flip the keys and values of the multimap.
|
static <K,V> HashBagMultimap<V,K> |
flip(ListMultimap<K,V> listMultimap)
Flip the keys and values of the multimap.
|
static <K,V> UnifiedSetMultimap<V,K> |
flip(SetMultimap<K,V> setMultimap)
Flip the keys and values of the multimap.
|
static <T> void |
forEach(Iterable<T> iterable,
Procedure<? super T> procedure)
The procedure is evaluated for each element of the iterable.
|
static <T,P> void |
forEachWith(Iterable<T> iterable,
Procedure2<? super T,? super P> procedure,
P parameter)
The procedure2 is evaluated for each element of the iterable with the specified parameter passed
as the second argument.
|
static <T> void |
forEachWithIndex(Iterable<T> iterable,
ObjectIntProcedure<? super T> objectIntProcedure)
Iterates over a collection passing each element and the current relative int index to the specified instance of
ObjectIntProcedure.
|
static <T> T |
getFirst(Iterable<T> iterable)
Returns the first element of a collection.
|
static <T> T |
getLast(Iterable<T> iterable)
Returns the last element of a collection.
|
static <T> T |
getOnly(Iterable<T> iterable) |
static <T,V> MutableMultimap<V,T> |
groupBy(Iterable<T> iterable,
Function<? super T,? extends V> function) |
static <T,V,R extends MutableMultimap<V,T>> |
groupBy(Iterable<T> iterable,
Function<? super T,? extends V> function,
R targetMultimap) |
static <T,K,V,R extends MutableMultimap<K,V>> |
groupByAndCollect(Iterable<T> iterable,
Function<? super T,? extends K> groupByFunction,
Function<? super T,? extends V> valueFunction,
R targetMultimap)
Iterate over the specified collection applying the specified Functions to each element to calculate
a key and value, add the results to
targetMultimap and return the targetMultimap . |
static <T,V> MutableMultimap<V,T> |
groupByEach(Iterable<T> iterable,
Function<? super T,? extends Iterable<V>> function) |
static <T,V,R extends MutableMultimap<V,T>> |
groupByEach(Iterable<T> iterable,
Function<? super T,? extends Iterable<V>> function,
R targetCollection) |
static <V,T> MutableMap<V,T> |
groupByUniqueKey(Iterable<T> iterable,
Function<? super T,? extends V> function) |
static <V,T,R extends MutableMap<V,T>> |
groupByUniqueKey(Iterable<T> iterable,
Function<? super T,? extends V> function,
R target) |
static <T> double |
injectInto(double injectValue,
Iterable<T> iterable,
DoubleObjectToDoubleFunction<? super T> function) |
static <T> float |
injectInto(float injectValue,
Iterable<T> iterable,
FloatObjectToFloatFunction<? super T> function) |
static <T> int |
injectInto(int injectValue,
Iterable<T> iterable,
IntObjectToIntFunction<? super T> function) |
static <T,IV> IV |
injectInto(IV injectValue,
Iterable<T> iterable,
Function2<? super IV,? super T,? extends IV> function) |
static <T> long |
injectInto(long injectValue,
Iterable<T> iterable,
LongObjectToLongFunction<? super T> function) |
static <T,IV,P> IV |
injectIntoWith(IV injectValue,
Iterable<T> iterable,
Function3<? super IV,? super T,? super P,? extends IV> function,
P parameter)
Similar to
injectInto(Object, Iterable, Function2) , except with a parameter is used as third generic argument in function3. |
static boolean |
isEmpty(Iterable<?> iterable)
A null-safe check on a collection to see if it isEmpty.
|
static <T> String |
makeString(Iterable<T> iterable) |
static <T> String |
makeString(Iterable<T> iterable,
String separator) |
static <T> String |
makeString(Iterable<T> iterable,
String start,
String separator,
String end) |
static <T> T |
max(Iterable<T> iterable) |
static <T> T |
max(Iterable<T> iterable,
Comparator<? super T> comparator) |
static <T,V extends Comparable<? super V>> |
maxBy(Iterable<T> iterable,
Function<? super T,? extends V> function)
Returns the maximum element out of the iterable based on the natural order of the attribute returned by the function.
|
static <T> T |
min(Iterable<T> iterable) |
static <T> T |
min(Iterable<T> iterable,
Comparator<? super T> comparator) |
static <T,V extends Comparable<? super V>> |
minBy(Iterable<T> iterable,
Function<? super T,? extends V> function)
Returns the minimum element out of the iterable based on the natural order of the attribute returned by the function.
|
static <T> boolean |
noneSatisfy(Iterable<T> iterable,
Predicate<? super T> predicate)
Returns true if the predicate evaluates to false for every element of the iterable, or returns false.
|
static <T,P> boolean |
noneSatisfyWith(Iterable<T> iterable,
Predicate2<? super T,? super P> predicate,
P parameter)
Returns true if the predicate evaluates to false for every element of the iterable, or returns false.
|
static boolean |
notEmpty(Iterable<?> iterable)
A null-safe check on a collection to see if it is notEmpty.
|
static <T> PartitionIterable<T> |
partition(Iterable<T> iterable,
Predicate<? super T> predicate)
Filters a collection into a PartitionIterable based on a predicate.
|
static <T,P> PartitionIterable<T> |
partitionWith(Iterable<T> iterable,
Predicate2<? super T,? super P> predicate,
P parameter)
Filters a collection into a PartitionIterable based on a predicate.
|
static <T,A,R> R |
reduceInPlace(Iterable<T> iterable,
Collector<? super T,A,R> collector)
This method produces the equivalent result as
Stream.collect(Collector) . |
static <T,R> R |
reduceInPlace(Iterable<T> iterable,
Supplier<R> supplier,
BiConsumer<R,? super T> accumulator)
This method produces the equivalent result as
Stream.collect(Supplier, BiConsumer, BiConsumer) . |
static <T> Collection<T> |
reject(Iterable<T> iterable,
Predicate<? super T> predicate)
Returns all elements of the iterable that evaluate to false for the specified predicate.
|
static <T,R extends Collection<T>> |
reject(Iterable<T> iterable,
Predicate<? super T> predicate,
R targetCollection)
Same as the reject method with one parameter but uses the specified target collection for the results.
|
static <T,P> Collection<T> |
rejectWith(Iterable<T> iterable,
Predicate2<? super T,? super P> predicate,
P parameter)
Similar to
reject(Iterable, Predicate) , except with an evaluation parameter for the second generic argument in Predicate2 . |
static <T,P,R extends Collection<T>> |
rejectWith(Iterable<T> iterable,
Predicate2<? super T,? super P> predicate,
P parameter,
R targetCollection)
Same as the reject method with two parameters but uses the specified target collection.
|
static <T,R extends Collection<T>> |
removeAllFrom(Iterable<? extends T> iterable,
R targetCollection)
Remove all elements present in Iterable from the target collection, return the target collection.
|
static <T> boolean |
removeAllIterable(Iterable<? extends T> iterable,
Collection<T> targetCollection)
Remove all elements present in Iterable from the target collection, returns true if any element was removed.
|
static <T> boolean |
removeIf(Iterable<T> iterable,
Predicate<? super T> predicate)
Removes all elements from the iterable that evaluate to true for the specified predicate.
|
static <T,P> boolean |
removeIfWith(Iterable<T> iterable,
Predicate2<? super T,? super P> predicate,
P parameter)
Removes all elements of the iterable that evaluate to true for the specified predicate2 and parameter.
|
static <T> Collection<T> |
select(Iterable<T> iterable,
Predicate<? super T> predicate)
Returns a new collection with only the elements that evaluated to true for the specified predicate.
|
static <T,R extends Collection<T>> |
select(Iterable<T> iterable,
Predicate<? super T> predicate,
R targetCollection)
Same as the select method with two parameters but uses the specified target collection
|
static <T,IV> Twin<MutableList<T>> |
selectAndRejectWith(Iterable<T> iterable,
Predicate2<? super T,? super IV> predicate,
IV injectedValue)
Filters a collection into two separate collections based on a predicate returned via a Twin.
|
static <T> Collection<T> |
selectInstancesOf(Iterable<?> iterable,
Class<T> clazz)
Returns a new collection with only the elements that are instances of the Class
clazz . |
static <T,IV> Collection<T> |
selectWith(Iterable<T> iterable,
Predicate2<? super T,? super IV> predicate,
IV parameter)
Returns a new collection with only elements that evaluated to true for the specified predicate and parameter.
|
static <T,P,R extends Collection<T>> |
selectWith(Iterable<T> iterable,
Predicate2<? super T,? super P> predicate,
P parameter,
R targetCollection)
Same as the selectWith method with two parameters but uses the specified target collection.
|
static int |
sizeOf(Iterable<?> iterable)
Returns the size of an iterable.
|
static <T extends Comparable<? super T>,L extends List<T>> |
sortThis(L list)
SortThis is a mutating method.
|
static <T,L extends List<T>> |
sortThis(L list,
Comparator<? super T> comparator)
SortThis is a mutating method.
|
static <T,L extends List<T>> |
sortThis(L list,
Predicate2<? super T,? super T> predicate)
SortThis is a mutating method.
|
static <T,V extends Comparable<? super V>,L extends List<T>> |
sortThisBy(L list,
Function<? super T,? extends V> function)
Sort the list by comparing an attribute defined by the function.
|
static <V,T> MutableMap<V,BigDecimal> |
sumByBigDecimal(Iterable<T> iterable,
Function<T,V> groupBy,
Function<? super T,BigDecimal> function)
Groups and sums the values of the iterable using the two specified functions.
|
static <V,T> MutableMap<V,BigInteger> |
sumByBigInteger(Iterable<T> iterable,
Function<T,V> groupBy,
Function<? super T,BigInteger> function)
Groups and sums the values of the iterable using the two specified functions.
|
static <T,V> ObjectDoubleMap<V> |
sumByDouble(Iterable<T> iterable,
Function<T,V> groupBy,
DoubleFunction<? super T> function) |
static <T,V> ObjectDoubleMap<V> |
sumByFloat(Iterable<T> iterable,
Function<T,V> groupBy,
FloatFunction<? super T> function) |
static <T,V> ObjectLongMap<V> |
sumByInt(Iterable<T> iterable,
Function<T,V> groupBy,
IntFunction<? super T> function) |
static <T,V> ObjectLongMap<V> |
sumByLong(Iterable<T> iterable,
Function<T,V> groupBy,
LongFunction<? super T> function) |
static <T> BigDecimal |
sumOfBigDecimal(Iterable<T> iterable,
Function<? super T,BigDecimal> function)
Returns the BigDecimal sum of the result of applying the function to each element of the iterable.
|
static <T> BigInteger |
sumOfBigInteger(Iterable<T> iterable,
Function<? super T,BigInteger> function)
Returns the BigInteger sum of the result of applying the function to each element of the iterable.
|
static <T> double |
sumOfDouble(Iterable<T> iterable,
DoubleFunction<? super T> function) |
static <T> double |
sumOfFloat(Iterable<T> iterable,
FloatFunction<? super T> function) |
static <T> long |
sumOfInt(Iterable<T> iterable,
IntFunction<? super T> function) |
static <T> long |
sumOfLong(Iterable<T> iterable,
LongFunction<? super T> function) |
static <T> Collection<T> |
take(Iterable<T> iterable,
int count)
Returns the first
count elements of the iterable
or all the elements in the iterable if count is greater than the length of
the iterable. |
static <T> T[] |
toArray(Iterable<? extends T> iterable,
T[] target)
Copies the specified iterable into the specified array.
|
static <T> Object[] |
toArray(Iterable<T> iterable)
Converts the specified iterable to an array.
|
static <T,K> MutableMap<K,T> |
toMap(Iterable<T> iterable,
Function<? super T,? extends K> keyFunction)
Iterate over the specified collection applying the specified Function to each element to calculate
a key and return the results as a Map.
|
static <T,K,V> MutableMap<K,V> |
toMap(Iterable<T> iterable,
Function<? super T,? extends K> keyFunction,
Function<? super T,? extends V> valueFunction)
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.
|
static <T,K,V,R extends MutableMultimap<K,V>> |
toMultimap(Iterable<T> iterable,
Function<? super T,? extends K> keyFunction,
Function<? super T,? extends Iterable<V>> valuesFunction,
R targetMultimap)
Iterate over the specified collection applying the specified Functions to each element to calculate
a key and values, add the results to
targetMultimap and return the targetMultimap . |
static <T extends Comparable<? super T>> |
toSortedList(Iterable<T> iterable)
Return the specified collection as a sorted List.
|
static <T> MutableList<T> |
toSortedList(Iterable<T> iterable,
Comparator<? super T> comparator)
Return the specified collection as a sorted List using the specified Comparator.
|
static <X,Y> Collection<Pair<X,Y>> |
zip(Iterable<X> xs,
Iterable<Y> ys) |
static <X,Y,R extends Collection<Pair<X,Y>>> |
zip(Iterable<X> xs,
Iterable<Y> ys,
R targetCollection) |
static <T> Collection<Pair<T,Integer>> |
zipWithIndex(Iterable<T> iterable) |
static <T,R extends Collection<Pair<T,Integer>>> |
zipWithIndex(Iterable<T> iterable,
R targetCollection) |
public static <T> void forEach(Iterable<T> iterable, Procedure<? super T> procedure)
Example using a Java 8 lambda expression:
Iterate.forEach(people, person -> LOGGER.info(person.getName());
Example using an anonymous inner class:
Iterate.forEach(people, new Procedure() { public void value(Person person) { LOGGER.info(person.getName()); } });
public static <T,P> void forEachWith(Iterable<T> iterable, Procedure2<? super T,? super P> procedure, P parameter)
Example using a Java 8 lambda expression:
Iterate.forEachWith(people, (Person person, Person other) -> { if (other.equals(person)) { LOGGER.info(person.getName()); } }, fred);
e.g. Iterate.forEachWith(people, new Procedure2() { public void value(Person person, Person other) { if (person.isRelatedTo(other)) { LOGGER.info(person.getName()); } } }, fred);
public static <T> void forEachWithIndex(Iterable<T> iterable, ObjectIntProcedure<? super T> objectIntProcedure)
Example using a Java 8 lambda expression:
Iterate.forEachWithIndex(people, (Person person, int index) -> LOGGER.info("Index: " + index + " person: " + person.getName()));
Example using anonymous inner class:
Iterate.forEachWithIndex(people, new ObjectIntProcedure() { public void value(Person person, int index) { LOGGER.info("Index: " + index + " person: " + person.getName()); } });
public static <T> Collection<T> select(Iterable<T> iterable, Predicate<? super T> predicate)
Example using a Java 8 lambda expression:
Collection<Person> selected = Iterate.select(people, person -> person.getAddress().getCity().equals("Metuchen"));
Example using an anonymous inner class:
e.g. Collection<Person> selected = Iterate.select(people, new Predicate<Person>() { public boolean accept(Person person) { return person.getAddress().getCity().equals("Metuchen"); } });
public static <T,IV> Collection<T> selectWith(Iterable<T> iterable, Predicate2<? super T,? super IV> predicate, IV parameter)
Example using a Java 8 lambda expression:
Collection<Person> selected = Iterate.selectWith(people, (Person person, Integer age) -> person.getAge() >= age, Integer.valueOf(18));
Example using an anonymous inner class:
Collection<Person> selected = Iterate.selectWith(people, new Predicate2<Person, Integer>() { public boolean accept(Person person, Integer age) { return person.getAge() >= age; } }, Integer.valueOf(18));
public static <T,IV> Twin<MutableList<T>> selectAndRejectWith(Iterable<T> iterable, Predicate2<? super T,? super IV> predicate, IV injectedValue)
Example using a Java 8 lambda expression:
Twin<MutableList<Person>>selectedRejected = Iterate.selectAndRejectWith(people, (Person person, String lastName) -> lastName.equals(person.getLastName()), "Mason");
Example using an anonymous inner class:
Twin<MutableList<Person>>selectedRejected = Iterate.selectAndRejectWith(people, new Predicate2<String, String>() { public boolean accept(Person person, String lastName) { return lastName.equals(person.getLastName()); } }, "Mason");
public static <T> PartitionIterable<T> partition(Iterable<T> iterable, Predicate<? super T> predicate)
Example using a Java 8 lambda expression:
PartitionIterable<Person> newYorkersAndNonNewYorkers = Iterate.partition(people, person -> person.getAddress().getState().getName().equals("New York"));
Example using an anonymous inner class:
PartitionIterable<Person> newYorkersAndNonNewYorkers = Iterate.partition(people, new Predicate<Person>() { public boolean accept(Person person) { return person.getAddress().getState().getName().equals("New York"); } });
public static <T,P> PartitionIterable<T> partitionWith(Iterable<T> iterable, Predicate2<? super T,? super P> predicate, P parameter)
Example using a Java 8 lambda expression:
PartitionIterable<Person>> newYorkersAndNonNewYorkers = Iterate.partitionWith(people, (Person person, String state) -> person.getAddress().getState().getName().equals(state), "New York");
Example using an anonymous inner class:
PartitionIterable<Person> newYorkersAndNonNewYorkers = Iterate.partitionWith(people, new Predicate<Person, String>() { public boolean accept(Person person, String state) { return person.getAddress().getState().getName().equals(state); } }, "New York");
public static <T> Collection<T> selectInstancesOf(Iterable<?> iterable, Class<T> clazz)
clazz
.public static <T> int count(Iterable<T> iterable, Predicate<? super T> predicate)
Example using a Java 8 lambda expression:
int count = Iterate.count(people, person -> person.getAddress().getState().getName().equals("New York"));
Example using anonymous inner class
int count = Iterate.count(people, new Predicate<Person>() { public boolean accept(Person person) { return person.getAddress().getState().getName().equals("New York"); } });
public static <T,IV> int countWith(Iterable<T> iterable, Predicate2<? super T,? super IV> predicate, IV injectedValue)
e.g. return Iterate.countWith(lastNames, Predicates2.equal(), "Smith");
public static <T,V> Collection<V> collectIf(Iterable<T> iterable, Predicate<? super T> predicate, Function<? super T,? extends V> function)
public static <T,V,R extends Collection<V>> R collectIf(Iterable<T> iterable, Predicate<? super T> predicate, Function<? super T,? extends V> function, R target)
public static <T,R extends Collection<T>> R select(Iterable<T> iterable, Predicate<? super T> predicate, R targetCollection)
Example using Java 8 lambda:
MutableList<Person> selected = Iterate.select(people, person -> person.person.getLastName().equals("Smith"), FastList.newList());
Example using anonymous inner class:
MutableList<Person> selected = Iterate.select(people, new Predicate<Person>() { public boolean accept(Person person) { return person.person.getLastName().equals("Smith"); } }, FastList.newList());
Example using Predicates factory:
MutableList<Person> selected = Iterate.select(collection, Predicates.attributeEqual("lastName", "Smith"), FastList.newList());
public static <T,P,R extends Collection<T>> R selectWith(Iterable<T> iterable, Predicate2<? super T,? super P> predicate, P parameter, R targetCollection)
public static <T> Collection<T> take(Iterable<T> iterable, int count)
count
elements of the iterable
or all the elements in the iterable if count
is greater than the length of
the iterable.iterable
- the collection to take from.count
- the number of items to take.IllegalArgumentException
- if count
is less than zeropublic static <T> Collection<T> drop(Iterable<T> iterable, int count)
count
elements of the iterable
or an empty iterable if the count
is greater than the length of the iterable.iterable
- the collection to drop from.count
- the number of items to drop.IllegalArgumentException
- if count
is less than zeropublic static <T> Collection<T> reject(Iterable<T> iterable, Predicate<? super T> predicate)
Example using Java 8 lambda:
Collection<Person> rejected = Iterate.reject(people, person -> person.person.getLastName().equals("Smith"));
Example using anonymous inner class:
Collection<Person> rejected = Iterate.reject(people, new Predicate<Person>() { public boolean accept(Person person) { return person.person.getLastName().equals("Smith"); } });
Example using Predicates factory:
Collection<Person> rejected = Iterate.reject(people, Predicates.attributeEqual("lastName", "Smith"));
public static <T extends Comparable<? super T>,L extends List<T>> L sortThis(L list)
public static <T,L extends List<T>> L sortThis(L list, Comparator<? super T> comparator)
public static <T,L extends List<T>> L sortThis(L list, Predicate2<? super T,? super T> predicate)
public static <T,V extends Comparable<? super V>,L extends List<T>> L sortThisBy(L list, Function<? super T,? extends V> function)
public static <T> boolean removeIf(Iterable<T> iterable, Predicate<? super T> predicate)
public static <T,P> boolean removeIfWith(Iterable<T> iterable, Predicate2<? super T,? super P> predicate, P parameter)
public static <T,P> Collection<T> rejectWith(Iterable<T> iterable, Predicate2<? super T,? super P> predicate, P parameter)
reject(Iterable, Predicate)
, except with an evaluation parameter for the second generic argument in Predicate2
.
Example using a Java 8 lambda expression:
Collection<Person> rejected = Iterate.rejectWith(people, (Person person, Integer age) -> person.getAge() >= age, Integer.valueOf(18));
Example using an anonymous inner class:
Collection<Person> rejected = Iterate.rejectWith(people, new Predicate2<Person, Integer>() { public boolean accept(Person person, Integer age) { return person.getAge() >= age; } }, Integer.valueOf(18));
public static <T,R extends Collection<T>> R reject(Iterable<T> iterable, Predicate<? super T> predicate, R targetCollection)
Example using Java 8 lambda:
MutableList<Person> rejected = Iterate.reject(people, person -> person.person.getLastName().equals("Smith"), FastList.newList());
Example using anonymous inner class:
MutableList<Person> rejected = Iterate.reject(people, new Predicate<Person>() { public boolean accept(Person person) { return person.person.getLastName().equals("Smith"); } }, FastList.newList());
Example using Predicates factory:
MutableList<Person> rejected = Iterate.reject(people, Predicates.attributeEqual("lastName", "Smith"), FastList.newList());
public static <T,P,R extends Collection<T>> R rejectWith(Iterable<T> iterable, Predicate2<? super T,? super P> predicate, P parameter, R targetCollection)
public static <T,R extends Collection<T>> R addAllTo(Iterable<? extends T> iterable, R targetCollection)
public static <T> boolean addAllIterable(Iterable<? extends T> iterable, Collection<T> targetCollection)
public static <T,R extends Collection<T>> R removeAllFrom(Iterable<? extends T> iterable, R targetCollection)
public static <T> boolean removeAllIterable(Iterable<? extends T> iterable, Collection<T> targetCollection)
public static <T,V> Collection<V> collect(Iterable<T> iterable, Function<? super T,? extends V> function)
Example using a Java 8 lambda expression:
Collection<String> names = Iterate.collect(people, person -> person.getFirstName() + " " + person.getLastName());
Example using an anonymous inner class:
Collection<String> names = Iterate.collect(people, new Function<Person, String>() { public String valueOf(Person person) { return person.getFirstName() + " " + person.getLastName(); } });
public static <T,A,R extends Collection<A>> R collect(Iterable<T> iterable, Function<? super T,? extends A> function, R targetCollection)
collect(Iterable, Function)
method with two parameters, except that the results are gathered into the specified
targetCollection
Example using a Java 8 lambda expression:
MutableList<String> names = Iterate.collect(people, person -> person.getFirstName() + " " + person.getLastName(), FastList.newList());
Example using an anonymous inner class:
MutableList<String> names = Iterate.collect(people, new Function<Person, String>() { public String valueOf(Person person) { return person.getFirstName() + " " + person.getLastName(); } }, FastList.newList());
public static <T> MutableBooleanCollection collectBoolean(Iterable<T> iterable, BooleanFunction<? super T> booleanFunction)
boolean
collection with the results of applying the specified booleanFunction for each element of the iterable.
Example using Java 8 lambda:
MutableBooleanCollection voters = Iterable.collectBoolean(people, person -> person.canVote());
Example using anonymous inner class:
MutableBooleanCollection voters = Iterate.collectBoolean(people, new BooleanFunction<Person>() { public boolean booleanValueOf(Person person) { return person.canVote(); } });
public static <T,R extends MutableBooleanCollection> R collectBoolean(Iterable<T> iterable, BooleanFunction<? super T> booleanFunction, R target)
collectBoolean(Iterable, BooleanFunction)
, except that the results are gathered into the specified target
collection.
Example using Java 8 lambda:
BooleanArrayList voters = Iterable.collectBoolean(people, person -> person.canVote(), new BooleanArrayList());
Example using an anonymous inner class:
BooleanArrayList voters = Iterate.collectBoolean(people, new BooleanFunction<Person>() { public boolean booleanValueOf(Person person) { return person.canVote(); } }, new BooleanArrayList());
public static <T> MutableByteCollection collectByte(Iterable<T> iterable, ByteFunction<? super T> byteFunction)
byte
collection with the results of applying the specified byteFunction for each element of the iterable.
Example using Java 8 lambda:
MutableByteCollection bytes = Iterate.collectByte(people, person -> person.getCode());
Example using anonymous inner class:
MutableByteCollection bytes = Iterate.collectByte(people, new ByteFunction<Person>() { public byte byteValueOf(Person person) { return person.getCode(); } });
public static <T,R extends MutableByteCollection> R collectByte(Iterable<T> iterable, ByteFunction<? super T> byteFunction, R target)
collectByte(Iterable, ByteFunction)
, except that the results are gathered into the specified target
collection.
Example using a Java 8 lambda expression:
ByteArrayList bytes = Iterate.collectByte(people, person -> person.getCode(), new ByteArrayList());
Example using an anonymous inner class:
ByteArrayList bytes = Iterate.collectByte(people, new ByteFunction<Person>() { public byte byteValueOf(Person person) { return person.getCode(); } }, new ByteArrayList());
public static <T> MutableCharCollection collectChar(Iterable<T> iterable, CharFunction<? super T> charFunction)
char
collection with the results of applying the specified charFunction for each element of the iterable.
Example using Java 8 lambda:
MutableCharCollection chars = Iterate.collectChar(people, person -> person.getMiddleInitial());
Example using anonymous inner class:
MutableCharCollection chars = Iterate.collectChar(people, new CharFunction<Person>() { public char charValueOf(Person person) { return person.getMiddleInitial(); } });
public static <T,R extends MutableCharCollection> R collectChar(Iterable<T> iterable, CharFunction<? super T> charFunction, R target)
collectChar(Iterable, CharFunction)
, except that the results are gathered into the specified target
collection.
CharArrayList chars = Iterate.collectChar(people, person -> person.getMiddleInitial());
Example using anonymous inner class:
CharArrayList chars = Iterate.collectChar(people, new CharFunction<Person>() { public char charValueOf(Person person) { return person.getMiddleInitial(); } }, new CharArrayList());
public static <T> MutableDoubleCollection collectDouble(Iterable<T> iterable, DoubleFunction<? super T> doubleFunction)
double
collection with the results of applying the specified doubleFunction for each element of the iterable.
Example using a Java 8 lambda expression:
MutableDoubleCollection doubles = Iterate.collectDouble(people, person -> person.getMilesFromNorthPole());Example using an anonymous inner class:
MutableDoubleCollection doubles = Iterate.collectDouble(people, new DoubleFunction<Person>() { public double doubleValueOf(Person person) { return person.getMilesFromNorthPole(); } });
public static <T,R extends MutableDoubleCollection> R collectDouble(Iterable<T> iterable, DoubleFunction<? super T> doubleFunction, R target)
collectDouble(Iterable, DoubleFunction)
, except that the results are gathered into the specified target
collection.
Example using a Java 8 lambda expression:
DoubleArrayList doubles = Iterate.collectDouble(people, person -> person.getMilesFromNorthPole());
Example using an anonymous inner class:
DoubleArrayList doubles = Iterate.collectDouble(people, new DoubleFunction<Person>() { public double doubleValueOf(Person person) { return person.getMilesFromNorthPole(); } }, new DoubleArrayList());
public static <T> MutableFloatCollection collectFloat(Iterable<T> iterable, FloatFunction<? super T> floatFunction)
float
collection with the results of applying the specified floatFunction for each element of the iterable.
Example using a Java 8 lambda expression:
MutableFloatCollection floats = Iterate.collectFloat(people, person -> person.getHeightInInches());
Example using an anonymous inner class:
MutableFloatCollection floats = Iterate.collectFloat(people, new FloatFunction<Person>() { public float floatValueOf(Person person) { return person.getHeightInInches(); } });
public static <T,R extends MutableFloatCollection> R collectFloat(Iterable<T> iterable, FloatFunction<? super T> floatFunction, R target)
collectFloat(Iterable, FloatFunction)
, except that the results are gathered into the specified target
collection.
Example using a Java 8 lambda expression:
FloatArrayList floats = Iterate.collectFloat(people, person -> person.getHeightInInches(), new FloatArrayList());
Example using an anonymous inner class:
FloatArrayList floats = Iterate.collectFloat(people, new FloatFunction<Person>() { public float floatValueOf(Person person) { return person.getHeightInInches(); } }, new FloatArrayList());
public static <T> MutableIntCollection collectInt(Iterable<T> iterable, IntFunction<? super T> intFunction)
int
collection with the results of applying the specified intFunction for each element of the iterable.
Example using a Java 8 lambda expression:
MutableIntCollection ages = Iterate.collectInt(people, person -> person.getAge());
Example using an anonymous inner class:
MutableIntCollection ages = Iterate.collectInt(people, new IntFunction<Person>() { public int intValueOf(Person person) { return person.getAge(); } });
public static <T,R extends MutableIntCollection> R collectInt(Iterable<T> iterable, IntFunction<? super T> intFunction, R target)
collectInt(Iterable, IntFunction)
, except that the results are gathered into the specified target
collection.
Example using a Java 8 lambda expression:
IntArrayList ages = Iterate.collectInt(people, person -> person.getAge(), new IntArrayList());
Example using an anonymous inner class:
IntArrayList ages = Iterate.collectInt(people, new IntFunction<Person>() { public int intValueOf(Person person) { return person.getAge(); } }, new IntArrayList());
public static <T> MutableLongCollection collectLong(Iterable<T> iterable, LongFunction<? super T> longFunction)
long
collection with the results of applying the specified longFunction for each element of the iterable.
Example using a Java 8 lambda expression:
MutableLongCollection longs = Iterate.collectLong(people, person -> person.getGuid());
Example using an anonymous inner class:
MutableLongCollection longs = Iterate.collectLong(people, new LongFunction<Person>() { public long longValueOf(Person person) { return person.getGuid(); } });
public static <T,R extends MutableLongCollection> R collectLong(Iterable<T> iterable, LongFunction<? super T> longFunction, R target)
collectLong(Iterable, LongFunction)
, except that the results are gathered into the specified target
collection.
Example using a Java 8 lambda expression:
LongArrayList longs = Iterate.collectLong(people, person -> person.getGuid(), new LongArrayList());
Example using an anonymous inner class:
LongArrayList longs = Iterate.collectLong(people, new LongFunction<Person>() { public long longValueOf(Person person) { return person.getGuid(); } }, new LongArrayList());
public static <T> MutableShortCollection collectShort(Iterable<T> iterable, ShortFunction<? super T> shortFunction)
short
collection with the results of applying the specified shortFunction for each element of the iterable.
Example using a Java 8 lambda expression:
MutableShortCollection shorts = Iterate.collectShort(people, person -> person.getNumberOfJunkMailItemsReceivedPerMonth());
Example using an anonymous inner class:
MutableShortCollection shorts = Iterate.collectShort(people, new ShortFunction<Person>() { public short shortValueOf(Person person) { return person.getNumberOfJunkMailItemsReceivedPerMonth(); } });
public static <T,R extends MutableShortCollection> R collectShort(Iterable<T> iterable, ShortFunction<? super T> shortFunction, R target)
collectShort(Iterable, ShortFunction)
, except that the results are gathered into the specified target
collection.
Example using a Java 8 lambda expression:
ShortArrayList shorts = Iterate.collectShort(people, person -> person.getNumberOfJunkMailItemsReceivedPerMonth(), new ShortArrayList());
Example using an anonymous inner class:
ShortArrayList shorts = Iterate.collectShort(people, new ShortFunction<Person>() { public short shortValueOf(Person person) { return person.getNumberOfJunkMailItemsReceivedPerMonth(); } }, new ShortArrayList());
public static <T,V> Collection<V> flatCollect(Iterable<T> iterable, Function<? super T,? extends Iterable<V>> function)
RichIterable.flatCollect(Function)
public static <T,A,R extends Collection<A>> R flatCollect(Iterable<T> iterable, Function<? super T,? extends Iterable<A>> function, R targetCollection)
public static <T,P,A> Collection<A> collectWith(Iterable<T> iterable, Function2<? super T,? super P,? extends A> function, P parameter)
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)
public static <T> Collection<T> flatten(Iterable<? extends Iterable<T>> iterable)
iterable
- A list of lists, e.g. { { 1, 2, 3 }, { 4, 5 }, { 6 } }public static <T,R extends Collection<T>> R flatten(Iterable<? extends Iterable<T>> iterable, R targetCollection)
flatten(Iterable)
except that the results are gathered into the specified targetCollection.public static <T> T getFirst(Iterable<T> iterable)
null
.
WARNING!!! The order of Sets are not guaranteed (except for TreeSets and other Ordered Set implementations), so if you use this method, the first element could be any element from the Set.
IllegalArgumentException
- if the Collection is nullpublic static boolean isEmpty(Iterable<?> iterable)
public static boolean notEmpty(Iterable<?> iterable)
public static <T> T getLast(Iterable<T> iterable)
null
.
WARNING!!! The order of Sets are not guaranteed (except for TreeSets and other Ordered Set implementations), so if you use this method, the last element could be any element from the Set.
IllegalArgumentException
- if the Collection is nullpublic static <T> T detect(Iterable<T> iterable, Predicate<? super T> predicate)
Example using a Java 8 lambda expression:
Person person = Iterate.detect(people, person -> person.getFirstName().equals("John") && person.getLastName().equals("Smith"));
Example using an anonymous inner class:
Person person = Iterate.detect(people, new Predicate<Person>() { public boolean accept(Person person) { return person.getFirstName().equals("John") && person.getLastName().equals("Smith"); } });
public static <T,P> T detectWith(Iterable<T> iterable, Predicate2<? super T,? super P> predicate, P parameter)
Example using a Java 8 lambda expression:
Person person = Iterate.detectWith(people, (person, fullName) -> person.getFullName().equals(fullName), "John Smith");
Example using an anonymous inner class:
Person person = Iterate.detectWith(people, new Predicate2<Person, String>() { public boolean accept(Person person, String fullName) { return person.getFullName().equals(fullName); } }, "John Smith");
public static <T> Optional<T> detectOptional(Iterable<T> iterable, Predicate<? super T> predicate)
Example using a Java 8 lambda expression:
Optional<Person> person = Iterate.detectOptional(people, person -> person.getFirstName().equals("John") && person.getLastName().equals("Smith"));
NullPointerException
- if the element selected is nullpublic static <T,P> Optional<T> detectWithOptional(Iterable<T> iterable, Predicate2<? super T,? super P> predicate, P parameter)
Example using a Java 8 lambda expression:
Optional<Person> person = Iterate.detectWithOptional(people, (person, fullName) -> person.getFullName().equals(fullName), "John Smith");
NullPointerException
- if the element selected is nullpublic static <T> T detectIfNone(Iterable<T> iterable, Predicate<? super T> predicate, T ifNone)
public static <T,P> T detectWithIfNone(Iterable<T> iterable, Predicate2<? super T,? super P> predicate, P parameter, T ifNone)
public static <T> int detectIndex(Iterable<T> iterable, Predicate<? super T> predicate)
public static <T,P> int detectIndexWith(Iterable<T> iterable, Predicate2<? super T,? super P> predicate, P parameter)
public static <T,A,R> R reduceInPlace(Iterable<T> iterable, Collector<? super T,A,R> collector)
Stream.collect(Collector)
.public static <T,R> R reduceInPlace(Iterable<T> iterable, Supplier<R> supplier, BiConsumer<R,? super T> accumulator)
Stream.collect(Supplier, BiConsumer, BiConsumer)
.
The combiner used in collect is unnecessary in the serial case, so is not included in the API.public static <T,IV> IV injectInto(IV injectValue, Iterable<T> iterable, Function2<? super IV,? super T,? extends IV> function)
public static <T> int injectInto(int injectValue, Iterable<T> iterable, IntObjectToIntFunction<? super T> function)
public static <T> long injectInto(long injectValue, Iterable<T> iterable, LongObjectToLongFunction<? super T> function)
public static <T> double injectInto(double injectValue, Iterable<T> iterable, DoubleObjectToDoubleFunction<? super T> function)
public static <T> float injectInto(float injectValue, Iterable<T> iterable, FloatObjectToFloatFunction<? super T> function)
public static <T> long sumOfInt(Iterable<T> iterable, IntFunction<? super T> function)
RichIterable.sumOfInt(IntFunction)
public static <T> long sumOfLong(Iterable<T> iterable, LongFunction<? super T> function)
RichIterable.sumOfLong(LongFunction)
public static <T> double sumOfFloat(Iterable<T> iterable, FloatFunction<? super T> function)
RichIterable.sumOfFloat(FloatFunction)
public static <T> double sumOfDouble(Iterable<T> iterable, DoubleFunction<? super T> function)
RichIterable.sumOfDouble(DoubleFunction)
public static <T> BigDecimal sumOfBigDecimal(Iterable<T> iterable, Function<? super T,BigDecimal> function)
public static <T> BigInteger sumOfBigInteger(Iterable<T> iterable, Function<? super T,BigInteger> function)
public static <V,T> MutableMap<V,BigDecimal> sumByBigDecimal(Iterable<T> iterable, Function<T,V> groupBy, Function<? super T,BigDecimal> function)
public static <V,T> MutableMap<V,BigInteger> sumByBigInteger(Iterable<T> iterable, Function<T,V> groupBy, Function<? super T,BigInteger> function)
public static <T,V> ObjectLongMap<V> sumByInt(Iterable<T> iterable, Function<T,V> groupBy, IntFunction<? super T> function)
public static <T,V> ObjectLongMap<V> sumByLong(Iterable<T> iterable, Function<T,V> groupBy, LongFunction<? super T> function)
public static <T,V> ObjectDoubleMap<V> sumByFloat(Iterable<T> iterable, Function<T,V> groupBy, FloatFunction<? super T> function)
RichIterable.sumOfFloat(FloatFunction)
public static <T,V> ObjectDoubleMap<V> sumByDouble(Iterable<T> iterable, Function<T,V> groupBy, DoubleFunction<? super T> function)
RichIterable.sumOfDouble(DoubleFunction)
public static <T,IV,P> IV injectIntoWith(IV injectValue, Iterable<T> iterable, Function3<? super IV,? super T,? super P,? extends IV> function, P parameter)
injectInto(Object, Iterable, Function2)
, except with a parameter is used as third generic argument in function3.public static <T> boolean anySatisfy(Iterable<T> iterable, Predicate<? super T> predicate)
public static <T,P> boolean anySatisfyWith(Iterable<T> iterable, Predicate2<? super T,? super P> predicate, P parameter)
public static <T> boolean allSatisfy(Iterable<T> iterable, Predicate<? super T> predicate)
public static <T,P> boolean allSatisfyWith(Iterable<T> iterable, Predicate2<? super T,? super P> predicate, P parameter)
public static <T> boolean noneSatisfy(Iterable<T> iterable, Predicate<? super T> predicate)
public static <T,P> boolean noneSatisfyWith(Iterable<T> iterable, Predicate2<? super T,? super P> predicate, P parameter)
public static <T,K> MutableMap<K,T> toMap(Iterable<T> iterable, Function<? super T,? extends K> keyFunction)
public static <T,K,V> MutableMap<K,V> toMap(Iterable<T> iterable, Function<? super T,? extends K> keyFunction, Function<? super T,? extends V> valueFunction)
public static <T,K,V,M extends Map<K,V>> M addToMap(Iterable<T> iterable, Function<? super T,? extends K> keyFunction, M map)
public static <T,K,V,M extends Map<K,V>> M addToMap(Iterable<T> iterable, Function<? super T,? extends K> keyFunction, Function<? super T,? extends V> valueFunction, M map)
public static <T,K,V,R extends MutableMultimap<K,V>> R toMultimap(Iterable<T> iterable, Function<? super T,? extends K> keyFunction, Function<? super T,? extends Iterable<V>> valuesFunction, R targetMultimap)
targetMultimap
and return the targetMultimap
.
Example using a Java 8 lambda expression:
MutableMultimap<String, String> multimap = Iterate.toMultimap(integers, each -> "key:" + each, each -> Lists.mutable.of("value:" + each), FastListMultimap.newMultimap());
Example using an anonymous inner class:
MutableMultimap<String, String> multimap = Iterate.groupByAndCollect(integers, new Function<Integer, String>() { public String valueOf(Integer each) { return "key:" + each; } }, new Function<Integer, Iterable<String>>() { public Iterable<String> valueOf(Integer each) { return Lists.mutable.of("value:" + each); } }, FastListMultimap.newMultimap());
public static <T extends Comparable<? super T>> MutableList<T> toSortedList(Iterable<T> iterable)
public static <T> MutableList<T> toSortedList(Iterable<T> iterable, Comparator<? super T> comparator)
public static int sizeOf(Iterable<?> iterable)
public static boolean contains(Iterable<?> iterable, Object value)
public static <T> Object[] toArray(Iterable<T> iterable)
public static <T> T[] toArray(Iterable<? extends T> iterable, T[] target)
public static <T,V> MutableMultimap<V,T> groupBy(Iterable<T> iterable, Function<? super T,? extends V> function)
public static <T,V,R extends MutableMultimap<V,T>> R groupBy(Iterable<T> iterable, Function<? super T,? extends V> function, R targetMultimap)
public static <T,K,V> MutableMap<K,V> aggregateInPlaceBy(Iterable<T> iterable, Function<? super T,? extends K> groupBy, Function0<? extends V> zeroValueFactory, Procedure2<? super V,? super T> mutatingAggregator)
public static <T,K,V> MutableMap<K,V> aggregateBy(Iterable<T> iterable, Function<? super T,? extends K> groupBy, Function0<? extends V> zeroValueFactory, Function2<? super V,? super T,? extends V> nonMutatingAggregator)
public static <T,V> MutableMultimap<V,T> groupByEach(Iterable<T> iterable, Function<? super T,? extends Iterable<V>> function)
public static <T,V,R extends MutableMultimap<V,T>> R groupByEach(Iterable<T> iterable, Function<? super T,? extends Iterable<V>> function, R targetCollection)
public static <T,K,V,R extends MutableMultimap<K,V>> R groupByAndCollect(Iterable<T> iterable, Function<? super T,? extends K> groupByFunction, Function<? super T,? extends V> valueFunction, R targetMultimap)
targetMultimap
and return the targetMultimap
.
Example using a Java 8 lambda expression:
MutableMultimap<String, String> multimap = Iterate.groupByAndCollect(integers, each -> "key:" + each, each -> "value:" + each, FastListMultimap.newMultimap());
Example using an anonymous inner class:
MutableMultimap<String, String> multimap = Iterate.groupByAndCollect(integers, new Function<Integer, String>() { public String valueOf(Integer each) { return "key:" + each; } }, new Function<Integer, String>() { public String valueOf(Integer each) { return "value:" + each; } }, FastListMultimap.newMultimap());
public static <V,T> MutableMap<V,T> groupByUniqueKey(Iterable<T> iterable, Function<? super T,? extends V> function)
RichIterable.groupByUniqueKey(Function)
public static <V,T,R extends MutableMap<V,T>> R groupByUniqueKey(Iterable<T> iterable, Function<? super T,? extends V> function, R target)
public static <T> T min(Iterable<T> iterable, Comparator<? super T> comparator)
RichIterable.min(Comparator)
public static <T> T max(Iterable<T> iterable, Comparator<? super T> comparator)
RichIterable.max(Comparator)
public static <T> T min(Iterable<T> iterable)
RichIterable.min()
public static <T> T max(Iterable<T> iterable)
RichIterable.max()
public static <T> T getOnly(Iterable<T> iterable)
public static <X,Y> Collection<Pair<X,Y>> zip(Iterable<X> xs, Iterable<Y> ys)
RichIterable.zip(Iterable)
public static <X,Y,R extends Collection<Pair<X,Y>>> R zip(Iterable<X> xs, Iterable<Y> ys, R targetCollection)
RichIterable.zip(Iterable, Collection)
public static <T> Collection<Pair<T,Integer>> zipWithIndex(Iterable<T> iterable)
RichIterable.zipWithIndex()
public static <T,R extends Collection<Pair<T,Integer>>> R zipWithIndex(Iterable<T> iterable, R targetCollection)
RichIterable.zipWithIndex(Collection)
public static <T> RichIterable<RichIterable<T>> chunk(Iterable<T> iterable, int size)
RichIterable.chunk(int)
public static <T> String makeString(Iterable<T> iterable)
RichIterable.makeString()
public static <T> String makeString(Iterable<T> iterable, String separator)
RichIterable.makeString(String)
public static <T> String makeString(Iterable<T> iterable, String start, String separator, String end)
public static <T> void appendString(Iterable<T> iterable, Appendable appendable)
RichIterable.appendString(Appendable)
public static <T> void appendString(Iterable<T> iterable, Appendable appendable, String separator)
public static <T> void appendString(Iterable<T> iterable, Appendable appendable, String start, String separator, String end)
public static <T,V extends Comparable<? super V>> T maxBy(Iterable<T> iterable, Function<? super T,? extends V> function)
public static <T,V extends Comparable<? super V>> T minBy(Iterable<T> iterable, Function<? super T,? extends V> function)
public static <K,V> HashBagMultimap<V,K> flip(BagMultimap<K,V> bagMultimap)
public static <K,V> HashBagMultimap<V,K> flip(ListMultimap<K,V> listMultimap)
public static <K,V> UnifiedSetMultimap<V,K> flip(SetMultimap<K,V> setMultimap)
Copyright © 2004–2016. All rights reserved.