public final class Iterate
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static <T> boolean |
addAllIterable(java.lang.Iterable<? extends T> iterable,
java.util.Collection<T> targetCollection) |
static <T,R extends java.util.Collection<T>> |
addAllTo(java.lang.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 java.util.Map<K,V>> |
addToMap(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends K> keyFunction,
com.gs.collections.api.block.function.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 return the results as a Map.
|
static <T,K,V,M extends java.util.Map<K,V>> |
addToMap(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.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 return the results as a Map.
|
static <T,K,V> com.gs.collections.api.map.MutableMap<K,V> |
aggregateBy(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends K> groupBy,
com.gs.collections.api.block.function.Function0<? extends V> zeroValueFactory,
com.gs.collections.api.block.function.Function2<? super V,? super T,? extends V> nonMutatingAggregator) |
static <T,K,V> com.gs.collections.api.map.MutableMap<K,V> |
aggregateInPlaceBy(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends K> groupBy,
com.gs.collections.api.block.function.Function0<? extends V> zeroValueFactory,
com.gs.collections.api.block.procedure.Procedure2<? super V,? super T> mutatingAggregator) |
static <T> boolean |
allSatisfy(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.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(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.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(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
Returns true if the predicate evaluates to true for any element of the iterable.
|
static <T,P> boolean |
anySatisfyWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.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(java.lang.Iterable<T> iterable,
java.lang.Appendable appendable) |
static <T> void |
appendString(java.lang.Iterable<T> iterable,
java.lang.Appendable appendable,
java.lang.String separator) |
static <T> void |
appendString(java.lang.Iterable<T> iterable,
java.lang.Appendable appendable,
java.lang.String start,
java.lang.String separator,
java.lang.String end) |
static <T> com.gs.collections.api.RichIterable<com.gs.collections.api.RichIterable<T>> |
chunk(java.lang.Iterable<T> iterable,
int size) |
static <T,A,R extends java.util.Collection<A>> |
collect(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends A> function,
R targetCollection)
Same as the collect method with two parameters, except that the results are gathered into the specified
targetCollection
|
static <T,V> java.util.Collection<V> |
collect(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.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> com.gs.collections.api.collection.primitive.MutableBooleanCollection |
collectBoolean(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.BooleanFunction<? super T> booleanFunction)
Returns a new collection with the results of applying the specified booleanFunction for each element of the iterable.
|
static <T> com.gs.collections.api.collection.primitive.MutableByteCollection |
collectByte(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.ByteFunction<? super T> byteFunction)
Returns a new collection with the results of applying the specified byteFunction for each element of the iterable.
|
static <T> com.gs.collections.api.collection.primitive.MutableCharCollection |
collectChar(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.CharFunction<? super T> charFunction)
Returns a new collection with the results of applying the specified charFunction for each element of the iterable.
|
static <T> com.gs.collections.api.collection.primitive.MutableDoubleCollection |
collectDouble(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.DoubleFunction<? super T> doubleFunction)
Returns a new collection with the results of applying the specified doubleFunction for each element of the iterable.
|
static <T> com.gs.collections.api.collection.primitive.MutableFloatCollection |
collectFloat(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.FloatFunction<? super T> floatFunction)
Returns a new collection with the results of applying the specified floatFunction for each element of the iterable.
|
static <T,V> java.util.Collection<V> |
collectIf(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate<? super T> predicate,
com.gs.collections.api.block.function.Function<? super T,? extends V> function) |
static <T,V,R extends java.util.Collection<V>> |
collectIf(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate<? super T> predicate,
com.gs.collections.api.block.function.Function<? super T,? extends V> function,
R target) |
static <T> com.gs.collections.api.collection.primitive.MutableIntCollection |
collectInt(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.IntFunction<? super T> intFunction)
Returns a new collection with the results of applying the specified intFunction for each element of the iterable.
|
static <T> com.gs.collections.api.collection.primitive.MutableLongCollection |
collectLong(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.LongFunction<? super T> longFunction)
Returns a new collection with the results of applying the specified longFunction for each element of the iterable.
|
static <T> com.gs.collections.api.collection.primitive.MutableShortCollection |
collectShort(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.ShortFunction<? super T> shortFunction)
Returns a new collection with the results of applying the specified shortFunction for each element of the iterable.
|
static <T,P,A> java.util.Collection<A> |
collectWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.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 java.util.Collection<A>> |
collectWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.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(java.lang.Iterable<?> iterable,
java.lang.Object value)
Returns true if the iterable contains the value.
|
static <T> int |
count(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
Returns the total number of elements that evaluate to true for the specified predicate.
|
static <T,IV> int |
countWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.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(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.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(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.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(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
Searches for the first occurrence where the predicate evaluates to true.
|
static <T,P> int |
detectIndexWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate2<? super T,? super P> predicate,
P parameter)
Searches for the first occurrence where the predicate evaluates to true.
|
static <T,P> T |
detectWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.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(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.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> java.util.Collection<T> |
drop(java.lang.Iterable<T> iterable,
int count)
Returns a collection without the first count elements of the iterable or the iterable itself if count is
non-positive.
|
static <T,A,R extends java.util.Collection<A>> |
flatCollect(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends java.lang.Iterable<A>> function,
R targetCollection) |
static <T,V> java.util.Collection<V> |
flatCollect(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends java.lang.Iterable<V>> function) |
static <T> java.util.Collection<T> |
flatten(java.lang.Iterable<? extends java.lang.Iterable<T>> iterable)
Flattens a collection of collections into one "flat" collection.
|
static <T,R extends java.util.Collection<T>> |
flatten(java.lang.Iterable<? extends java.lang.Iterable<T>> iterable,
R targetCollection)
Same as
flatten(Iterable) except that the results are gathered into the specified targetCollection. |
static <T> void |
forEach(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.procedure.Procedure<? super T> procedure)
The procedure is evaluated for each element of the iterable.
|
static <T,P> void |
forEachWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.procedure.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(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.procedure.primitive.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(java.lang.Iterable<T> iterable)
Returns the first element of a collection.
|
static <T> T |
getLast(java.lang.Iterable<T> iterable)
Returns the last element of a collection.
|
static <T> T |
getOnly(java.lang.Iterable<T> iterable) |
static <T,V> com.gs.collections.api.multimap.MutableMultimap<V,T> |
groupBy(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends V> function) |
static <T,V,R extends com.gs.collections.api.multimap.MutableMultimap<V,T>> |
groupBy(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends V> function,
R targetMultimap) |
static <T,V> com.gs.collections.api.multimap.MutableMultimap<V,T> |
groupByEach(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends java.lang.Iterable<V>> function) |
static <T,V,R extends com.gs.collections.api.multimap.MutableMultimap<V,T>> |
groupByEach(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends java.lang.Iterable<V>> function,
R targetCollection) |
static <T> double |
injectInto(double injectValue,
java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.DoubleObjectToDoubleFunction<? super T> function) |
static <T> float |
injectInto(float injectValue,
java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.FloatObjectToFloatFunction<? super T> function) |
static <T> int |
injectInto(int injectValue,
java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.IntObjectToIntFunction<? super T> function) |
static <T,IV> IV |
injectInto(IV injectValue,
java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function2<? super IV,? super T,? extends IV> function) |
static <T> long |
injectInto(long injectValue,
java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.LongObjectToLongFunction<? super T> function) |
static <T,IV,P> IV |
injectIntoWith(IV injectValue,
java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function3<? super IV,? super T,? super P,? extends IV> function,
P parameter) |
static boolean |
isEmpty(java.lang.Iterable<?> iterable)
A null-safe check on a collection to see if it isEmpty.
|
static <T> java.lang.String |
makeString(java.lang.Iterable<T> iterable) |
static <T> java.lang.String |
makeString(java.lang.Iterable<T> iterable,
java.lang.String separator) |
static <T> java.lang.String |
makeString(java.lang.Iterable<T> iterable,
java.lang.String start,
java.lang.String separator,
java.lang.String end) |
static <T> T |
max(java.lang.Iterable<T> iterable) |
static <T> T |
max(java.lang.Iterable<T> iterable,
java.util.Comparator<? super T> comparator) |
static <T,V extends java.lang.Comparable<? super V>> |
maxBy(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends V> function) |
static <T> T |
min(java.lang.Iterable<T> iterable) |
static <T> T |
min(java.lang.Iterable<T> iterable,
java.util.Comparator<? super T> comparator) |
static <T,V extends java.lang.Comparable<? super V>> |
minBy(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends V> function) |
static <T> boolean |
noneSatisfy(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.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(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.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(java.lang.Iterable<?> iterable)
A null-safe check on a collection to see if it is notEmpty.
|
static <T> com.gs.collections.api.partition.PartitionIterable<T> |
partition(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
Filters a collection into a PartitionIterable based on a predicate.
|
static <T> java.util.Collection<T> |
reject(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
Returns all elements of the iterable that evaluate to false for the specified predicate.
|
static <T,R extends java.util.Collection<T>> |
reject(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate<? super T> predicate,
R targetCollection)
Same as the reject method with two parameters but uses the specified target collection for the results.
|
static <T,IV> java.util.Collection<T> |
rejectWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate2<? super T,? super IV> predicate,
IV injectedValue)
Returns all elements of the iterable that evaluate to false for the specified predicate2 and parameter.
|
static <T,P,R extends java.util.Collection<T>> |
rejectWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.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> java.util.Collection<T> |
removeIf(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
Removes all elements from the iterable that evaluate to true for the specified predicate.
|
static <T,P> java.util.Collection<T> |
removeIfWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.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> java.util.Collection<T> |
select(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
Returns a new collection with only the elements that evaluated to true for the specified predicate.
|
static <T,R extends java.util.Collection<T>> |
select(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate<? super T> predicate,
R targetCollection)
Same as the select method with two parameters but uses the specified target collection
|
static <T,IV> com.gs.collections.api.tuple.Twin<com.gs.collections.api.list.MutableList<T>> |
selectAndRejectWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.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> java.util.Collection<T> |
selectInstancesOf(java.lang.Iterable<?> iterable,
java.lang.Class<T> clazz)
Returns a new collection with only the elements that are instances of the Class
clazz. |
static <T,IV> java.util.Collection<T> |
selectWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.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 java.util.Collection<T>> |
selectWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.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(java.lang.Iterable<?> iterable)
Returns the size of an iterable.
|
static <T extends java.lang.Comparable<? super T>,L extends java.util.List<T>> |
sortThis(L list)
SortThis is a mutating method.
|
static <T,L extends java.util.List<T>> |
sortThis(L list,
java.util.Comparator<? super T> comparator)
SortThis is a mutating method.
|
static <T,L extends java.util.List<T>> |
sortThis(L list,
com.gs.collections.api.block.predicate.Predicate2<? super T,? super T> predicate)
SortThis is a mutating method.
|
static <T,V extends java.lang.Comparable<V>,L extends java.util.List<T>> |
sortThisBy(L list,
com.gs.collections.api.block.function.Function<? super T,? extends V> function)
Sort the list by comparing an attribute defined by the function.
|
static <T> double |
sumOfDouble(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.DoubleFunction<? super T> function) |
static <T> double |
sumOfFloat(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.FloatFunction<? super T> function) |
static <T> long |
sumOfInt(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.IntFunction<? super T> function) |
static <T> long |
sumOfLong(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.LongFunction<? super T> function) |
static <T> java.util.Collection<T> |
take(java.lang.Iterable<T> iterable,
int count)
Returns the first count elements of the iterable or the iterable itself if count is greater than the length of
the iterable.
|
static <T> T[] |
toArray(java.lang.Iterable<? extends T> iterable,
T[] target)
Copies the specified iterable into the specified array.
|
static <T> java.lang.Object[] |
toArray(java.lang.Iterable<T> iterable)
Converts the specified iterable to an array.
|
static <T,K> com.gs.collections.api.map.MutableMap<K,T> |
toMap(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.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> com.gs.collections.api.map.MutableMap<K,V> |
toMap(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends K> keyFunction,
com.gs.collections.api.block.function.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 extends java.lang.Comparable<? super T>> |
toSortedList(java.lang.Iterable<T> iterable)
Return the specified collection as a sorted List.
|
static <T> com.gs.collections.api.list.MutableList<T> |
toSortedList(java.lang.Iterable<T> iterable,
java.util.Comparator<? super T> comparator)
Return the specified collection as a sorted List using the specified Comparator.
|
static <X,Y> java.util.Collection<com.gs.collections.api.tuple.Pair<X,Y>> |
zip(java.lang.Iterable<X> xs,
java.lang.Iterable<Y> ys) |
static <X,Y,R extends java.util.Collection<com.gs.collections.api.tuple.Pair<X,Y>>> |
zip(java.lang.Iterable<X> xs,
java.lang.Iterable<Y> ys,
R targetCollection) |
static <T> java.util.Collection<com.gs.collections.api.tuple.Pair<T,java.lang.Integer>> |
zipWithIndex(java.lang.Iterable<T> iterable) |
static <T,R extends java.util.Collection<com.gs.collections.api.tuple.Pair<T,java.lang.Integer>>> |
zipWithIndex(java.lang.Iterable<T> iterable,
R targetCollection) |
public static <T> void forEach(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.procedure.Procedure<? super T> procedure)
e.g. Iterate.forEach(people, new Procedure() { public void value(Person person) { LOGGER.info(person.getName()); } });
public static <T,P> void forEachWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.procedure.Procedure2<? super T,? super P> procedure,
P parameter)
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(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure<? super T> objectIntProcedure)
public static <T> java.util.Collection<T> select(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
e.g.
return Iterate.select(collection, new Predicate<Person>()
{
public boolean value(Person person)
{
return person.getAddress().getCity().equals("Metuchen");
}
});
public static <T,IV> java.util.Collection<T> selectWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate2<? super T,? super IV> predicate,
IV parameter)
e.g. return Iterate.selectWith(integers, Predicates2.equal(), new Integer(5));
public static <T,IV> com.gs.collections.api.tuple.Twin<com.gs.collections.api.list.MutableList<T>> selectAndRejectWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate2<? super T,? super IV> predicate,
IV injectedValue)
e.g. return Iterate.selectAndRejectWith(lastNames, Predicates2.lessThan(), "Mason");
public static <T> com.gs.collections.api.partition.PartitionIterable<T> partition(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
e.g.
return Iterate.partition(collection, new Predicate<Person>()
{
public boolean value(Person person)
{
return person.getAddress().getState().getName().equals("New York");
}
});
public static <T> java.util.Collection<T> selectInstancesOf(java.lang.Iterable<?> iterable,
java.lang.Class<T> clazz)
clazz.public static <T> int count(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
e.g.
return Iterate.count(collection, new Predicate<Person>()
{
public boolean value(Person person)
{
return person.getAddress().getState().getName().equals("New York");
}
});
public static <T,IV> int countWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate2<? super T,? super IV> predicate,
IV injectedValue)
e.g. return Iterate.countWith(lastNames, Predicates2.equal(), "Smith");
public static <T,V> java.util.Collection<V> collectIf(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate<? super T> predicate,
com.gs.collections.api.block.function.Function<? super T,? extends V> function)
RichIterable.collectIf(Predicate, Function)public static <T,V,R extends java.util.Collection<V>> R collectIf(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate<? super T> predicate,
com.gs.collections.api.block.function.Function<? super T,? extends V> function,
R target)
RichIterable.collectIf(Predicate, Function, Collection)public static <T,R extends java.util.Collection<T>> R select(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate<? super T> predicate,
R targetCollection)
e.g.
return Iterate.select(collection, new Predicate<Person>()
{
public boolean value(Person person)
{
return person.person.getLastName().equals("Smith");
}
}, FastList.newList());
e.g.
return Iterate.select(collection, Predicates.attributeEqual("lastName", "Smith"), new ArrayList());
public static <T,P,R extends java.util.Collection<T>> R selectWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate2<? super T,? super P> predicate,
P parameter,
R targetCollection)
public static <T> java.util.Collection<T> take(java.lang.Iterable<T> iterable,
int count)
iterable - the collection to take from.count - the number of items to take.public static <T> java.util.Collection<T> drop(java.lang.Iterable<T> iterable,
int count)
iterable - the collection to drop from.count - the number of items to drop.public static <T> java.util.Collection<T> reject(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
e.g.
return Iterate.reject(collection, new Predicate<Person>()
{
public boolean value(Person person)
{
return person.person.getLastName().equals("Smith");
}
});
e.g.
return Iterate.reject(collection, Predicates.attributeEqual("lastName", "Smith"));
public static <T extends java.lang.Comparable<? super T>,L extends java.util.List<T>> L sortThis(L list)
public static <T,L extends java.util.List<T>> L sortThis(L list,
java.util.Comparator<? super T> comparator)
public static <T,L extends java.util.List<T>> L sortThis(L list,
com.gs.collections.api.block.predicate.Predicate2<? super T,? super T> predicate)
public static <T,V extends java.lang.Comparable<V>,L extends java.util.List<T>> L sortThisBy(L list,
com.gs.collections.api.block.function.Function<? super T,? extends V> function)
public static <T> java.util.Collection<T> removeIf(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
public static <T,P> java.util.Collection<T> removeIfWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate2<? super T,? super P> predicate,
P parameter)
public static <T,IV> java.util.Collection<T> rejectWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate2<? super T,? super IV> predicate,
IV injectedValue)
public static <T,R extends java.util.Collection<T>> R reject(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate<? super T> predicate,
R targetCollection)
e.g.
return Iterate.reject(collection, new Predicate<Person>()
{
public boolean value(Person person)
{
return person.person.getLastName().equals("Smith");
}
}, FastList.newList());
public static <T,P,R extends java.util.Collection<T>> R rejectWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate2<? super T,? super P> predicate,
P parameter,
R targetCollection)
public static <T,R extends java.util.Collection<T>> R addAllTo(java.lang.Iterable<? extends T> iterable,
R targetCollection)
public static <T> boolean addAllIterable(java.lang.Iterable<? extends T> iterable,
java.util.Collection<T> targetCollection)
public static <T,V> java.util.Collection<V> collect(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends V> function)
e.g.
return Iterate.collect(collection, new Function<Person, String>()
{
public String value(Person person)
{
return person.getFirstName() + " " + person.getLastName();
}
});
public static <T> com.gs.collections.api.collection.primitive.MutableBooleanCollection collectBoolean(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.BooleanFunction<? super T> booleanFunction)
e.g.
return Iterate.collectBoolean(collection, new BooleanFunction<Person>()
{
public boolean booleanValueOf(Person person)
{
return person.canVote();
}
});
public static <T> com.gs.collections.api.collection.primitive.MutableByteCollection collectByte(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.ByteFunction<? super T> byteFunction)
e.g.
return Iterate.collectByte(collection, new ByteFunction<Person>()
{
public byte byteValueOf(Person person)
{
return person.getAge();
}
});
public static <T> com.gs.collections.api.collection.primitive.MutableCharCollection collectChar(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.CharFunction<? super T> charFunction)
e.g.
return Iterate.collectChar(collection, new CharFunction<Person>()
{
public char charValueOf(Person person)
{
return person.getMiddleInitial();
}
});
public static <T> com.gs.collections.api.collection.primitive.MutableDoubleCollection collectDouble(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.DoubleFunction<? super T> doubleFunction)
e.g.
return Iterate.collectDouble(collection, new DoubleFunction<Person>()
{
public double doubleValueOf(Person person)
{
return person.getAge();
}
});
public static <T> com.gs.collections.api.collection.primitive.MutableFloatCollection collectFloat(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.FloatFunction<? super T> floatFunction)
e.g.
return Iterate.collectFloat(collection, new FloatFunction<Person>()
{
public float floatValueOf(Person person)
{
return person.getAge();
}
});
public static <T> com.gs.collections.api.collection.primitive.MutableIntCollection collectInt(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.IntFunction<? super T> intFunction)
e.g.
return Iterate.collectInt(collection, new IntFunction<Person>()
{
public int intValueOf(Person person)
{
return person.getAge();
}
});
public static <T> com.gs.collections.api.collection.primitive.MutableLongCollection collectLong(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.LongFunction<? super T> longFunction)
e.g.
return Iterate.collectLong(collection, new LongFunction<Person>()
{
public long longValueOf(Person person)
{
return person.getGuid();
}
});
public static <T> com.gs.collections.api.collection.primitive.MutableShortCollection collectShort(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.ShortFunction<? super T> shortFunction)
e.g.
return Iterate.collectShort(collection, new ShortFunction<Person>()
{
public short shortValueOf(Person person)
{
return person.getAge();
}
});
public static <T,V> java.util.Collection<V> flatCollect(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends java.lang.Iterable<V>> function)
RichIterable.flatCollect(Function)public static <T,A,R extends java.util.Collection<A>> R collect(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends A> function,
R targetCollection)
e.g.
return Iterate.collect(collection, new Function<Person, String>()
{
public String value(Person person)
{
return person.getFirstName() + " " + person.getLastName();
}
}, FastList.newList());
public static <T,A,R extends java.util.Collection<A>> R flatCollect(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends java.lang.Iterable<A>> function,
R targetCollection)
RichIterable.flatCollect(Function, Collection)public static <T,P,A> java.util.Collection<A> collectWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function2<? super T,? super P,? extends A> function,
P parameter)
public static <T,P,A,R extends java.util.Collection<A>> R collectWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function2<? super T,? super P,? extends A> function,
P parameter,
R targetCollection)
public static <T> java.util.Collection<T> flatten(java.lang.Iterable<? extends java.lang.Iterable<T>> iterable)
iterable - A list of lists, e.g. { { 1, 2, 3 }, { 4, 5 }, { 6 } }public static <T,R extends java.util.Collection<T>> R flatten(java.lang.Iterable<? extends java.lang.Iterable<T>> iterable,
R targetCollection)
flatten(Iterable) except that the results are gathered into the specified targetCollection.public static <T> T getFirst(java.lang.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.java.lang.IllegalArgumentException - if the Collection is nullpublic static boolean isEmpty(java.lang.Iterable<?> iterable)
public static boolean notEmpty(java.lang.Iterable<?> iterable)
public static <T> T getLast(java.lang.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.java.lang.IllegalArgumentException - if the Collection is nullpublic static <T> T detect(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
e.g.
return Iterate.detect(collection, new Predicate<Person>()
{
public boolean value(Person person)
{
return person.getFirstName().equals("John") && person.getLastName().equals("Smith");
}
});
public static <T,P> T detectWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate2<? super T,? super P> predicate,
P parameter)
e.g.
Iterate.detectWith(collection, new Predicate2<Person, String>()
{
public boolean value(Person person, String fullName)
{
return person.getFullName().equals(fullName);
}
}, "John Smith");
public static <T> T detectIfNone(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate<? super T> predicate,
T ifNone)
public static <T,P> T detectWithIfNone(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate2<? super T,? super P> predicate,
P parameter,
T ifNone)
public static <T> int detectIndex(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
public static <T,P> int detectIndexWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate2<? super T,? super P> predicate,
P parameter)
public static <T,IV> IV injectInto(IV injectValue,
java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function2<? super IV,? super T,? extends IV> function)
RichIterable.injectInto(Object, Function2)public static <T> int injectInto(int injectValue,
java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.IntObjectToIntFunction<? super T> function)
RichIterable.injectInto(int, IntObjectToIntFunction)public static <T> long injectInto(long injectValue,
java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.LongObjectToLongFunction<? super T> function)
RichIterable.injectInto(long, LongObjectToLongFunction)public static <T> double injectInto(double injectValue,
java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.DoubleObjectToDoubleFunction<? super T> function)
RichIterable.injectInto(double, DoubleObjectToDoubleFunction)public static <T> float injectInto(float injectValue,
java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.FloatObjectToFloatFunction<? super T> function)
RichIterable.injectInto(float, FloatObjectToFloatFunction)public static <T> long sumOfInt(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.IntFunction<? super T> function)
RichIterable.sumOfInt(IntFunction)public static <T> long sumOfLong(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.LongFunction<? super T> function)
RichIterable.sumOfLong(LongFunction)public static <T> double sumOfFloat(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.FloatFunction<? super T> function)
RichIterable.sumOfFloat(FloatFunction)public static <T> double sumOfDouble(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.primitive.DoubleFunction<? super T> function)
RichIterable.sumOfDouble(DoubleFunction)public static <T,IV,P> IV injectIntoWith(IV injectValue,
java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function3<? super IV,? super T,? super P,? extends IV> function,
P parameter)
public static <T> boolean anySatisfy(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
public static <T,P> boolean anySatisfyWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate2<? super T,? super P> predicate,
P parameter)
public static <T> boolean allSatisfy(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
public static <T,P> boolean allSatisfyWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate2<? super T,? super P> predicate,
P parameter)
public static <T> boolean noneSatisfy(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
public static <T,P> boolean noneSatisfyWith(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.predicate.Predicate2<? super T,? super P> predicate,
P parameter)
public static <T,K> com.gs.collections.api.map.MutableMap<K,T> toMap(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends K> keyFunction)
public static <T,K,V> com.gs.collections.api.map.MutableMap<K,V> toMap(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends K> keyFunction,
com.gs.collections.api.block.function.Function<? super T,? extends V> valueFunction)
public static <T,K,V,M extends java.util.Map<K,V>> M addToMap(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends K> keyFunction,
M map)
public static <T,K,V,M extends java.util.Map<K,V>> M addToMap(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends K> keyFunction,
com.gs.collections.api.block.function.Function<? super T,? extends V> valueFunction,
M map)
public static <T extends java.lang.Comparable<? super T>> com.gs.collections.api.list.MutableList<T> toSortedList(java.lang.Iterable<T> iterable)
public static <T> com.gs.collections.api.list.MutableList<T> toSortedList(java.lang.Iterable<T> iterable,
java.util.Comparator<? super T> comparator)
public static int sizeOf(java.lang.Iterable<?> iterable)
public static boolean contains(java.lang.Iterable<?> iterable,
java.lang.Object value)
public static <T> java.lang.Object[] toArray(java.lang.Iterable<T> iterable)
public static <T> T[] toArray(java.lang.Iterable<? extends T> iterable,
T[] target)
public static <T,V> com.gs.collections.api.multimap.MutableMultimap<V,T> groupBy(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends V> function)
RichIterable.groupBy(Function)public static <T,V,R extends com.gs.collections.api.multimap.MutableMultimap<V,T>> R groupBy(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends V> function,
R targetMultimap)
RichIterable.groupBy(Function, MutableMultimap)public static <T,K,V> com.gs.collections.api.map.MutableMap<K,V> aggregateInPlaceBy(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends K> groupBy,
com.gs.collections.api.block.function.Function0<? extends V> zeroValueFactory,
com.gs.collections.api.block.procedure.Procedure2<? super V,? super T> mutatingAggregator)
RichIterable.aggregateInPlaceBy(Function, Function0, Procedure2)public static <T,K,V> com.gs.collections.api.map.MutableMap<K,V> aggregateBy(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends K> groupBy,
com.gs.collections.api.block.function.Function0<? extends V> zeroValueFactory,
com.gs.collections.api.block.function.Function2<? super V,? super T,? extends V> nonMutatingAggregator)
RichIterable.aggregateBy(Function, Function0, Function2)public static <T,V> com.gs.collections.api.multimap.MutableMultimap<V,T> groupByEach(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends java.lang.Iterable<V>> function)
RichIterable.groupByEach(Function)public static <T,V,R extends com.gs.collections.api.multimap.MutableMultimap<V,T>> R groupByEach(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends java.lang.Iterable<V>> function,
R targetCollection)
RichIterable.groupByEach(Function, MutableMultimap)public static <T> T min(java.lang.Iterable<T> iterable,
java.util.Comparator<? super T> comparator)
RichIterable.min(Comparator)public static <T> T max(java.lang.Iterable<T> iterable,
java.util.Comparator<? super T> comparator)
RichIterable.max(Comparator)public static <T> T min(java.lang.Iterable<T> iterable)
RichIterable.min()public static <T> T max(java.lang.Iterable<T> iterable)
RichIterable.max()public static <T> T getOnly(java.lang.Iterable<T> iterable)
public static <X,Y> java.util.Collection<com.gs.collections.api.tuple.Pair<X,Y>> zip(java.lang.Iterable<X> xs,
java.lang.Iterable<Y> ys)
RichIterable.zip(Iterable)public static <X,Y,R extends java.util.Collection<com.gs.collections.api.tuple.Pair<X,Y>>> R zip(java.lang.Iterable<X> xs,
java.lang.Iterable<Y> ys,
R targetCollection)
RichIterable.zip(Iterable, Collection)public static <T> java.util.Collection<com.gs.collections.api.tuple.Pair<T,java.lang.Integer>> zipWithIndex(java.lang.Iterable<T> iterable)
RichIterable.zipWithIndex()public static <T,R extends java.util.Collection<com.gs.collections.api.tuple.Pair<T,java.lang.Integer>>> R zipWithIndex(java.lang.Iterable<T> iterable,
R targetCollection)
RichIterable.zipWithIndex(Collection)public static <T> com.gs.collections.api.RichIterable<com.gs.collections.api.RichIterable<T>> chunk(java.lang.Iterable<T> iterable,
int size)
RichIterable.chunk(int)public static <T> java.lang.String makeString(java.lang.Iterable<T> iterable)
RichIterable.makeString()public static <T> java.lang.String makeString(java.lang.Iterable<T> iterable,
java.lang.String separator)
RichIterable.makeString(String)public static <T> java.lang.String makeString(java.lang.Iterable<T> iterable,
java.lang.String start,
java.lang.String separator,
java.lang.String end)
RichIterable.makeString(String, String, String)public static <T> void appendString(java.lang.Iterable<T> iterable,
java.lang.Appendable appendable)
RichIterable.appendString(Appendable)public static <T> void appendString(java.lang.Iterable<T> iterable,
java.lang.Appendable appendable,
java.lang.String separator)
RichIterable.appendString(Appendable, String)public static <T> void appendString(java.lang.Iterable<T> iterable,
java.lang.Appendable appendable,
java.lang.String start,
java.lang.String separator,
java.lang.String end)
RichIterable.appendString(Appendable, String, String, String)public static <T,V extends java.lang.Comparable<? super V>> T maxBy(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends V> function)
public static <T,V extends java.lang.Comparable<? super V>> T minBy(java.lang.Iterable<T> iterable,
com.gs.collections.api.block.function.Function<? super T,? extends V> function)