public class ImmutableArrayBag<T> extends AbstractImmutableBag<T> implements java.io.Serializable
AbstractImmutableBag.ImmutableBagSerializationProxy<T>| Modifier and Type | Method and Description |
|---|---|
<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> 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.
|
<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.
|
static <T> ImmutableArrayBag<T> |
copyFrom(com.gs.collections.api.bag.Bag<T> bag) |
boolean |
equals(java.lang.Object other)
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). |
void |
forEach(com.gs.collections.api.block.procedure.Procedure<? super T> procedure)
The procedure is executed for each element in the iterable.
|
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. |
int |
hashCode()
Returns the hash code for this Bag, defined as this.
Bag.toMapOfItemToCount().hashCode(). |
java.util.Iterator<T> |
iterator() |
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> ImmutableArrayBag<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) |
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.
|
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.
|
<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.
|
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.
|
com.gs.collections.api.bag.ImmutableBag<T> |
toImmutable()
Convert the Bag to an ImmutableBag.
|
com.gs.collections.api.map.MutableMap<T,java.lang.Integer> |
toMapOfItemToCount()
Converts the Bag to a Map of the Item type to its count as an Integer.
|
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. |
com.gs.collections.api.bag.ImmutableBag<com.gs.collections.api.tuple.Pair<T,java.lang.Integer>> |
zipWithIndex()
Zips this
RichIterable with its indices. |
collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectInt, collectLong, collectShort, newMutable, toStringOfItemToCountadd, addAll, aggregateBy, aggregateInPlaceBy, allSatisfy, anySatisfy, appendString, appendString, appendString, asLazy, chunk, clear, collect, collectIf, contains, containsAll, containsAllArguments, containsAllIterable, count, detect, detectIfNone, flatCollect, forEachWith, forEachWithIndex, injectInto, injectInto, injectInto, injectInto, injectInto, isEmpty, makeString, makeString, makeString, noneSatisfy, notEmpty, reject, remove, removeAll, removeAllFrom, retainAll, select, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toList, toMap, toSet, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toSortedSetBy, toString, zip, zipWithIndexclone, finalize, getClass, notify, notifyAll, wait, wait, waitaggregateBy, aggregateInPlaceByallSatisfy, anySatisfy, appendString, appendString, appendString, asLazy, chunk, collect, collectIf, contains, containsAll, containsAllArguments, containsAllIterable, count, detect, detectIfNone, flatCollect, injectInto, injectInto, injectInto, injectInto, injectInto, isEmpty, makeString, makeString, makeString, noneSatisfy, notEmpty, reject, select, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toList, toMap, toSet, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toSortedSetBy, toString, zip, zipWithIndexpublic static <T> ImmutableArrayBag<T> newBagWith(T... elements)
public static <T> ImmutableArrayBag<T> copyFrom(com.gs.collections.api.bag.Bag<T> bag)
public int size()
com.gs.collections.api.RichIterablepublic 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.map.MutableMap<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.bag.ImmutableBag<T> toImmutable()
com.gs.collections.api.bag.BagtoImmutable in interface com.gs.collections.api.bag.Bag<T>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 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.collection.ImmutableCollection<T>select in interface com.gs.collections.api.RichIterable<T>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 AbstractImmutableCollection<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 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.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 <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 AbstractImmutableCollection<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 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.collection.ImmutableCollection<T>partition in interface com.gs.collections.api.RichIterable<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.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.Bag<T>collect in interface com.gs.collections.api.bag.ImmutableBag<T>collect in interface com.gs.collections.api.collection.ImmutableCollection<T>collect in interface com.gs.collections.api.RichIterable<T>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 AbstractImmutableCollection<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> 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.Bag<T>collectIf in interface com.gs.collections.api.bag.ImmutableBag<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.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.collection.ImmutableCollection<T>groupBy in interface com.gs.collections.api.RichIterable<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.collection.ImmutableCollection<T>groupByEach in interface com.gs.collections.api.RichIterable<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 <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.Bag<T>flatCollect in interface com.gs.collections.api.bag.ImmutableBag<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 <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>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>public boolean equals(java.lang.Object other)
com.gs.collections.api.bag.Bagpublic int hashCode()
com.gs.collections.api.bag.BagBag.toMapOfItemToCount().hashCode().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 java.util.Iterator<T> iterator()
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 AbstractImmutableCollection<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 AbstractImmutableCollection<T>public T min()
com.gs.collections.api.RichIterablemin in interface com.gs.collections.api.RichIterable<T>min in class AbstractImmutableCollection<T>public T max()
com.gs.collections.api.RichIterablemax in interface com.gs.collections.api.RichIterable<T>max in class AbstractImmutableCollection<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 AbstractImmutableCollection<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 AbstractImmutableCollection<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.Bag<T>zip in interface com.gs.collections.api.bag.ImmutableBag<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 com.gs.collections.api.bag.ImmutableBag<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.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)protected java.lang.Object writeReplace()