java.io.Serializable
, java.lang.Iterable<T>
, Bag<T>
, ImmutableBag<T>
, ImmutableBagIterable<T>
, UnsortedBag<T>
, ImmutableCollection<T>
, InternalIterable<T>
, RichIterable<T>
public class ImmutableHashBag<T> extends AbstractImmutableBag<T> implements java.io.Serializable
Constructor | Description |
---|---|
ImmutableHashBag() |
|
ImmutableHashBag(java.lang.Iterable<? extends T> source) |
|
ImmutableHashBag(Bag<? extends T> source) |
Modifier and Type | Method | Description |
---|---|---|
boolean |
allSatisfy(Predicate<? super T> predicate) |
Returns true if the predicate evaluates to true for every element of the iterable or if the iterable is empty.
|
<P> boolean |
allSatisfyWith(Predicate2<? super T,? super P> predicate,
P parameter) |
Returns true if the predicate evaluates to true for every element of the collection, or returns false.
|
boolean |
anySatisfy(Predicate<? super T> predicate) |
Returns true if the predicate evaluates to true for any element of the iterable.
|
<P> boolean |
anySatisfyWith(Predicate2<? super T,? super P> predicate,
P parameter) |
Returns true if the predicate evaluates to true for any element of the collection, or return false.
|
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 . |
LazyIterable<T> |
asLazy() |
Returns a lazy (deferred) iterable, most likely implemented by calling LazyIterate.adapt(this).
|
<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,R extends java.util.Collection<V>> |
collect(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> 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.
|
<V,R extends java.util.Collection<V>> |
collectIf(Predicate<? super T> predicate,
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.
|
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(Predicate<? super T> predicate) |
Return the total number of elements that answer true to the specified predicate.
|
T |
detect(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(Predicate<? super T> predicate,
Function0<? extends T> function) |
Returns the first element of the iterable for which the predicate evaluates to true.
|
java.util.Optional<T> |
detectOptional(Predicate<? super T> predicate) |
Returns the first element of the iterable for which the predicate evaluates to true as an Optional.
|
<P> T |
detectWith(Predicate2<? super T,? super P> predicate,
P parameter) |
Returns the first element that evaluates to true for the specified predicate2 and parameter, or null if none
evaluate to true.
|
<P> java.util.Optional<T> |
detectWithOptional(Predicate2<? super T,? super P> predicate,
P parameter) |
Returns the first element that evaluates to true for the specified predicate2 and parameter as an Optional.
|
void |
each(Procedure<? super T> procedure) |
The procedure is executed for each element in the iterable.
|
boolean |
equals(java.lang.Object obj) |
Two bagsb1 and b2 are equal if m1.toMapOfItemToCount().equals(m2.toMapOfItemToCount()).
|
<V> ImmutableBag<V> |
flatCollect(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(Function<? super T,? extends java.lang.Iterable<V>> function,
R target) |
Same as flatCollect, only the results are collected into the target collection.
|
void |
forEachWithIndex(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(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.
|
T |
getOnly() |
Returns the element if the iterable has exactly one element.
|
<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 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 MutableMultimap<V,T>> |
groupByEach(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> 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(). |
double |
injectInto(double injectedValue,
DoubleObjectToDoubleFunction<? super T> function) |
Returns the final double result of evaluating function using each element of the iterable and the previous evaluation
result as the parameters.
|
float |
injectInto(float injectedValue,
FloatObjectToFloatFunction<? super T> function) |
Returns the final float result of evaluating function using each element of the iterable and the previous evaluation
result as the parameters.
|
int |
injectInto(int injectedValue,
IntObjectToIntFunction<? super T> function) |
Returns the final int result of evaluating function using each element of the iterable and the previous evaluation
result as the parameters.
|
long |
injectInto(long injectedValue,
LongObjectToLongFunction<? super T> function) |
Returns the final long result of evaluating function using each element of the iterable and the previous evaluation
result as the parameters.
|
<IV> IV |
injectInto(IV injectedValue,
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 with the elements separated by the specified
separator and enclosed between the start and end strings.
|
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(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(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(Bag<? extends T> bag) |
|
static <T> ImmutableHashBag<T> |
newBagWith(T... elements) |
|
ImmutableBag<T> |
newWith(T element) |
This method is similar to the
with method in MutableCollection
with the difference that a new copy of this collection with the element appended will be returned. |
ImmutableBag<T> |
newWithAll(java.lang.Iterable<? extends T> elements) |
This method is similar to the
withAll method in MutableCollection
with the difference that a new copy of this collection with the elements appended will be returned. |
ImmutableBag<T> |
newWithout(T element) |
This method is similar to the
without method in MutableCollection
with the difference that a new copy of this collection with the element removed will be returned. |
boolean |
noneSatisfy(Predicate<? super T> predicate) |
Returns true if the predicate evaluates to false for every element of the iterable or if the iterable is empty.
|
<P> boolean |
noneSatisfyWith(Predicate2<? super T,? super P> predicate,
P parameter) |
Returns true if the predicate evaluates to false for every element of the collection, or return false.
|
boolean |
notEmpty() |
The English equivalent of !this.isEmpty()
|
int |
occurrencesOf(java.lang.Object item) |
The occurrences of a distinct item in the bag.
|
PartitionImmutableBag<T> |
partition(Predicate<? super T> predicate) |
Filters a collection into a PartitionedIterable based on the evaluation of the predicate.
|
ImmutableBag<T> |
reject(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(Predicate<? super T> predicate,
R target) |
Same as the reject method with one parameter but uses the specified target collection for the results.
|
ImmutableBag<T> |
select(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(Predicate<? super T> predicate,
R target) |
Same as the select method with one parameter but uses the specified target collection for the results.
|
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(java.lang.Class<S> clazz) |
Returns all elements of the source collection that are instances of the Class
clazz . |
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.
|
MutableBag<T> |
toBag() |
Converts the collection to the default MutableBag implementation.
|
MutableList<T> |
toList() |
Converts the collection to a MutableList implementation.
|
<K,V> MutableMap<K,V> |
toMap(Function<? super T,? extends K> keyFunction,
Function<? super T,? extends V> valueFunction) |
Converts the collection to a MutableMap implementation using the specified key and value functions.
|
MutableMap<T,java.lang.Integer> |
toMapOfItemToCount() |
Converts the Bag to a Map of the Item type to its count as an Integer.
|
MutableSet<T> |
toSet() |
Converts the collection to a MutableSet implementation.
|
MutableSortedBag<T> |
toSortedBag() |
Converts the collection to a MutableSortedBag implementation and sorts it using the natural order of the
elements.
|
MutableSortedBag<T> |
toSortedBag(java.util.Comparator<? super T> comparator) |
Converts the collection to the MutableSortedBag implementation and sorts it using the specified comparator.
|
<V extends java.lang.Comparable<? super V>> |
toSortedBagBy(Function<? super T,? extends V> function) |
Converts the collection to a MutableSortedBag implementation and sorts it based on the natural order of the
attribute returned by
function . |
MutableList<T> |
toSortedList() |
Converts the collection to a MutableList implementation and sorts it using the natural order of the elements.
|
MutableList<T> |
toSortedList(java.util.Comparator<? super T> comparator) |
Converts the collection to a MutableList implementation and sorts it using the specified comparator.
|
<K,V> MutableSortedMap<K,V> |
toSortedMap(java.util.Comparator<? super K> comparator,
Function<? super T,? extends K> keyFunction,
Function<? super T,? extends V> valueFunction) |
Converts the collection to a MutableSortedMap implementation using the specified key and value functions
sorted by the given comparator.
|
<K,V> MutableSortedMap<K,V> |
toSortedMap(Function<? super T,? extends K> keyFunction,
Function<? super T,? extends V> valueFunction) |
Converts the collection to a MutableSortedMap implementation using the specified key and value functions
sorted by the key elements' natural ordering.
|
MutableSortedSet<T> |
toSortedSet() |
Converts the collection to a MutableSortedSet implementation and sorts it using the natural order of the
elements.
|
MutableSortedSet<T> |
toSortedSet(java.util.Comparator<? super T> comparator) |
Converts the collection to a MutableSortedSet implementation and sorts it using the specified comparator.
|
java.lang.String |
toString() |
Returns a string with the elements of the iterable separated by commas with spaces and
enclosed in square brackets.
|
<S> ImmutableBag<Pair<T,S>> |
zip(java.lang.Iterable<S> that) |
Deprecated.
in 6.0. Use
OrderedIterable.zip(Iterable) instead. |
<S,R extends java.util.Collection<Pair<T,S>>> |
zip(java.lang.Iterable<S> that,
R target) |
Same as
RichIterable.zip(Iterable) but uses target for output. |
ImmutableSet<Pair<T,java.lang.Integer>> |
zipWithIndex() |
Deprecated.
in 6.0. Use
OrderedIterable.zipWithIndex() instead. |
<R extends java.util.Collection<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, injectIntoWith, rejectWith, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toStringOfItemToCount
bottomOccurrences, chunk, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectInt, collectLong, collectShort, collectWith, countBy, countByWith, newWithoutAll, partitionWith, rejectWith, selectWith, tap, toImmutable, topOccurrences
add, addAll, aggregateBy, aggregateInPlaceBy, castToCollection, clear, parallelStream, remove, removeAll, retainAll, spliterator, stream, sumByDouble, sumByFloat, sumByInt, sumByLong
containsAll, countWith, detectWithIfNone, forEach, forEachWith, groupByUniqueKey, into, toSortedListBy, toSortedSetBy
collectWithOccurrences, reduceInPlace, reduceInPlace, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, toStringOfItemToCount
aggregateBy, aggregateInPlaceBy, castToCollection, parallelStream, spliterator, stream, sumByDouble, sumByFloat, sumByInt, sumByLong
forEach, forEach, forEachWith
collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectInt, collectLong, collectShort, collectWith, containsAll, countBy, countByWith, countWith, detectWithIfNone, groupByUniqueKey, into, maxByOptional, maxOptional, maxOptional, minByOptional, minOptional, minOptional, reduce, rejectWith, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toSortedListBy, toSortedSetBy
public ImmutableHashBag()
public ImmutableHashBag(java.lang.Iterable<? 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(Bag<? extends T> bag)
public ImmutableBag<T> newWith(T element)
ImmutableCollection
with
method in MutableCollection
with the difference that a new copy of this collection with the element appended will be returned.newWith
in interface ImmutableBag<T>
newWith
in interface ImmutableCollection<T>
public ImmutableBag<T> newWithout(T element)
ImmutableCollection
without
method in MutableCollection
with the difference that a new copy of this collection with the element removed will be returned.newWithout
in interface ImmutableBag<T>
newWithout
in interface ImmutableCollection<T>
public ImmutableBag<T> newWithAll(java.lang.Iterable<? extends T> elements)
ImmutableCollection
withAll
method in MutableCollection
with the difference that a new copy of this collection with the elements appended will be returned.newWithAll
in interface ImmutableBag<T>
newWithAll
in interface ImmutableCollection<T>
public int size()
RichIterable
size
in interface RichIterable<T>
public <V> ImmutableBagMultimap<V,T> groupBy(Function<? super T,? extends V> function)
RichIterable
Example using a Java 8 method reference:
Multimap<String, Person> peopleByLastName = people.groupBy(Person::getLastName);
Example using an anonymous inner class:
Multimap<String, Person> peopleByLastName = people.groupBy(new Function<Person, String>() { public String valueOf(Person person) { return person.getLastName(); } });
groupBy
in interface Bag<T>
groupBy
in interface ImmutableBag<T>
groupBy
in interface ImmutableBagIterable<T>
groupBy
in interface ImmutableCollection<T>
groupBy
in interface RichIterable<T>
groupBy
in interface UnsortedBag<T>
public <V,R extends MutableMultimap<V,T>> R groupBy(Function<? super T,? extends V> function, R target)
RichIterable
RichIterable.groupBy(Function)
, except that the results are gathered into the specified target
multimap.
Example using a Java 8 method reference:
FastListMultimap<String, Person> peopleByLastName = people.groupBy(Person::getLastName, new FastListMultimap<String, Person>());
Example using an anonymous inner class:
FastListMultimap<String, Person> peopleByLastName = people.groupBy(new Function<Person, String>() { public String valueOf(Person person) { return person.getLastName(); } }, new FastListMultimap<String, Person>());
groupBy
in interface RichIterable<T>
groupBy
in class AbstractBag<T>
public <V> ImmutableBagMultimap<V,T> groupByEach(Function<? super T,? extends java.lang.Iterable<V>> function)
RichIterable
RichIterable.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 ImmutableBagIterable<T>
groupByEach
in interface ImmutableCollection<T>
groupByEach
in interface RichIterable<T>
groupByEach
in interface UnsortedBag<T>
public <V,R extends MutableMultimap<V,T>> R groupByEach(Function<? super T,? extends java.lang.Iterable<V>> function, R target)
RichIterable
RichIterable.groupByEach(Function)
, except that the results are gathered into the specified target
multimap.groupByEach
in interface RichIterable<T>
groupByEach
in class AbstractBag<T>
public <V> ImmutableMap<V,T> groupByUniqueKey(Function<? super T,? extends V> function)
RichIterable
groupByUniqueKey
in interface ImmutableCollection<T>
groupByUniqueKey
in interface RichIterable<T>
groupByUniqueKey
in class AbstractImmutableBag<T>
RichIterable.groupBy(Function)
public boolean isEmpty()
RichIterable
isEmpty
in interface RichIterable<T>
isEmpty
in class AbstractRichIterable<T>
public boolean notEmpty()
RichIterable
notEmpty
in interface RichIterable<T>
public T getFirst()
RichIterable
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.
getFirst
in interface RichIterable<T>
public T getLast()
RichIterable
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.
getLast
in interface RichIterable<T>
public T getOnly()
RichIterable
IllegalStateException
.getOnly
in interface RichIterable<T>
public T min(java.util.Comparator<? super T> comparator)
RichIterable
min
in interface RichIterable<T>
min
in class AbstractRichIterable<T>
public T max(java.util.Comparator<? super T> comparator)
RichIterable
max
in interface RichIterable<T>
max
in class AbstractRichIterable<T>
public T min()
RichIterable
min
in interface RichIterable<T>
min
in class AbstractRichIterable<T>
public T max()
RichIterable
max
in interface RichIterable<T>
max
in class AbstractRichIterable<T>
public <V extends java.lang.Comparable<? super V>> T minBy(Function<? super T,? extends V> function)
RichIterable
minBy
in interface RichIterable<T>
minBy
in class AbstractRichIterable<T>
public <V extends java.lang.Comparable<? super V>> T maxBy(Function<? super T,? extends V> function)
RichIterable
maxBy
in interface RichIterable<T>
maxBy
in class AbstractRichIterable<T>
public boolean contains(java.lang.Object object)
RichIterable
contains
in interface RichIterable<T>
contains
in class AbstractRichIterable<T>
public boolean containsAllIterable(java.lang.Iterable<?> source)
RichIterable
containsAllIterable
in interface RichIterable<T>
containsAllIterable
in class AbstractRichIterable<T>
public boolean containsAllArguments(java.lang.Object... elements)
RichIterable
containsAllArguments
in interface RichIterable<T>
containsAllArguments
in class AbstractRichIterable<T>
public <K,V> MutableMap<K,V> toMap(Function<? super T,? extends K> keyFunction, Function<? super T,? extends V> valueFunction)
RichIterable
toMap
in interface RichIterable<T>
toMap
in class AbstractRichIterable<T>
public void each(Procedure<? super T> procedure)
RichIterable
Example using a Java 8 lambda expression:
people.each(person -> LOGGER.info(person.getName()));
Example using an anonymous inner class:
people.each(new Procedure<Person>() { public void value(Person person) { LOGGER.info(person.getName()); } });This method is a variant of
InternalIterable.forEach(Procedure)
that has a signature conflict with Iterable.forEach(java.util.function.Consumer)
.each
in interface RichIterable<T>
InternalIterable.forEach(Procedure)
,
Iterable.forEach(java.util.function.Consumer)
public void forEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure)
InternalIterable
Example using a Java 8 lambda:
people.forEachWithIndex((Person person, int index) -> LOGGER.info("Index: " + index + " person: " + person.getName()));
Example using an anonymous inner class:
people.forEachWithIndex(new ObjectIntProcedure<Person>() { public void value(Person person, int index) { LOGGER.info("Index: " + index + " person: " + person.getName()); } });
forEachWithIndex
in interface InternalIterable<T>
forEachWithIndex
in class AbstractRichIterable<T>
public <S> ImmutableBag<S> selectInstancesOf(java.lang.Class<S> clazz)
RichIterable
clazz
.
RichIterable<Integer> integers = List.mutable.with(new Integer(0), new Long(0L), new Double(0.0)).selectInstancesOf(Integer.class);
selectInstancesOf
in interface Bag<T>
selectInstancesOf
in interface ImmutableBag<T>
selectInstancesOf
in interface ImmutableBagIterable<T>
selectInstancesOf
in interface ImmutableCollection<T>
selectInstancesOf
in interface RichIterable<T>
selectInstancesOf
in interface UnsortedBag<T>
public ImmutableBag<T> selectByOccurrences(IntPredicate predicate)
Bag
selectByOccurrences
in interface Bag<T>
selectByOccurrences
in interface ImmutableBag<T>
selectByOccurrences
in interface ImmutableBagIterable<T>
selectByOccurrences
in interface UnsortedBag<T>
public void forEachWithOccurrences(ObjectIntProcedure<? super T> objectIntProcedure)
Bag
forEachWithOccurrences
in interface Bag<T>
public int sizeDistinct()
Bag
sizeDistinct
in interface Bag<T>
public int occurrencesOf(java.lang.Object item)
Bag
occurrencesOf
in interface Bag<T>
public MutableList<T> toList()
RichIterable
toList
in interface RichIterable<T>
toList
in class AbstractBag<T>
public MutableList<T> toSortedList()
RichIterable
toSortedList
in interface RichIterable<T>
public MutableList<T> toSortedList(java.util.Comparator<? super T> comparator)
RichIterable
toSortedList
in interface RichIterable<T>
toSortedList
in class AbstractBag<T>
public MutableSortedSet<T> toSortedSet()
RichIterable
toSortedSet
in interface RichIterable<T>
toSortedSet
in class AbstractBag<T>
public MutableSortedSet<T> toSortedSet(java.util.Comparator<? super T> comparator)
RichIterable
toSortedSet
in interface RichIterable<T>
toSortedSet
in class AbstractBag<T>
public <K,V> MutableSortedMap<K,V> toSortedMap(Function<? super T,? extends K> keyFunction, Function<? super T,? extends V> valueFunction)
RichIterable
toSortedMap
in interface RichIterable<T>
toSortedMap
in class AbstractRichIterable<T>
public <K,V> MutableSortedMap<K,V> toSortedMap(java.util.Comparator<? super K> comparator, Function<? super T,? extends K> keyFunction, Function<? super T,? extends V> valueFunction)
RichIterable
toSortedMap
in interface RichIterable<T>
toSortedMap
in class AbstractRichIterable<T>
public ImmutableBag<T> select(Predicate<? super T> predicate)
RichIterable
Example using a Java 8 lambda expression:
RichIterable<Person> selected = people.select(person -> person.getAddress().getCity().equals("London"));
Example using an anonymous inner class:
RichIterable<Person> selected = people.select(new Predicate<Person>() { public boolean accept(Person person) { return person.getAddress().getCity().equals("London"); } });
select
in interface Bag<T>
select
in interface ImmutableBag<T>
select
in interface ImmutableBagIterable<T>
select
in interface ImmutableCollection<T>
select
in interface RichIterable<T>
select
in interface UnsortedBag<T>
public <R extends java.util.Collection<T>> R select(Predicate<? super T> predicate, R target)
RichIterable
Example using a Java 8 lambda expression:
MutableList<Person> selected = people.select(person -> person.person.getLastName().equals("Smith"), Lists.mutable.empty());
Example using an anonymous inner class:
MutableList<Person> selected = people.select(new Predicate<Person>() { public boolean accept(Person person) { return person.person.getLastName().equals("Smith"); } }, Lists.mutable.empty());
select
in interface RichIterable<T>
select
in class AbstractBag<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 predicate
target
, which contains appended elements as a result of the select criteriaRichIterable.select(Predicate)
public ImmutableBag<T> reject(Predicate<? super T> predicate)
RichIterable
Example using a Java 8 lambda expression:
RichIterable<Person> rejected = people.reject(person -> person.person.getLastName().equals("Smith"));
Example using an anonymous inner class:
RichIterable<Person> rejected = people.reject(new Predicate<Person>() { public boolean accept(Person person) { return person.person.getLastName().equals("Smith"); } });
reject
in interface Bag<T>
reject
in interface ImmutableBag<T>
reject
in interface ImmutableBagIterable<T>
reject
in interface ImmutableCollection<T>
reject
in interface RichIterable<T>
reject
in interface UnsortedBag<T>
predicate
- a Predicate
to use as the reject criteriaPredicate.accept(Object)
method to evaluate to falsepublic <R extends java.util.Collection<T>> R reject(Predicate<? super T> predicate, R target)
RichIterable
Example using a Java 8 lambda expression:
MutableList<Person> rejected = people.reject(person -> person.person.getLastName().equals("Smith"), Lists.mutable.empty());
Example using an anonymous inner class:
MutableList<Person> rejected = people.reject(new Predicate<Person>() { public boolean accept(Person person) { return person.person.getLastName().equals("Smith"); } }, Lists.mutable.empty());
reject
in interface RichIterable<T>
reject
in class AbstractBag<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 PartitionImmutableBag<T> partition(Predicate<? super T> predicate)
RichIterable
Example using a Java 8 lambda expression:
PartitionIterable<Person> newYorkersAndNonNewYorkers = people.partition(person -> person.getAddress().getState().getName().equals("New York"));
Example using an anonymous inner class:
PartitionIterable<Person> newYorkersAndNonNewYorkers = people.partition(new Predicate<Person>() { public boolean accept(Person person) { return person.getAddress().getState().getName().equals("New York"); } });
partition
in interface Bag<T>
partition
in interface ImmutableBag<T>
partition
in interface ImmutableBagIterable<T>
partition
in interface ImmutableCollection<T>
partition
in interface RichIterable<T>
partition
in interface UnsortedBag<T>
partition
in class AbstractImmutableBag<T>
public <V> ImmutableBag<V> collect(Function<? super T,? extends V> function)
RichIterable
Example using a Java 8 lambda expression:
RichIterable<String> names = people.collect(person -> person.getFirstName() + " " + person.getLastName());
Example using an anonymous inner class:
RichIterable<String> names = people.collect(new Function<Person, String>() { public String valueOf(Person person) { return person.getFirstName() + " " + person.getLastName(); } });
collect
in interface ImmutableBag<T>
collect
in interface ImmutableCollection<T>
collect
in interface RichIterable<T>
collect
in interface UnsortedBag<T>
public <V,R extends java.util.Collection<V>> R collect(Function<? super T,? extends V> function, R target)
RichIterable
RichIterable.collect(Function)
, except that the results are gathered into the specified target
collection.
Example using a Java 8 lambda expression:
MutableList<String> names = people.collect(person -> person.getFirstName() + " " + person.getLastName(), Lists.mutable.empty());
Example using an anonymous inner class:
MutableList<String> names = people.collect(new Function<Person, String>() { public String valueOf(Person person) { return person.getFirstName() + " " + person.getLastName(); } }, Lists.mutable.empty());
collect
in interface RichIterable<T>
collect
in class AbstractBag<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 function
target
, which contains appended elements as a result of the collect transformationRichIterable.collect(Function)
public <V> ImmutableBag<V> collectIf(Predicate<? super T> predicate, Function<? super T,? extends V> function)
RichIterable
Example using a Java 8 lambda and method reference:
RichIterable<String> strings = Lists.mutable.with(1, 2, 3).collectIf(e -> e != null, Object::toString);
Example using Predicates factory:
RichIterable<String> strings = Lists.mutable.with(1, 2, 3).collectIf(Predicates.notNull(), Functions.getToString());
collectIf
in interface ImmutableBag<T>
collectIf
in interface ImmutableCollection<T>
collectIf
in interface RichIterable<T>
collectIf
in interface UnsortedBag<T>
public <V,R extends java.util.Collection<V>> R collectIf(Predicate<? super T> predicate, Function<? super T,? extends V> function, R target)
RichIterable
collectIf
in interface RichIterable<T>
collectIf
in class AbstractBag<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 predicate
targetCollection
, which contains appended elements as a result of the collect criteria and transformationRichIterable.collectIf(Predicate, Function)
public <V> ImmutableBag<V> flatCollect(Function<? super T,? extends java.lang.Iterable<V>> function)
RichIterable
flatCollect
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 = Person::getAddresses; RichIterable<Person> people = ...;Using
collect
returns a collection of collections of addresses.
RichIterable<List<Address>> addresses = people.collect(addressFunction);Using
flatCollect
returns a single flattened list of addresses.
RichIterable<Address> addresses = people.flatCollect(addressFunction);
flatCollect
in interface ImmutableBag<T>
flatCollect
in interface ImmutableCollection<T>
flatCollect
in interface RichIterable<T>
flatCollect
in interface UnsortedBag<T>
function
- The Function
to applyfunction
public <V,R extends java.util.Collection<V>> R flatCollect(Function<? super T,? extends java.lang.Iterable<V>> function, R target)
RichIterable
flatCollect
in interface RichIterable<T>
flatCollect
in class AbstractBag<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 function
RichIterable.flatCollect(Function)
public T detect(Predicate<? super T> predicate)
RichIterable
Example using a Java 8 lambda expression:
Person person = people.detect(person -> person.getFirstName().equals("John") && person.getLastName().equals("Smith"));
Example using an anonymous inner class:
Person person = people.detect(new Predicate<Person>() { public boolean accept(Person person) { return person.getFirstName().equals("John") && person.getLastName().equals("Smith"); } });
detect
in interface RichIterable<T>
detect
in class AbstractRichIterable<T>
public <P> T detectWith(Predicate2<? super T,? super P> predicate, P parameter)
RichIterable
Example using a Java 8 lambda expression:
Person person = people.detectWith((person, fullName) -> person.getFullName().equals(fullName), "John Smith");
Example using an anonymous inner class:
Person person = people.detectWith(new Predicate2<Person, String>() { public boolean accept(Person person, String fullName) { return person.getFullName().equals(fullName); } }, "John Smith");
detectWith
in interface RichIterable<T>
detectWith
in class AbstractRichIterable<T>
public java.util.Optional<T> detectOptional(Predicate<? super T> predicate)
RichIterable
Example using a Java 8 lambda expression:
Person person = people.detectOptional(person -> person.getFirstName().equals("John") && person.getLastName().equals("Smith"));
detectOptional
in interface RichIterable<T>
detectOptional
in class AbstractRichIterable<T>
public <P> java.util.Optional<T> detectWithOptional(Predicate2<? super T,? super P> predicate, P parameter)
RichIterable
Example using a Java 8 lambda expression:
Optional<Person> person = people.detectWithOptional((person, fullName) -> person.getFullName().equals(fullName), "John Smith");
detectWithOptional
in interface RichIterable<T>
detectWithOptional
in class AbstractRichIterable<T>
public T detectIfNone(Predicate<? super T> predicate, Function0<? extends T> function)
RichIterable
detectIfNone
in interface RichIterable<T>
public int count(Predicate<? super T> predicate)
RichIterable
Example using a Java 8 lambda expression:
int count = people.count(person -> person.getAddress().getState().getName().equals("New York"));
Example using an anonymous inner class:
int count = people.count(new Predicate<Person>() { public boolean accept(Person person) { return person.getAddress().getState().getName().equals("New York"); } });
count
in interface RichIterable<T>
count
in class AbstractBag<T>
public boolean anySatisfy(Predicate<? super T> predicate)
RichIterable
anySatisfy
in interface RichIterable<T>
anySatisfy
in class AbstractRichIterable<T>
public <P> boolean anySatisfyWith(Predicate2<? super T,? super P> predicate, P parameter)
RichIterable
anySatisfyWith
in interface RichIterable<T>
anySatisfyWith
in class AbstractRichIterable<T>
public boolean allSatisfy(Predicate<? super T> predicate)
RichIterable
allSatisfy
in interface RichIterable<T>
allSatisfy
in class AbstractRichIterable<T>
public <P> boolean allSatisfyWith(Predicate2<? super T,? super P> predicate, P parameter)
RichIterable
allSatisfyWith
in interface RichIterable<T>
allSatisfyWith
in class AbstractRichIterable<T>
public boolean noneSatisfy(Predicate<? super T> predicate)
RichIterable
noneSatisfy
in interface RichIterable<T>
noneSatisfy
in class AbstractRichIterable<T>
public <P> boolean noneSatisfyWith(Predicate2<? super T,? super P> predicate, P parameter)
RichIterable
noneSatisfyWith
in interface RichIterable<T>
noneSatisfyWith
in class AbstractRichIterable<T>
public <IV> IV injectInto(IV injectedValue, Function2<? super IV,? super T,? extends IV> function)
RichIterable
injectInto
in interface RichIterable<T>
injectInto
in class AbstractBag<T>
public int injectInto(int injectedValue, IntObjectToIntFunction<? super T> function)
RichIterable
injectInto
in interface RichIterable<T>
injectInto
in class AbstractBag<T>
public long injectInto(long injectedValue, LongObjectToLongFunction<? super T> function)
RichIterable
injectInto
in interface RichIterable<T>
injectInto
in class AbstractBag<T>
public double injectInto(double injectedValue, DoubleObjectToDoubleFunction<? super T> function)
RichIterable
injectInto
in interface RichIterable<T>
injectInto
in class AbstractBag<T>
public float injectInto(float injectedValue, FloatObjectToFloatFunction<? super T> function)
RichIterable
injectInto
in interface RichIterable<T>
injectInto
in class AbstractBag<T>
public boolean equals(java.lang.Object obj)
Bag
public int hashCode()
Bag
Bag.toMapOfItemToCount()
.hashCode().public MutableMap<T,java.lang.Integer> toMapOfItemToCount()
Bag
toMapOfItemToCount
in interface Bag<T>
toMapOfItemToCount
in interface ImmutableBagIterable<T>
public MutableSet<T> toSet()
RichIterable
toSet
in interface RichIterable<T>
toSet
in class AbstractBag<T>
public MutableBag<T> toBag()
RichIterable
toBag
in interface RichIterable<T>
toBag
in class AbstractBag<T>
public MutableSortedBag<T> toSortedBag()
RichIterable
toSortedBag
in interface RichIterable<T>
toSortedBag
in class AbstractBag<T>
public MutableSortedBag<T> toSortedBag(java.util.Comparator<? super T> comparator)
RichIterable
toSortedBag
in interface RichIterable<T>
toSortedBag
in class AbstractBag<T>
public <V extends java.lang.Comparable<? super V>> MutableSortedBag<T> toSortedBagBy(Function<? super T,? extends V> function)
RichIterable
function
.toSortedBagBy
in interface RichIterable<T>
toSortedBagBy
in class AbstractRichIterable<T>
public LazyIterable<T> asLazy()
RichIterable
asLazy
in interface RichIterable<T>
asLazy
in class AbstractRichIterable<T>
public java.lang.Object[] toArray()
RichIterable
toArray
in interface RichIterable<T>
toArray
in class AbstractRichIterable<T>
Collection.toArray()
public <T> T[] toArray(T[] a)
RichIterable
toArray
in interface RichIterable<T>
toArray
in class AbstractRichIterable<T>
Collection.toArray(Object[])
public java.lang.String toString()
AbstractRichIterable
Assert.assertEquals("[]", Lists.mutable.empty().toString()); Assert.assertEquals("[1]", Lists.mutable.with(1).toString()); Assert.assertEquals("[1, 2, 3]", Lists.mutable.with(1, 2, 3).toString());
toString
in interface RichIterable<T>
toString
in class AbstractRichIterable<T>
AbstractCollection.toString()
public java.lang.String makeString()
RichIterable
RichIterable.makeString(String)
and defaulting
the separator parameter to the characters ", " (comma and space).makeString
in interface RichIterable<T>
public java.lang.String makeString(java.lang.String separator)
RichIterable
RichIterable.makeString(String, String, String)
and defaulting the start and end parameters to "" (the empty String).makeString
in interface RichIterable<T>
public java.lang.String makeString(java.lang.String start, java.lang.String separator, java.lang.String end)
RichIterable
makeString
in interface RichIterable<T>
public void appendString(java.lang.Appendable appendable)
RichIterable
Appendable
. Prints the string returned
by RichIterable.makeString()
.appendString
in interface RichIterable<T>
public void appendString(java.lang.Appendable appendable, java.lang.String separator)
RichIterable
Appendable
. Prints the string returned
by RichIterable.makeString(String)
.appendString
in interface 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)
RichIterable
Appendable
. Prints the string returned
by RichIterable.makeString(String, String, String)
.appendString
in interface RichIterable<T>
appendString
in class AbstractRichIterable<T>
@Deprecated public <S> ImmutableBag<Pair<T,S>> zip(java.lang.Iterable<S> that)
OrderedIterable.zip(Iterable)
instead.RichIterable
RichIterable
formed from this RichIterable
and another RichIterable
by
combining corresponding elements in pairs. If one of the two RichIterable
s is longer than the other, its
remaining elements are ignored.zip
in interface ImmutableBag<T>
zip
in interface ImmutableCollection<T>
zip
in interface RichIterable<T>
zip
in interface UnsortedBag<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<Pair<T,S>>> R zip(java.lang.Iterable<S> that, R target)
RichIterable
RichIterable.zip(Iterable)
but uses target
for output.zip
in interface RichIterable<T>
zip
in class AbstractRichIterable<T>
@Deprecated public ImmutableSet<Pair<T,java.lang.Integer>> zipWithIndex()
OrderedIterable.zipWithIndex()
instead.RichIterable
RichIterable
with its indices.zipWithIndex
in interface Bag<T>
zipWithIndex
in interface ImmutableBag<T>
zipWithIndex
in interface ImmutableBagIterable<T>
zipWithIndex
in interface ImmutableCollection<T>
zipWithIndex
in interface RichIterable<T>
zipWithIndex
in interface UnsortedBag<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<Pair<T,java.lang.Integer>>> R zipWithIndex(R target)
RichIterable
RichIterable.zipWithIndex()
but uses target
for output.zipWithIndex
in interface RichIterable<T>
zipWithIndex
in class AbstractRichIterable<T>
Copyright © 2004–2018. All rights reserved.