public class ImmutableHashBag<T> extends AbstractImmutableBag<T> implements java.io.Serializable
| Constructor and Description |
|---|
ImmutableHashBag() |
ImmutableHashBag(com.gs.collections.api.bag.Bag<? extends T> source) |
ImmutableHashBag(java.lang.Iterable<? extends T> source) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
allSatisfy(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 if the iterable is empty.
|
boolean |
anySatisfy(com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
Returns true if the predicate evaluates to true for any element of the iterable.
|
void |
appendString(java.lang.Appendable appendable)
Prints a string representation of this collection onto the given
Appendable. |
void |
appendString(java.lang.Appendable appendable,
java.lang.String separator)
Prints a string representation of this collection onto the given
Appendable. |
void |
appendString(java.lang.Appendable appendable,
java.lang.String start,
java.lang.String separator,
java.lang.String end)
Prints a string representation of this collection onto the given
Appendable. |
com.gs.collections.api.LazyIterable<T> |
asLazy()
Returns a lazy (deferred) iterable, most likely implemented by calling LazyIterate.adapt(this).
|
<V> com.gs.collections.api.bag.ImmutableBag<V> |
collect(com.gs.collections.api.block.function.Function<? super T,? extends V> function)
Returns a new collection with the results of applying the specified function on each element of the source
collection.
|
<V,R extends java.util.Collection<V>> |
collect(com.gs.collections.api.block.function.Function<? super T,? extends V> function,
R target)
Same as
RichIterable.collect(Function), except that the results are gathered into the specified target
collection. |
<V> com.gs.collections.api.bag.ImmutableBag<V> |
collectIf(com.gs.collections.api.block.predicate.Predicate<? super T> predicate,
com.gs.collections.api.block.function.Function<? super T,? extends V> function)
Returns a new collection with the results of applying the specified function on each element of the source
collection, but only for those elements which return true upon evaluation of the predicate.
|
<V,R extends java.util.Collection<V>> |
collectIf(com.gs.collections.api.block.predicate.Predicate<? super T> predicate,
com.gs.collections.api.block.function.Function<? super T,? extends V> function,
R target)
Same as the collectIf method with two parameters but uses the specified target collection for the results.
|
<P,V,R extends java.util.Collection<V>> |
collectWith(com.gs.collections.api.block.function.Function2<? super T,? super P,? extends V> function,
P parameter,
R targetCollection)
Same as collectWith but with a targetCollection parameter to gather the results.
|
boolean |
contains(java.lang.Object object)
Returns true if the iterable has an element which responds true to element.equals(object).
|
boolean |
containsAllArguments(java.lang.Object... elements)
Returns true if all elements in the specified var arg array are contained in this collection.
|
boolean |
containsAllIterable(java.lang.Iterable<?> source)
Returns true if all elements in source are contained in this collection.
|
int |
count(com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
Return the total number of elements that answer true to the specified predicate.
|
T |
detect(com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
Returns the first element of the iterable for which the predicate evaluates to true or null in the case where no
element returns true.
|
T |
detectIfNone(com.gs.collections.api.block.predicate.Predicate<? super T> predicate,
com.gs.collections.api.block.function.Function0<? extends T> function)
Returns the first element of the iterable for which the predicate evaluates to true.
|
boolean |
equals(java.lang.Object obj)
Two bagsb1 and b2 are equal if m1.toMapOfItemToCount().equals(m2.toMapOfItemToCount()).
|
<V> com.gs.collections.api.bag.ImmutableBag<V> |
flatCollect(com.gs.collections.api.block.function.Function<? super T,? extends java.lang.Iterable<V>> function)
flatCollect is a special case of RichIterable.collect(Function). |
<V,R extends java.util.Collection<V>> |
flatCollect(com.gs.collections.api.block.function.Function<? super T,? extends java.lang.Iterable<V>> function,
R target)
Same as flatCollect, only the results are collected into the target collection.
|
void |
forEach(com.gs.collections.api.block.procedure.Procedure<? super T> procedure)
The procedure is executed for each element in the iterable.
|
<P> void |
forEachWith(com.gs.collections.api.block.procedure.Procedure2<? super T,? super P> procedure,
P parameter)
The procedure2 is evaluated for each element in the iterable with the specified parameter provided
as the second argument.
|
void |
forEachWithIndex(com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure<? super T> objectIntProcedure)
Iterates over the iterable passing each element and the current relative int index to the specified instance of
ObjectIntProcedure
|
void |
forEachWithOccurrences(com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure<? super T> objectIntProcedure)
For each distinct item, with the number of occurrences, execute the specified procedure.
|
T |
getFirst()
Returns the first element of an iterable.
|
T |
getLast()
Returns the last element of an iterable.
|
<V> com.gs.collections.api.multimap.bag.ImmutableBagMultimap<V,T> |
groupBy(com.gs.collections.api.block.function.Function<? super T,? extends V> function)
For each element of the iterable, the function is evaluated and the results of these evaluations are collected
into a new multimap, where the transformed value is the key and the original values are added to the same (or similar)
species of collection as the source iterable.
|
<V,R extends com.gs.collections.api.multimap.MutableMultimap<V,T>> |
groupBy(com.gs.collections.api.block.function.Function<? super T,? extends V> function,
R target)
Same as
RichIterable.groupBy(Function), except that the results are gathered into the specified target
multimap. |
<V> com.gs.collections.api.multimap.bag.ImmutableBagMultimap<V,T> |
groupByEach(com.gs.collections.api.block.function.Function<? super T,? extends java.lang.Iterable<V>> function)
Similar to
RichIterable.groupBy(Function), except the result of evaluating function will return a collection of keys
for each value. |
<V,R extends com.gs.collections.api.multimap.MutableMultimap<V,T>> |
groupByEach(com.gs.collections.api.block.function.Function<? super T,? extends java.lang.Iterable<V>> function,
R target)
Same as
RichIterable.groupByEach(Function), except that the results are gathered into the specified target
multimap. |
<V> com.gs.collections.api.map.ImmutableMap<V,T> |
groupByUniqueKey(com.gs.collections.api.block.function.Function<? super T,? extends V> function)
For each element of the iterable, the function is evaluated and he results of these evaluations are collected
into a new map, where the transformed value is the key.
|
int |
hashCode()
Returns the hash code for this Bag, defined as this.
Bag.toMapOfItemToCount().hashCode(). |
<IV> IV |
injectInto(IV injectedValue,
com.gs.collections.api.block.function.Function2<? super IV,? super T,? extends IV> function)
Returns the final result of evaluating function using each element of the iterable and the previous evaluation
result as the parameters.
|
boolean |
isEmpty()
Returns true if this iterable has zero items.
|
java.util.Iterator<T> |
iterator() |
java.lang.String |
makeString()
Returns a string representation of this collection by delegating to
RichIterable.makeString(String) and defaulting
the separator parameter to the characters ", " (comma and space). |
java.lang.String |
makeString(java.lang.String separator)
Returns a string representation of this collection by delegating to
RichIterable.makeString(String, String, String)
and defaulting the start and end parameters to "" (the empty String). |
java.lang.String |
makeString(java.lang.String start,
java.lang.String separator,
java.lang.String end)
Returns a string representation of this collection.
|
T |
max()
Returns the maximum element out of this container based on the natural order.
|
T |
max(java.util.Comparator<? super T> comparator)
Returns the maximum element out of this container based on the comparator.
|
<V extends java.lang.Comparable<? super V>> |
maxBy(com.gs.collections.api.block.function.Function<? super T,? extends V> function)
Returns the maximum elements out of this container based on the natural order of the attribute returned by Function.
|
T |
min()
Returns the minimum element out of this container based on the natural order.
|
T |
min(java.util.Comparator<? super T> comparator)
Returns the minimum element out of this container based on the comparator.
|
<V extends java.lang.Comparable<? super V>> |
minBy(com.gs.collections.api.block.function.Function<? super T,? extends V> function)
Returns the minimum elements out of this container based on the natural order of the attribute returned by Function.
|
static <T> ImmutableHashBag<T> |
newBag() |
static <T> ImmutableHashBag<T> |
newBag(java.lang.Iterable<? extends T> source) |
static <T> ImmutableHashBag<T> |
newBagWith(com.gs.collections.api.bag.Bag<? extends T> bag) |
static <T> ImmutableHashBag<T> |
newBagWith(T... elements) |
com.gs.collections.api.bag.ImmutableBag<T> |
newWith(T element) |
com.gs.collections.api.bag.ImmutableBag<T> |
newWithAll(java.lang.Iterable<? extends T> elements) |
com.gs.collections.api.bag.ImmutableBag<T> |
newWithout(T element) |
com.gs.collections.api.bag.ImmutableBag<T> |
newWithoutAll(java.lang.Iterable<? extends T> elements) |
boolean |
noneSatisfy(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 if the iterable is empty.
|
boolean |
notEmpty()
The English equivalent of !this.isEmpty()
|
int |
occurrencesOf(java.lang.Object item)
The occurrences of a distinct item in the bag.
|
com.gs.collections.api.partition.bag.PartitionImmutableBag<T> |
partition(com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
Filters a collection into a PartitionedIterable based on the evaluation of the predicate.
|
<P> com.gs.collections.api.partition.bag.PartitionImmutableBag<T> |
partitionWith(com.gs.collections.api.block.predicate.Predicate2<? super T,? super P> predicate,
P parameter)
Filters a collection into a PartitionIterable based on the evaluation of the predicate.
|
com.gs.collections.api.bag.ImmutableBag<T> |
reject(com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
Returns all elements of the source collection that return false when evaluating of the predicate.
|
<R extends java.util.Collection<T>> |
reject(com.gs.collections.api.block.predicate.Predicate<? super T> predicate,
R target)
Same as the reject method with one parameter but uses the specified target collection for the results.
|
<P,R extends java.util.Collection<T>> |
rejectWith(com.gs.collections.api.block.predicate.Predicate2<? super T,? super P> predicate,
P parameter,
R targetCollection)
Similar to
RichIterable.reject(Predicate, Collection), except with an evaluation parameter for the second generic argument in Predicate2. |
com.gs.collections.api.bag.ImmutableBag<T> |
select(com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
Returns all elements of the source collection that return true when evaluating the predicate.
|
<R extends java.util.Collection<T>> |
select(com.gs.collections.api.block.predicate.Predicate<? super T> predicate,
R target)
Same as the select method with one parameter but uses the specified target collection for the results.
|
com.gs.collections.api.bag.ImmutableBag<T> |
selectByOccurrences(com.gs.collections.api.block.predicate.primitive.IntPredicate predicate)
Returns all elements of the bag that have a number of occurrences that satisfy the predicate.
|
<S> com.gs.collections.api.bag.ImmutableBag<S> |
selectInstancesOf(java.lang.Class<S> clazz)
Returns all elements of the source collection that are instances of the Class
clazz. |
<P,R extends java.util.Collection<T>> |
selectWith(com.gs.collections.api.block.predicate.Predicate2<? super T,? super P> predicate,
P parameter,
R targetCollection)
Similar to
RichIterable.select(Predicate, Collection), except with an evaluation parameter for the second generic argument in Predicate2. |
int |
size()
Returns the number of items in this iterable.
|
int |
sizeDistinct()
The size of the Bag when counting only distinct elements.
|
java.lang.Object[] |
toArray()
Converts this iterable to an array.
|
<T> T[] |
toArray(T[] a)
Converts this iterable to an array using the specified target array, assuming the target array is as long
or longer than the iterable.
|
com.gs.collections.api.bag.MutableBag<T> |
toBag()
Converts the collection to the default MutableBag implementation.
|
com.gs.collections.api.bag.ImmutableBag<T> |
toImmutable()
Converts the UnsortedBag to an ImmutableBag.
|
com.gs.collections.api.list.MutableList<T> |
toList()
Converts the collection to a MutableList implementation.
|
<K,V> com.gs.collections.api.map.MutableMap<K,V> |
toMap(com.gs.collections.api.block.function.Function<? super T,? extends K> keyFunction,
com.gs.collections.api.block.function.Function<? super T,? extends V> valueFunction)
Converts the collection to a MutableMap implementation using the specified key and value functions.
|
com.gs.collections.api.map.MapIterable<T,java.lang.Integer> |
toMapOfItemToCount()
Converts the Bag to a Map of the Item type to its count as an Integer.
|
com.gs.collections.api.set.MutableSet<T> |
toSet()
Converts the collection to a MutableSet implementation.
|
com.gs.collections.api.list.MutableList<T> |
toSortedList()
Converts the collection to a MutableList implementation and sorts it using the natural order of the elements.
|
com.gs.collections.api.list.MutableList<T> |
toSortedList(java.util.Comparator<? super T> comparator)
Converts the collection to a MutableList implementation and sorts it using the specified comparator.
|
java.lang.String |
toString()
Returns a string representation of this collection.
|
protected java.lang.Object |
writeReplace() |
<S> com.gs.collections.api.bag.ImmutableBag<com.gs.collections.api.tuple.Pair<T,S>> |
zip(java.lang.Iterable<S> that)
Returns a
RichIterable formed from this RichIterable and another RichIterable by
combining corresponding elements in pairs. |
<S,R extends java.util.Collection<com.gs.collections.api.tuple.Pair<T,S>>> |
zip(java.lang.Iterable<S> that,
R target)
Same as
RichIterable.zip(Iterable) but uses target for output. |
com.gs.collections.api.set.ImmutableSet<com.gs.collections.api.tuple.Pair<T,java.lang.Integer>> |
zipWithIndex()
Zips this
RichIterable with its indices. |
<R extends java.util.Collection<com.gs.collections.api.tuple.Pair<T,java.lang.Integer>>> |
zipWithIndex(R target)
Same as
RichIterable.zipWithIndex() but uses target for output. |
collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectInt, collectLong, collectShort, collectWith, newMutable, rejectWith, selectWith, toStringOfItemToCountadd, addAll, aggregateBy, aggregateInPlaceBy, chunk, clear, remove, removeAll, removeAllFrom, retainAllallSatisfyWith, anySatisfyWith, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectInt, collectLong, collectShort, containsAll, countWith, detectWith, detectWithIfNone, injectInto, injectInto, injectInto, injectInto, noneSatisfyWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toSortedListBy, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toSortedSetByclone, finalize, getClass, notify, notifyAll, wait, wait, waitaggregateBy, aggregateInPlaceBy, allSatisfyWith, anySatisfyWith, chunk, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectInt, collectLong, collectShort, containsAll, countWith, detectWith, detectWithIfNone, injectInto, injectInto, injectInto, injectInto, noneSatisfyWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toSortedListBy, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toSortedSetBypublic ImmutableHashBag()
public ImmutableHashBag(java.lang.Iterable<? extends T> source)
public ImmutableHashBag(com.gs.collections.api.bag.Bag<? extends T> source)
public static <T> ImmutableHashBag<T> newBag()
public static <T> ImmutableHashBag<T> newBag(java.lang.Iterable<? extends T> source)
public static <T> ImmutableHashBag<T> newBagWith(T... elements)
public static <T> ImmutableHashBag<T> newBagWith(com.gs.collections.api.bag.Bag<? extends T> bag)
public com.gs.collections.api.bag.ImmutableBag<T> newWithAll(java.lang.Iterable<? extends T> elements)
public com.gs.collections.api.bag.ImmutableBag<T> newWithoutAll(java.lang.Iterable<? extends T> elements)
public int size()
com.gs.collections.api.RichIterablepublic <V> com.gs.collections.api.multimap.bag.ImmutableBagMultimap<V,T> groupBy(com.gs.collections.api.block.function.Function<? super T,? extends V> function)
com.gs.collections.api.RichIterablee.g.
return people.groupBy(new Function<Person, String>()
{
public String value(Person person)
{
return person.getFirstName() + " " + person.getLastName();
}
});
groupBy in interface com.gs.collections.api.bag.Bag<T>groupBy in interface com.gs.collections.api.bag.ImmutableBag<T>groupBy in interface com.gs.collections.api.bag.UnsortedBag<T>groupBy in interface com.gs.collections.api.collection.ImmutableCollection<T>groupBy in interface com.gs.collections.api.RichIterable<T>public <V,R extends com.gs.collections.api.multimap.MutableMultimap<V,T>> R groupBy(com.gs.collections.api.block.function.Function<? super T,? extends V> function, R target)
com.gs.collections.api.RichIterableRichIterable.groupBy(Function), except that the results are gathered into the specified target
multimap.
e.g.
return people.groupBy(new Function<Person, String>()
{
public String value(Person person)
{
return person.getFirstName() + " " + person.getLastName();
}
}, new FastListMultimap<String, Person>());
groupBy in interface com.gs.collections.api.RichIterable<T>groupBy in class AbstractRichIterable<T>public <V> com.gs.collections.api.multimap.bag.ImmutableBagMultimap<V,T> groupByEach(com.gs.collections.api.block.function.Function<? super T,? extends java.lang.Iterable<V>> function)
com.gs.collections.api.RichIterableRichIterable.groupBy(Function), except the result of evaluating function will return a collection of keys
for each value.groupByEach in interface com.gs.collections.api.bag.Bag<T>groupByEach in interface com.gs.collections.api.bag.ImmutableBag<T>groupByEach in interface com.gs.collections.api.bag.UnsortedBag<T>groupByEach in interface com.gs.collections.api.collection.ImmutableCollection<T>groupByEach in interface com.gs.collections.api.RichIterable<T>public <V,R extends com.gs.collections.api.multimap.MutableMultimap<V,T>> R groupByEach(com.gs.collections.api.block.function.Function<? super T,? extends java.lang.Iterable<V>> function, R target)
com.gs.collections.api.RichIterableRichIterable.groupByEach(Function), except that the results are gathered into the specified target
multimap.groupByEach in interface com.gs.collections.api.RichIterable<T>groupByEach in class AbstractRichIterable<T>public <V> com.gs.collections.api.map.ImmutableMap<V,T> groupByUniqueKey(com.gs.collections.api.block.function.Function<? super T,? extends V> function)
com.gs.collections.api.RichIterablepublic boolean isEmpty()
com.gs.collections.api.RichIterableisEmpty in interface com.gs.collections.api.RichIterable<T>isEmpty in interface java.util.Collection<T>isEmpty in class AbstractRichIterable<T>public boolean notEmpty()
com.gs.collections.api.RichIterablenotEmpty in interface com.gs.collections.api.RichIterable<T>notEmpty in class AbstractRichIterable<T>public T getFirst()
com.gs.collections.api.RichIterablegetFirst in interface com.gs.collections.api.RichIterable<T>public T getLast()
com.gs.collections.api.RichIterablegetLast in interface com.gs.collections.api.RichIterable<T>public T min(java.util.Comparator<? super T> comparator)
com.gs.collections.api.RichIterablemin in interface com.gs.collections.api.RichIterable<T>min in class AbstractRichIterable<T>public T max(java.util.Comparator<? super T> comparator)
com.gs.collections.api.RichIterablemax in interface com.gs.collections.api.RichIterable<T>max in class AbstractRichIterable<T>public T min()
com.gs.collections.api.RichIterablemin in interface com.gs.collections.api.RichIterable<T>min in class AbstractRichIterable<T>public T max()
com.gs.collections.api.RichIterablemax in interface com.gs.collections.api.RichIterable<T>max in class AbstractRichIterable<T>public <V extends java.lang.Comparable<? super V>> T minBy(com.gs.collections.api.block.function.Function<? super T,? extends V> function)
com.gs.collections.api.RichIterableminBy in interface com.gs.collections.api.RichIterable<T>minBy in class AbstractRichIterable<T>public <V extends java.lang.Comparable<? super V>> T maxBy(com.gs.collections.api.block.function.Function<? super T,? extends V> function)
com.gs.collections.api.RichIterablemaxBy in interface com.gs.collections.api.RichIterable<T>maxBy in class AbstractRichIterable<T>public boolean contains(java.lang.Object object)
com.gs.collections.api.RichIterablecontains in interface com.gs.collections.api.RichIterable<T>contains in interface java.util.Collection<T>contains in class AbstractRichIterable<T>public boolean containsAllIterable(java.lang.Iterable<?> source)
com.gs.collections.api.RichIterablecontainsAllIterable in interface com.gs.collections.api.RichIterable<T>containsAllIterable in class AbstractRichIterable<T>public boolean containsAllArguments(java.lang.Object... elements)
com.gs.collections.api.RichIterablecontainsAllArguments in interface com.gs.collections.api.RichIterable<T>containsAllArguments in class AbstractRichIterable<T>public <K,V> com.gs.collections.api.map.MutableMap<K,V> toMap(com.gs.collections.api.block.function.Function<? super T,? extends K> keyFunction, com.gs.collections.api.block.function.Function<? super T,? extends V> valueFunction)
com.gs.collections.api.RichIterabletoMap in interface com.gs.collections.api.RichIterable<T>toMap in class AbstractRichIterable<T>public void forEach(com.gs.collections.api.block.procedure.Procedure<? super T> procedure)
com.gs.collections.api.InternalIterablee.g. people.forEach(new Procedure() { public void value(Person person) { LOGGER.info(person.getName()); } });
forEach in interface com.gs.collections.api.InternalIterable<T>public void forEachWithIndex(com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure<? super T> objectIntProcedure)
com.gs.collections.api.InternalIterablee.g. people.forEachWithIndex(new ObjectIntProcedure() { public void value(Person person, int index) { LOGGER.info("Index: " + index + " person: " + person.getName()); } });
forEachWithIndex in interface com.gs.collections.api.InternalIterable<T>forEachWithIndex in class AbstractRichIterable<T>public <P> void forEachWith(com.gs.collections.api.block.procedure.Procedure2<? super T,? super P> procedure, P parameter)
com.gs.collections.api.InternalIterablee.g. people.forEachWith(new Procedure2() { public void value(Person person, Person other) { if (person.isRelatedTo(other)) { LOGGER.info(person.getName()); } } }, fred);
forEachWith in interface com.gs.collections.api.InternalIterable<T>forEachWith in class AbstractRichIterable<T>public com.gs.collections.api.bag.ImmutableBag<T> selectByOccurrences(com.gs.collections.api.block.predicate.primitive.IntPredicate predicate)
com.gs.collections.api.bag.Bagpublic com.gs.collections.api.bag.ImmutableBag<T> select(com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
com.gs.collections.api.RichIterablee.g.
return people.select(new Predicate<Person>()
{
public boolean accept(Person person)
{
return person.getAddress().getCity().equals("Metuchen");
}
});
select in interface com.gs.collections.api.bag.Bag<T>select in interface com.gs.collections.api.bag.ImmutableBag<T>select in interface com.gs.collections.api.bag.UnsortedBag<T>select in interface com.gs.collections.api.collection.ImmutableCollection<T>select in interface com.gs.collections.api.RichIterable<T>public com.gs.collections.api.bag.ImmutableBag<T> reject(com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
com.gs.collections.api.RichIterablee.g.
return people.reject(new Predicate<Person>()
{
public boolean accept(Person person)
{
return person.person.getLastName().equals("Smith");
}
});
e.g.
return people.reject(Predicates.attributeEqual("lastName", "Smith"));
reject in interface com.gs.collections.api.bag.Bag<T>reject in interface com.gs.collections.api.bag.ImmutableBag<T>reject in interface com.gs.collections.api.bag.UnsortedBag<T>reject in interface com.gs.collections.api.collection.ImmutableCollection<T>reject in interface com.gs.collections.api.RichIterable<T>predicate - a Predicate to use as the reject criteriaPredicate.accept(Object) method to evaluate to falsepublic com.gs.collections.api.partition.bag.PartitionImmutableBag<T> partition(com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
com.gs.collections.api.RichIterablee.g.
return people.partition(new Predicate<Person>()
{
public boolean accept(Person person)
{
return person.getAddress().getState().getName().equals("New York");
}
});
partition in interface com.gs.collections.api.bag.Bag<T>partition in interface com.gs.collections.api.bag.ImmutableBag<T>partition in interface com.gs.collections.api.bag.UnsortedBag<T>partition in interface com.gs.collections.api.collection.ImmutableCollection<T>partition in interface com.gs.collections.api.RichIterable<T>partition in class AbstractImmutableBag<T>public <P> com.gs.collections.api.partition.bag.PartitionImmutableBag<T> partitionWith(com.gs.collections.api.block.predicate.Predicate2<? super T,? super P> predicate, P parameter)
com.gs.collections.api.RichIterablee.g.
return people.partitionWith(new Predicate2<Person, String>()
{
public boolean accept(Person person, String state)
{
return person.getAddress().getState().getName().equals(state);
}
}, "New York");
partitionWith in interface com.gs.collections.api.bag.Bag<T>partitionWith in interface com.gs.collections.api.bag.ImmutableBag<T>partitionWith in interface com.gs.collections.api.collection.ImmutableCollection<T>partitionWith in interface com.gs.collections.api.RichIterable<T>partitionWith in class AbstractImmutableBag<T>public <S> com.gs.collections.api.bag.ImmutableBag<S> selectInstancesOf(java.lang.Class<S> clazz)
com.gs.collections.api.RichIterableclazz.selectInstancesOf in interface com.gs.collections.api.bag.Bag<T>selectInstancesOf in interface com.gs.collections.api.bag.ImmutableBag<T>selectInstancesOf in interface com.gs.collections.api.bag.UnsortedBag<T>selectInstancesOf in interface com.gs.collections.api.collection.ImmutableCollection<T>selectInstancesOf in interface com.gs.collections.api.RichIterable<T>public <V> com.gs.collections.api.bag.ImmutableBag<V> collect(com.gs.collections.api.block.function.Function<? super T,? extends V> function)
com.gs.collections.api.RichIterablee.g.
return people.collect(new Function<Person, String>()
{
public String valueOf(Person person)
{
return person.getFirstName() + " " + person.getLastName();
}
});
collect in interface com.gs.collections.api.bag.ImmutableBag<T>collect in interface com.gs.collections.api.bag.UnsortedBag<T>collect in interface com.gs.collections.api.collection.ImmutableCollection<T>collect in interface com.gs.collections.api.RichIterable<T>public <V> com.gs.collections.api.bag.ImmutableBag<V> collectIf(com.gs.collections.api.block.predicate.Predicate<? super T> predicate, com.gs.collections.api.block.function.Function<? super T,? extends V> function)
com.gs.collections.api.RichIterablee.g. Lists.mutable.of().with(1, 2, 3).collectIf(Predicates.notNull(), Functions.getToString())
collectIf in interface com.gs.collections.api.bag.ImmutableBag<T>collectIf in interface com.gs.collections.api.bag.UnsortedBag<T>collectIf in interface com.gs.collections.api.collection.ImmutableCollection<T>collectIf in interface com.gs.collections.api.RichIterable<T>public <V> com.gs.collections.api.bag.ImmutableBag<V> flatCollect(com.gs.collections.api.block.function.Function<? super T,? extends java.lang.Iterable<V>> function)
com.gs.collections.api.RichIterableflatCollect is a special case of RichIterable.collect(Function). With collect, when the Function returns
a collection, the result is a collection of collections. flatCollect outputs a single "flattened" collection
instead. This method is commonly called flatMap.
Consider the following example where we have a Person class, and each Person has a list of Address objects. Take the following Function:
Function<Person, List<Address>> addressFunction = new Function<Person, List<Address>>()
{
public List<Address> valueOf(Person person)
{
return person.getAddresses();
}
};
MutableList<Person> people = ...;
Using collect returns a collection of collections of addresses.
MutableList<List<Address>> addresses = people.collect(addressFunction);Using
flatCollect returns a single flattened list of addresses.
MutableList<Address> addresses = people.flatCollect(addressFunction);
flatCollect in interface com.gs.collections.api.bag.ImmutableBag<T>flatCollect in interface com.gs.collections.api.bag.UnsortedBag<T>flatCollect in interface com.gs.collections.api.collection.ImmutableCollection<T>flatCollect in interface com.gs.collections.api.RichIterable<T>function - The Function to applyfunctionpublic com.gs.collections.api.list.MutableList<T> toList()
com.gs.collections.api.RichIterabletoList in interface com.gs.collections.api.RichIterable<T>toList in class AbstractRichIterable<T>public int sizeDistinct()
com.gs.collections.api.bag.BagsizeDistinct in interface com.gs.collections.api.bag.Bag<T>public int occurrencesOf(java.lang.Object item)
com.gs.collections.api.bag.BagoccurrencesOf in interface com.gs.collections.api.bag.Bag<T>public void forEachWithOccurrences(com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure<? super T> objectIntProcedure)
com.gs.collections.api.bag.BagforEachWithOccurrences in interface com.gs.collections.api.bag.Bag<T>public com.gs.collections.api.list.MutableList<T> toSortedList()
com.gs.collections.api.RichIterabletoSortedList in interface com.gs.collections.api.RichIterable<T>toSortedList in class AbstractRichIterable<T>public com.gs.collections.api.list.MutableList<T> toSortedList(java.util.Comparator<? super T> comparator)
com.gs.collections.api.RichIterabletoSortedList in interface com.gs.collections.api.RichIterable<T>toSortedList in class AbstractRichIterable<T>public <R extends java.util.Collection<T>> R select(com.gs.collections.api.block.predicate.Predicate<? super T> predicate, R target)
com.gs.collections.api.RichIterablee.g.
return people.select(new Predicate<Person>()
{
public boolean accept(Person person)
{
return person.person.getLastName().equals("Smith");
}
}, Lists.mutable.of());
e.g.
return collection.select(Predicates.attributeEqual("lastName", "Smith"), new ArrayList());
select in interface com.gs.collections.api.RichIterable<T>select in class AbstractRichIterable<T>predicate - a Predicate to use as the select criteriatarget - the Collection to append to for all elements in this RichIterable that meet select criteria predicatetarget, which contains appended elements as a result of the select criteriaRichIterable.select(Predicate)public <P,R extends java.util.Collection<T>> R selectWith(com.gs.collections.api.block.predicate.Predicate2<? super T,? super P> predicate, P parameter, R targetCollection)
com.gs.collections.api.RichIterableRichIterable.select(Predicate, Collection), except with an evaluation parameter for the second generic argument in Predicate2.selectWith in interface com.gs.collections.api.RichIterable<T>selectWith in class AbstractRichIterable<T>predicate - a Predicate2 to use as the select criteriaparameter - a parameter to pass in for evaluation of the second argument P in predicatetargetCollection - the Collection to append to for all elements in this RichIterable that meet select criteria predicatetargetCollection, which contains appended elements as a result of the select criteriaRichIterable.select(Predicate),
RichIterable.select(Predicate, Collection)public <R extends java.util.Collection<T>> R reject(com.gs.collections.api.block.predicate.Predicate<? super T> predicate, R target)
com.gs.collections.api.RichIterablee.g.
return people.reject(new Predicate<Person>()
{
public boolean accept(Person person)
{
return person.person.getLastName().equals("Smith");
}
}, Lists.mutable.of());
reject in interface com.gs.collections.api.RichIterable<T>reject in class AbstractRichIterable<T>predicate - a Predicate to use as the reject criteriatarget - the Collection to append to for all elements in this RichIterable that cause Predicate#accept(Object) method to evaluate to falsetarget, which contains appended elements as a result of the reject criteriapublic <P,R extends java.util.Collection<T>> R rejectWith(com.gs.collections.api.block.predicate.Predicate2<? super T,? super P> predicate, P parameter, R targetCollection)
com.gs.collections.api.RichIterableRichIterable.reject(Predicate, Collection), except with an evaluation parameter for the second generic argument in Predicate2.
E.g. return a Collection of Person elements where the person has a height greater than 100cm
return people.reject(new Predicate2<Person, Integer>()
{
public boolean accept(Person p, Integer i)
{
return p.getHeightInCm() < i.intValue();
}
}, Integer.valueOf(100), FastList.newList());
rejectWith in interface com.gs.collections.api.RichIterable<T>rejectWith in class AbstractRichIterable<T>predicate - a Predicate2 to use as the reject criteriaparameter - a parameter to pass in for evaluation of the second argument P in predicatetargetCollection - the Collection to append to for all elements in this RichIterable that cause Predicate#accept(Object) method to evaluate to falsetargetCollection, which contains appended elements as a result of the reject criteriaRichIterable.reject(Predicate),
RichIterable.reject(Predicate, Collection)public <V,R extends java.util.Collection<V>> R collect(com.gs.collections.api.block.function.Function<? super T,? extends V> function, R target)
com.gs.collections.api.RichIterableRichIterable.collect(Function), except that the results are gathered into the specified target
collection.
e.g.
return people.collect(new Function<Person, String>()
{
public String valueOf(Person person)
{
return person.getFirstName() + " " + person.getLastName();
}
}, Lists.mutable.of());
collect in interface com.gs.collections.api.RichIterable<T>collect in class AbstractRichIterable<T>function - a Function to use as the collect transformation functiontarget - the Collection to append to for all elements in this RichIterable that meet select criteria functiontarget, which contains appended elements as a result of the collect transformationRichIterable.collect(Function)public <P,V,R extends java.util.Collection<V>> R collectWith(com.gs.collections.api.block.function.Function2<? super T,? super P,? extends V> function, P parameter, R targetCollection)
com.gs.collections.api.RichIterablee.g. Function2addParameterFunction = new Function2 () { public Integer value(final Integer each, final Integer parameter) { return each + parameter; } }; FastList.newListWith(1, 2, 3).collectWith(addParameterFunction, Integer.valueOf(1), UnifiedSet.newSet());
collectWith in interface com.gs.collections.api.RichIterable<T>collectWith in class AbstractRichIterable<T>function - a Function2 to use as the collect transformation functionparameter - a parameter to pass in for evaluation of the second argument P in functiontargetCollection - the Collection to append to for all elements in this RichIterable that meet select criteria functiontargetCollection, which contains appended elements as a result of the collect transformationpublic <V,R extends java.util.Collection<V>> R flatCollect(com.gs.collections.api.block.function.Function<? super T,? extends java.lang.Iterable<V>> function, R target)
com.gs.collections.api.RichIterableflatCollect in interface com.gs.collections.api.RichIterable<T>flatCollect in class AbstractRichIterable<T>function - The Function to applytarget - The collection into which results should be added.target, which will contain a flattened collection of results produced by applying the given functionRichIterable.flatCollect(Function)public <V,R extends java.util.Collection<V>> R collectIf(com.gs.collections.api.block.predicate.Predicate<? super T> predicate, com.gs.collections.api.block.function.Function<? super T,? extends V> function, R target)
com.gs.collections.api.RichIterablecollectIf in interface com.gs.collections.api.RichIterable<T>collectIf in class AbstractRichIterable<T>predicate - a Predicate to use as the select criteriafunction - a Function to use as the collect transformation functiontarget - the Collection to append to for all elements in this RichIterable that meet the collect criteria predicatetargetCollection, which contains appended elements as a result of the collect criteria and transformationRichIterable.collectIf(Predicate, Function)public T detect(com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
com.gs.collections.api.RichIterablee.g.
return people.detect(new Predicate<Person>()
{
public boolean value(Person person)
{
return person.getFirstName().equals("John") && person.getLastName().equals("Smith");
}
});
detect in interface com.gs.collections.api.RichIterable<T>detect in class AbstractRichIterable<T>public T detectIfNone(com.gs.collections.api.block.predicate.Predicate<? super T> predicate, com.gs.collections.api.block.function.Function0<? extends T> function)
com.gs.collections.api.RichIterabledetectIfNone in interface com.gs.collections.api.RichIterable<T>detectIfNone in class AbstractRichIterable<T>public int count(com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
com.gs.collections.api.RichIterablee.g.
return people.count(new Predicate<Person>()
{
public boolean value(Person person)
{
return person.getAddress().getState().getName().equals("New York");
}
});
count in interface com.gs.collections.api.RichIterable<T>count in class AbstractRichIterable<T>public boolean anySatisfy(com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
com.gs.collections.api.RichIterableanySatisfy in interface com.gs.collections.api.RichIterable<T>anySatisfy in class AbstractRichIterable<T>public boolean allSatisfy(com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
com.gs.collections.api.RichIterableallSatisfy in interface com.gs.collections.api.RichIterable<T>allSatisfy in class AbstractRichIterable<T>public boolean noneSatisfy(com.gs.collections.api.block.predicate.Predicate<? super T> predicate)
com.gs.collections.api.RichIterablenoneSatisfy in interface com.gs.collections.api.RichIterable<T>noneSatisfy in class AbstractRichIterable<T>public <IV> IV injectInto(IV injectedValue,
com.gs.collections.api.block.function.Function2<? super IV,? super T,? extends IV> function)
com.gs.collections.api.RichIterableinjectInto in interface com.gs.collections.api.RichIterable<T>injectInto in class AbstractRichIterable<T>public boolean equals(java.lang.Object obj)
com.gs.collections.api.bag.Bagpublic int hashCode()
com.gs.collections.api.bag.BagBag.toMapOfItemToCount().hashCode().public com.gs.collections.api.map.MapIterable<T,java.lang.Integer> toMapOfItemToCount()
com.gs.collections.api.bag.BagtoMapOfItemToCount in interface com.gs.collections.api.bag.Bag<T>public com.gs.collections.api.set.MutableSet<T> toSet()
com.gs.collections.api.RichIterabletoSet in interface com.gs.collections.api.RichIterable<T>toSet in class AbstractRichIterable<T>public com.gs.collections.api.bag.MutableBag<T> toBag()
com.gs.collections.api.RichIterabletoBag in interface com.gs.collections.api.RichIterable<T>toBag in class AbstractRichIterable<T>public com.gs.collections.api.bag.ImmutableBag<T> toImmutable()
com.gs.collections.api.bag.UnsortedBagtoImmutable in interface com.gs.collections.api.bag.UnsortedBag<T>public com.gs.collections.api.LazyIterable<T> asLazy()
com.gs.collections.api.RichIterableasLazy in interface com.gs.collections.api.RichIterable<T>asLazy in class AbstractRichIterable<T>public java.lang.Object[] toArray()
com.gs.collections.api.RichIterabletoArray in interface com.gs.collections.api.RichIterable<T>toArray in interface java.util.Collection<T>toArray in class AbstractRichIterable<T>Collection.toArray()public <T> T[] toArray(T[] a)
com.gs.collections.api.RichIterabletoArray in interface com.gs.collections.api.RichIterable<T>toArray in interface java.util.Collection<T>toArray in class AbstractRichIterable<T>Collection.toArray(Object[])public java.lang.String toString()
AbstractRichIterableThis implementation creates an empty string buffer, appends a left square bracket, and iterates over the collection appending the string representation of each element in turn. After appending each element except the last, the string ", " is appended. Finally a right bracket is appended. A string is obtained from the string buffer, and returned.
toString in interface com.gs.collections.api.RichIterable<T>toString in class AbstractRichIterable<T>public java.lang.String makeString()
com.gs.collections.api.RichIterableRichIterable.makeString(String) and defaulting
the separator parameter to the characters ", " (comma and space).makeString in interface com.gs.collections.api.RichIterable<T>makeString in class AbstractRichIterable<T>public java.lang.String makeString(java.lang.String separator)
com.gs.collections.api.RichIterableRichIterable.makeString(String, String, String)
and defaulting the start and end parameters to "" (the empty String).makeString in interface com.gs.collections.api.RichIterable<T>makeString in class AbstractRichIterable<T>public java.lang.String makeString(java.lang.String start,
java.lang.String separator,
java.lang.String end)
com.gs.collections.api.RichIterablemakeString in interface com.gs.collections.api.RichIterable<T>makeString in class AbstractRichIterable<T>public void appendString(java.lang.Appendable appendable)
com.gs.collections.api.RichIterableAppendable. Prints the string returned
by RichIterable.makeString().appendString in interface com.gs.collections.api.RichIterable<T>appendString in class AbstractRichIterable<T>public void appendString(java.lang.Appendable appendable,
java.lang.String separator)
com.gs.collections.api.RichIterableAppendable. Prints the string returned
by RichIterable.makeString(String).appendString in interface com.gs.collections.api.RichIterable<T>appendString in class AbstractRichIterable<T>public void appendString(java.lang.Appendable appendable,
java.lang.String start,
java.lang.String separator,
java.lang.String end)
com.gs.collections.api.RichIterableAppendable. Prints the string returned
by RichIterable.makeString(String, String, String).appendString in interface com.gs.collections.api.RichIterable<T>appendString in class AbstractRichIterable<T>public <S> com.gs.collections.api.bag.ImmutableBag<com.gs.collections.api.tuple.Pair<T,S>> zip(java.lang.Iterable<S> that)
com.gs.collections.api.RichIterableRichIterable formed from this RichIterable and another RichIterable by
combining corresponding elements in pairs. If one of the two RichIterables is longer than the other, its
remaining elements are ignored.zip in interface com.gs.collections.api.bag.ImmutableBag<T>zip in interface com.gs.collections.api.bag.UnsortedBag<T>zip in interface com.gs.collections.api.collection.ImmutableCollection<T>zip in interface com.gs.collections.api.RichIterable<T>S - the type of the second half of the returned pairsthat - The RichIterable providing the second half of each result pairRichIterable containing pairs consisting of corresponding elements of this RichIterable and that. The length of the returned RichIterable is the minimum of the lengths of
this RichIterable and that.public <S,R extends java.util.Collection<com.gs.collections.api.tuple.Pair<T,S>>> R zip(java.lang.Iterable<S> that, R target)
com.gs.collections.api.RichIterableRichIterable.zip(Iterable) but uses target for output.zip in interface com.gs.collections.api.RichIterable<T>zip in class AbstractRichIterable<T>public com.gs.collections.api.set.ImmutableSet<com.gs.collections.api.tuple.Pair<T,java.lang.Integer>> zipWithIndex()
com.gs.collections.api.RichIterableRichIterable with its indices.zipWithIndex in interface com.gs.collections.api.bag.Bag<T>zipWithIndex in interface com.gs.collections.api.bag.ImmutableBag<T>zipWithIndex in interface com.gs.collections.api.bag.UnsortedBag<T>zipWithIndex in interface com.gs.collections.api.collection.ImmutableCollection<T>zipWithIndex in interface com.gs.collections.api.RichIterable<T>RichIterable containing pairs consisting of all elements of this RichIterable
paired with their index. Indices start at 0.RichIterable.zip(Iterable)public <R extends java.util.Collection<com.gs.collections.api.tuple.Pair<T,java.lang.Integer>>> R zipWithIndex(R target)
com.gs.collections.api.RichIterableRichIterable.zipWithIndex() but uses target for output.zipWithIndex in interface com.gs.collections.api.RichIterable<T>zipWithIndex in class AbstractRichIterable<T>public java.util.Iterator<T> iterator()
protected java.lang.Object writeReplace()