public class ImmutableArrayBag<T> extends AbstractImmutableBag<T> implements Serializable
| Modifier and Type | Method and Description |
|---|---|
<V> ImmutableBag<V> |
collect(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> ImmutableBag<V> |
collectIf(Predicate<? super T> predicate,
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.
|
static <T> ImmutableArrayBag<T> |
copyFrom(Bag<T> bag) |
boolean |
equals(Object other)
Two bagsb1 and b2 are equal if m1.toMapOfItemToCount().equals(m2.toMapOfItemToCount()).
|
<V> ImmutableBag<V> |
flatCollect(Function<? super T,? extends Iterable<V>> function)
flatCollect is a special case of RichIterable.collect(Function). |
void |
forEach(Procedure<? super T> procedure)
The procedure is executed for each element in the iterable.
|
void |
forEachWithOccurrences(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> ImmutableBagMultimap<V,T> |
groupBy(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 MutableMultimap<V,T>> |
groupBy(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> ImmutableBagMultimap<V,T> |
groupByEach(Function<? super T,? extends 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 MutableMultimap<V,T>> |
groupByEach(Function<? super T,? extends Iterable<V>> function,
R target)
Same as
RichIterable.groupByEach(Function), except that the results are gathered into the specified target
multimap. |
<V> ImmutableMap<V,T> |
groupByUniqueKey(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(). |
Iterator<T> |
iterator() |
T |
max()
Returns the maximum element out of this container based on the natural order.
|
T |
max(Comparator<? super T> comparator)
Returns the maximum element out of this container based on the comparator.
|
<V extends Comparable<? super V>> |
maxBy(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(Comparator<? super T> comparator)
Returns the minimum element out of this container based on the comparator.
|
<V extends Comparable<? super V>> |
minBy(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) |
ImmutableBag<T> |
newWith(T element) |
ImmutableBag<T> |
newWithAll(Iterable<? extends T> elements) |
ImmutableBag<T> |
newWithout(T element) |
ImmutableBag<T> |
newWithoutAll(Iterable<? extends T> elements) |
int |
occurrencesOf(Object item)
The occurrences of a distinct item in the bag.
|
ImmutableBag<T> |
reject(Predicate<? super T> predicate)
Returns all elements of the source collection that return false when evaluating of the predicate.
|
<P,R extends Collection<T>> |
rejectWith(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. |
ImmutableBag<T> |
select(Predicate<? super T> predicate)
Returns all elements of the source collection that return true when evaluating the predicate.
|
ImmutableBag<T> |
selectByOccurrences(IntPredicate predicate)
Returns all elements of the bag that have a number of occurrences that satisfy the predicate.
|
<S> ImmutableBag<S> |
selectInstancesOf(Class<S> clazz)
Returns all elements of the source collection that are instances of the Class
clazz. |
<P,R extends Collection<T>> |
selectWith(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.
|
ImmutableBag<T> |
toImmutable()
Converts the UnsortedBag to an ImmutableBag.
|
MutableMap<T,Integer> |
toMapOfItemToCount()
Converts the Bag to a Map of the Item type to its count as an Integer.
|
<S> ImmutableBag<Pair<T,S>> |
zip(Iterable<S> that)
Returns a
RichIterable formed from this RichIterable and another RichIterable by
combining corresponding elements in pairs. |
ImmutableSet<Pair<T,Integer>> |
zipWithIndex()
Zips this
RichIterable with its indices. |
collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectInt, collectLong, collectShort, collectWith, partition, partitionWith, rejectWith, selectWith, toStringOfItemToCountadd, addAll, aggregateBy, aggregateInPlaceBy, chunk, clear, remove, removeAll, retainAllallSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, appendString, asLazy, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, contains, containsAll, containsAllArguments, containsAllIterable, count, countWith, detect, detectIfNone, detectWith, detectWithIfNone, flatCollect, forEachWith, forEachWithIndex, injectInto, injectInto, injectInto, injectInto, injectInto, isEmpty, makeString, makeString, makeString, noneSatisfy, noneSatisfyWith, notEmpty, reject, select, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toList, toMap, toSet, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toSortedSetBy, toString, zip, zipWithIndexaggregateBy, aggregateInPlaceBy, allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, appendString, asLazy, chunk, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, contains, containsAll, containsAllArguments, containsAllIterable, count, countWith, detect, detectIfNone, detectWith, detectWithIfNone, flatCollect, injectInto, injectInto, injectInto, injectInto, injectInto, isEmpty, makeString, makeString, makeString, noneSatisfy, noneSatisfyWith, notEmpty, reject, select, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toList, toMap, toSet, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toSortedSetBy, toString, zip, zipWithIndexforEachWith, forEachWithIndexforEach, spliteratoraggregateBy, aggregateInPlaceBycontains, containsAll, isEmpty, parallelStream, removeIf, spliterator, stream, toArray, toArraypublic static <T> ImmutableArrayBag<T> newBagWith(T... elements)
public static <T> ImmutableArrayBag<T> copyFrom(Bag<T> bag)
public int size()
RichIterablesize in interface RichIterable<T>size in interface Collection<T>public int sizeDistinct()
BagsizeDistinct in interface Bag<T>public int occurrencesOf(Object item)
BagoccurrencesOf in interface Bag<T>public void forEachWithOccurrences(ObjectIntProcedure<? super T> objectIntProcedure)
BagforEachWithOccurrences in interface Bag<T>public ImmutableBag<T> newWith(T element)
newWith in interface ImmutableBag<T>newWith in interface ImmutableCollection<T>public ImmutableBag<T> newWithout(T element)
newWithout in interface ImmutableBag<T>newWithout in interface ImmutableCollection<T>public MutableMap<T,Integer> toMapOfItemToCount()
BagtoMapOfItemToCount in interface Bag<T>public ImmutableBag<T> toImmutable()
UnsortedBagtoImmutable in interface UnsortedBag<T>public ImmutableBag<T> newWithAll(Iterable<? extends T> elements)
newWithAll in interface ImmutableBag<T>newWithAll in interface ImmutableCollection<T>public ImmutableBag<T> newWithoutAll(Iterable<? extends T> elements)
newWithoutAll in interface ImmutableBag<T>newWithoutAll in interface ImmutableCollection<T>public ImmutableBag<T> selectByOccurrences(IntPredicate predicate)
BagselectByOccurrences in interface Bag<T>selectByOccurrences in interface ImmutableBag<T>selectByOccurrences in interface UnsortedBag<T>public ImmutableBag<T> select(Predicate<? super T> predicate)
RichIterablee.g.
return people.select(new Predicate<Person>()
{
public boolean accept(Person person)
{
return person.getAddress().getCity().equals("Metuchen");
}
});
select in interface Bag<T>select in interface ImmutableBag<T>select in interface UnsortedBag<T>select in interface ImmutableCollection<T>select in interface RichIterable<T>public <P,R extends Collection<T>> R selectWith(Predicate2<? super T,? super P> predicate, P parameter, R targetCollection)
RichIterableRichIterable.select(Predicate, Collection), except with an evaluation parameter for the second generic argument in Predicate2.selectWith in interface 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 ImmutableBag<T> reject(Predicate<? super T> predicate)
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 Bag<T>reject in interface ImmutableBag<T>reject in interface UnsortedBag<T>reject in interface ImmutableCollection<T>reject in interface RichIterable<T>predicate - a Predicate to use as the reject criteriaPredicate.accept(Object) method to evaluate to falsepublic <P,R extends Collection<T>> R rejectWith(Predicate2<? super T,? super P> predicate, P parameter, R targetCollection)
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 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 <S> ImmutableBag<S> selectInstancesOf(Class<S> clazz)
RichIterableclazz.selectInstancesOf in interface Bag<T>selectInstancesOf in interface ImmutableBag<T>selectInstancesOf in interface UnsortedBag<T>selectInstancesOf in interface ImmutableCollection<T>selectInstancesOf in interface RichIterable<T>public <V> ImmutableBag<V> collect(Function<? super T,? extends V> function)
RichIterablee.g.
return people.collect(new Function<Person, String>()
{
public String valueOf(Person person)
{
return person.getFirstName() + " " + person.getLastName();
}
});
collect in interface ImmutableBag<T>collect in interface UnsortedBag<T>collect in interface ImmutableCollection<T>collect in interface RichIterable<T>public <V> ImmutableBag<V> collectIf(Predicate<? super T> predicate, Function<? super T,? extends V> function)
RichIterablee.g. Lists.mutable.of().with(1, 2, 3).collectIf(Predicates.notNull(), Functions.getToString())
collectIf in interface ImmutableBag<T>collectIf in interface UnsortedBag<T>collectIf in interface ImmutableCollection<T>collectIf in interface RichIterable<T>public <V> ImmutableBagMultimap<V,T> groupBy(Function<? super T,? extends V> function)
RichIterablee.g.
return people.groupBy(new Function<Person, String>()
{
public String value(Person person)
{
return person.getFirstName() + " " + person.getLastName();
}
});
groupBy in interface Bag<T>groupBy in interface ImmutableBag<T>groupBy in interface UnsortedBag<T>groupBy in interface ImmutableCollection<T>groupBy in interface RichIterable<T>public <V> ImmutableBagMultimap<V,T> groupByEach(Function<? super T,? extends Iterable<V>> function)
RichIterableRichIterable.groupBy(Function), except the result of evaluating function will return a collection of keys
for each value.groupByEach in interface Bag<T>groupByEach in interface ImmutableBag<T>groupByEach in interface UnsortedBag<T>groupByEach in interface ImmutableCollection<T>groupByEach in interface RichIterable<T>public <V> ImmutableMap<V,T> groupByUniqueKey(Function<? super T,? extends V> function)
RichIterablegroupByUniqueKey in interface ImmutableCollection<T>groupByUniqueKey in interface RichIterable<T>RichIterable.groupBy(Function)public T getFirst()
RichIterablegetFirst in interface RichIterable<T>public T getLast()
RichIterablegetLast in interface RichIterable<T>public <V> ImmutableBag<V> flatCollect(Function<? super T,? extends Iterable<V>> function)
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 ImmutableBag<T>flatCollect in interface UnsortedBag<T>flatCollect in interface ImmutableCollection<T>flatCollect in interface RichIterable<T>function - The Function to applyfunctionpublic <V,R extends MutableMultimap<V,T>> R groupBy(Function<? super T,? extends V> function, R target)
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 RichIterable<T>groupBy in class AbstractRichIterable<T>public <V,R extends MutableMultimap<V,T>> R groupByEach(Function<? super T,? extends Iterable<V>> function, R target)
RichIterableRichIterable.groupByEach(Function), except that the results are gathered into the specified target
multimap.groupByEach in interface RichIterable<T>groupByEach in class AbstractRichIterable<T>public boolean equals(Object other)
Bagequals in interface Bag<T>equals in interface Collection<T>equals in class ObjectMap.equals(Object)public int hashCode()
BagBag.toMapOfItemToCount().hashCode().hashCode in interface Bag<T>hashCode in interface Collection<T>hashCode in class ObjectMap.hashCode()public void forEach(Procedure<? super T> procedure)
InternalIterablee.g. people.forEach(new Procedure() { public void value(Person person) { LOGGER.info(person.getName()); } });
forEach in interface InternalIterable<T>public T min(Comparator<? super T> comparator)
RichIterablemin in interface RichIterable<T>min in class AbstractRichIterable<T>public T max(Comparator<? super T> comparator)
RichIterablemax in interface RichIterable<T>max in class AbstractRichIterable<T>public T min()
RichIterablemin in interface RichIterable<T>min in class AbstractRichIterable<T>public T max()
RichIterablemax in interface RichIterable<T>max in class AbstractRichIterable<T>public <V extends Comparable<? super V>> T minBy(Function<? super T,? extends V> function)
RichIterableminBy in interface RichIterable<T>minBy in class AbstractRichIterable<T>public <V extends Comparable<? super V>> T maxBy(Function<? super T,? extends V> function)
RichIterablemaxBy in interface RichIterable<T>maxBy in class AbstractRichIterable<T>public <S> ImmutableBag<Pair<T,S>> zip(Iterable<S> that)
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 ImmutableBag<T>zip in interface UnsortedBag<T>zip in interface ImmutableCollection<T>zip in interface 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 ImmutableSet<Pair<T,Integer>> zipWithIndex()
RichIterableRichIterable with its indices.zipWithIndex in interface Bag<T>zipWithIndex in interface ImmutableBag<T>zipWithIndex in interface UnsortedBag<T>zipWithIndex in interface ImmutableCollection<T>zipWithIndex in interface RichIterable<T>RichIterable containing pairs consisting of all elements of this RichIterable
paired with their index. Indices start at 0.RichIterable.zip(Iterable)Copyright © 2004–2017. All rights reserved.