Class ImmutableEmptyBag<T>
- All Implemented Interfaces:
Serializable
,Iterable<T>
,Collection<T>
,Bag<T>
,ImmutableBag<T>
,ImmutableBagIterable<T>
,UnsortedBag<T>
,ImmutableCollection<T>
,InternalIterable<T>
,RichIterable<T>
ImmutableBag
which is created by calling the Bags.immutable.empty().- Since:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final PartitionImmutableBag
<Object> (package private) static final ImmutableBag
<?> private static final LazyIterable
<?> private static final long
private static final Object[]
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
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
allSatisfyWithOccurrences
(ObjectIntPredicate<? super T> predicate) Returns true if the predicate evaluates to true for all elements of the Bag.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.boolean
anySatisfyWithOccurrences
(ObjectIntPredicate<? super T> predicate) Returns true if the predicate evaluates to true for any element of the Bag.void
appendString
(Appendable appendable) Prints a string representation of this collection onto the givenAppendable
.void
appendString
(Appendable appendable, String separator) Prints a string representation of this collection onto the givenAppendable
.void
appendString
(Appendable appendable, String start, String separator, String end) Prints a string representation of this collection onto the givenAppendable
.asLazy()
Returns a lazy (deferred) iterable, most likely implemented by calling LazyIterate.adapt(this).chunk
(int size) Partitions elements in fixed size chunks.<V> ImmutableBag
<V> Returns a new collection with the results of applying the specified function on each element of the source collection.collectBoolean
(BooleanFunction<? super T> booleanFunction) Returns a new primitiveboolean
iterable with the results of applying the specified function on each element of the source collection.collectByte
(ByteFunction<? super T> byteFunction) Returns a new primitivebyte
iterable with the results of applying the specified function on each element of the source collection.collectChar
(CharFunction<? super T> charFunction) Returns a new primitivechar
iterable with the results of applying the specified function on each element of the source collection.collectDouble
(DoubleFunction<? super T> doubleFunction) Returns a new primitivedouble
iterable with the results of applying the specified function on each element of the source collection.collectFloat
(FloatFunction<? super T> floatFunction) Returns a new primitivefloat
iterable with the results of applying the specified function on each element of the source collection.<V> ImmutableBag
<V> 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.collectInt
(IntFunction<? super T> intFunction) Returns a new primitiveint
iterable with the results of applying the specified function on each element of the source collection.collectLong
(LongFunction<? super T> longFunction) Returns a new primitivelong
iterable with the results of applying the specified function on each element of the source collection.collectShort
(ShortFunction<? super T> shortFunction) Returns a new primitiveshort
iterable with the results of applying the specified function on each element of the source collection.<P,
V> ImmutableBag <V> collectWith
(Function2<? super T, ? super P, ? extends V> function, P parameter) Same asRichIterable.collect(Function)
with aFunction2
and specified parameter which is passed to the block.<V> ImmutableBag
<V> collectWithOccurrences
(ObjectIntToObjectFunction<? super T, ? extends V> function) Iterates over the unique elements and their occurrences and collects the results of applying the specified function.<V,
R extends Collection<V>>
RcollectWithOccurrences
(ObjectIntToObjectFunction<? super T, ? extends V> function, R target) Iterates over the unique elements and their occurrences and collects the results of applying the specified function into the target collection.boolean
Returns true if the iterable has an element which responds true to element.equals(object).boolean
containsAllArguments
(Object... elements) Returns true if all elements in the specified var arg array are contained in this collection.boolean
containsAllIterable
(Iterable<?> source) Returns true if all elements in source are contained in this collection.int
Return the total number of elements that answer true to the specified predicate.<V> ImmutableBag
<V> This method will count the number of occurrences of each value calculated by applying the function to each element of the collection.<V,
R extends MutableBagIterable<V>>
RThis method will count the number of occurrences of each value calculated by applying the function to each element of the collection.<V> ImmutableBag
<V> countByEach
(Function<? super T, ? extends Iterable<V>> function) This method will count the number of occurrences of each value calculated by applying the function to each element of the collection.<V,
R extends MutableBagIterable<V>>
RcountByEach
(Function<? super T, ? extends Iterable<V>> function, R target) This method will count the number of occurrences of each value calculated by applying the function to each element of the collection.<V,
P> ImmutableBag <V> countByWith
(Function2<? super T, ? super P, ? extends V> function, P parameter) This method will count the number of occurrences of each value calculated by applying the function to each element of the collection with the specified parameter as the second argument.<V,
P, R extends MutableBagIterable<V>>
RcountByWith
(Function2<? super T, ? super P, ? extends V> function, P parameter, R target) This method will count the number of occurrences of each value calculated by applying the function to each element of the collection with the specified parameter as the second argument.<P> int
countWith
(Predicate2<? super T, ? super P> predicate, P parameter) Returns the total number of elements that evaluate to true for the specified 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.detectIfNone
(Predicate<? super T> predicate, Function0<? extends T> function) Returns the first element of the iterable for which the predicate evaluates to true.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> T
detectWithIfNone
(Predicate2<? super T, ? super P> predicate, P parameter, Function0<? extends T> function) Returns the first element of the iterable that evaluates to true for the specified predicate2 and parameter, or returns the value of evaluating the specified function.detectWithOccurrences
(ObjectIntPredicate<? super T> predicate) Returns an element of the Bag that satisfies the predicate or null if such an element does not existdetectWithOptional
(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.Returns an unmodifiable view on the distinct elements with the same complexity as the Bag implementation.void
The procedure is executed for each element in the iterable.boolean
Two bagsb1
andb2
are equal ifm1.toMapOfItemToCount().equals(m2.toMapOfItemToCount())
.<V> ImmutableBag
<V> flatCollect
(Function<? super T, ? extends Iterable<V>> function) flatCollect
is a special case ofRichIterable.collect(Function)
.<P> void
forEachWith
(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
(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.getFirst()
Returns the first element of an iterable.getLast()
Returns the last element of an iterable.getOnly()
Returns the element if the iterable has exactly one element.<V> ImmutableBagMultimap
<V, T> 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> ImmutableBagMultimap
<V, T> groupByEach
(Function<? super T, ? extends Iterable<V>> function) Similar toRichIterable.groupBy(Function)
, except the result of evaluating function will return a collection of keys for each value.<V> ImmutableMap
<V, T> groupByUniqueKey
(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 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, 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.iterator()
Returns a string representation of this collection by delegating toRichIterable.makeString(String)
and defaulting the separator parameter to the characters", "
(comma and space).makeString
(String separator) Returns a string representation of this collection by delegating toRichIterable.makeString(String, String, String)
and defaulting the start and end parameters to""
(the empty String).makeString
(String start, String separator, 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.max()
Returns the maximum element out of this container based on the natural order.max
(Comparator<? super T> comparator) Returns the maximum element out of this container based on the comparator.<V extends Comparable<? super V>>
TReturns the maximum elements out of this container based on the natural order of the attribute returned by Function.min()
Returns the minimum element out of this container based on the natural order.min
(Comparator<? super T> comparator) Returns the minimum element out of this container based on the comparator.<V extends Comparable<? super V>>
TReturns the minimum elements out of this container based on the natural order of the attribute returned by Function.This method is similar to thewith
method inMutableCollection
with the difference that a new copy of this collection with the element appended will be returned.newWithAll
(Iterable<? extends T> elements) This method is similar to thewithAll
method inMutableCollection
with the difference that a new copy of this collection with the elements appended will be returned.newWithout
(T element) This method is similar to thewithout
method inMutableCollection
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
noneSatisfyWithOccurrences
(ObjectIntPredicate<? super T> predicate) Returns true if the Bag is empty or if the predicate evaluates to false for all elements of the Bag.boolean
notEmpty()
The English equivalent of !this.isEmpty()int
occurrencesOf
(Object item) The occurrences of a distinct item in the bag.Filters a collection into a PartitionedIterable based on the evaluation of the predicate.<P> PartitionImmutableBag
<T> partitionWith
(Predicate2<? super T, ? super P> predicate, P parameter) Filters a collection into a PartitionIterable based on the evaluation of the predicate.Returns all elements of the source collection that return false when evaluating of the predicate.<P> ImmutableBag
<T> rejectWith
(Predicate2<? super T, ? super P> predicate, P parameter) Similar toRichIterable.reject(Predicate)
, except with an evaluation parameter for the second generic argument inPredicate2
.Returns all elements of the source collection that return true when evaluating the predicate.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 Classclazz
.Returns a set containing all elements of the bag that have exactly one occurrence.<P> ImmutableBag
<T> selectWith
(Predicate2<? super T, ? super P> predicate, P parameter) Similar toRichIterable.select(Predicate)
, except with an evaluation parameter for the second generic argument inPredicate2
.int
size()
Returns the number of items in this iterable.int
The size of the Bag when counting only distinct elements.Executes the Procedure for each element in the iterable and returnsthis
.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.toBag()
Converts the collection to the default MutableBag implementation.toList()
Converts the collection to a MutableList implementation.<NK,
NV> MutableMap <NK, NV> Converts the collection to a MutableMap implementation using the specified key and value functions.<NK,
NV, R extends Map<NK, NV>>
RtoMap
(Function<? super T, ? extends NK> keyFunction, Function<? super T, ? extends NV> valueFunction, R target) Same asRichIterable.toMap(Function, Function)
, except that the results are gathered into the specifiedtarget
map.Converts the Bag to a Map of the Item type to its count as an Integer.toSet()
Converts the collection to a MutableSet implementation.Converts the collection to a MutableSortedBag implementation and sorts it using the natural order of the elements.toSortedBag
(Comparator<? super T> comparator) Converts the collection to the MutableSortedBag implementation and sorts it using the specified comparator.Converts the collection to a MutableList implementation and sorts it using the natural order of the elements.toSortedList
(Comparator<? super T> comparator) Converts the collection to a MutableList implementation and sorts it using the specified comparator.<NK,
NV> MutableSortedMap <NK, NV> toSortedMap
(Comparator<? super NK> comparator, Function<? super T, ? extends NK> keyFunction, Function<? super T, ? extends NV> valueFunction) Converts the collection to a MutableSortedMap implementation using the specified key and value functions sorted by the given comparator.<NK,
NV> MutableSortedMap <NK, NV> toSortedMap
(Function<? super T, ? extends NK> keyFunction, Function<? super T, ? extends NV> valueFunction) Converts the collection to a MutableSortedMap implementation using the specified key and value functions sorted by the key elements' natural ordering.toString()
Returns a string with the elements of the iterable separated by commas with spaces and enclosed in square brackets.private Object
<S> ImmutableBag
<Pair<T, S>> Deprecated.in 6.0.Deprecated.in 6.0.Methods inherited from class org.eclipse.collections.impl.bag.immutable.AbstractImmutableBag
bottomOccurrences, newWithoutAll, toImmutable, topOccurrences
Methods inherited from class org.eclipse.collections.impl.bag.immutable.AbstractImmutableBagIterable
add, addAll, castToCollection, clear, parallelStream, remove, removeAll, removeAllFrom, retainAll, shortCircuit, spliterator, stream, sumByDouble, sumByFloat, sumByInt, sumByLong
Methods inherited from class org.eclipse.collections.impl.bag.AbstractBag
collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, groupBy, groupByEach, injectInto, injectInto, injectInto, injectInto, injectIntoWith, occurrencesSortingBy, reject, rejectWith, select, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toListWithOccurrences, toSortedSet, toSortedSet, toStringOfItemToCount
Methods inherited from class org.eclipse.collections.impl.AbstractRichIterable
containsAll, forEach, groupByUniqueKey, into, toBiMap, toSortedBagBy, toSortedListBy, toSortedMapBy, toSortedSetBy, zip, zipWithIndex
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.collections.api.bag.Bag
aggregateBy, reduceInPlace, reduceInPlace, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, toStringOfItemToCount
Methods inherited from interface java.util.Collection
containsAll, removeIf, toArray
Methods inherited from interface org.eclipse.collections.api.bag.ImmutableBag
flatCollectWith, selectDuplicates, toImmutableBag
Methods inherited from interface org.eclipse.collections.api.bag.ImmutableBagIterable
selectDuplicates
Methods inherited from interface org.eclipse.collections.api.collection.ImmutableCollection
aggregateBy, aggregateInPlaceBy, castToCollection, flatCollectWith, parallelStream, spliterator, stream, sumByDouble, sumByFloat, sumByInt, sumByLong
Methods inherited from interface org.eclipse.collections.api.InternalIterable
forEach
Methods inherited from interface org.eclipse.collections.api.RichIterable
collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, containsAll, containsAny, containsAnyIterable, containsBy, containsNone, containsNoneIterable, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, flatCollectWith, forEach, getAny, groupBy, groupByAndCollect, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectIntoDouble, injectIntoFloat, injectIntoInt, injectIntoLong, into, makeString, maxByOptional, maxOptional, maxOptional, minByOptional, minOptional, minOptional, reduce, reject, rejectWith, select, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toBiMap, toImmutableBiMap, toImmutableList, toImmutableMap, toImmutableSet, toImmutableSortedBag, toImmutableSortedBag, toImmutableSortedBagBy, toImmutableSortedList, toImmutableSortedList, toImmutableSortedListBy, toImmutableSortedSet, toImmutableSortedSet, toImmutableSortedSetBy, toSortedBagBy, toSortedListBy, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, zip, zipWithIndex
-
Field Details
-
INSTANCE
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
LAZY_ITERABLE
-
TO_ARRAY
-
IMMUTABLE_EMPTY_PARTITION
-
-
Constructor Details
-
ImmutableEmptyBag
ImmutableEmptyBag()
-
-
Method Details
-
equals
Description copied from interface:Bag
Two bagsb1
andb2
are equal ifm1.toMapOfItemToCount().equals(m2.toMapOfItemToCount())
. -
sizeDistinct
public int sizeDistinct()Description copied from interface:Bag
The size of the Bag when counting only distinct elements.- Specified by:
sizeDistinct
in interfaceBag<T>
-
occurrencesOf
Description copied from interface:Bag
The occurrences of a distinct item in the bag.- Specified by:
occurrencesOf
in interfaceBag<T>
-
forEachWithOccurrences
Description copied from interface:Bag
For each distinct item, with the number of occurrences, execute the specified procedure.- Specified by:
forEachWithOccurrences
in interfaceBag<T>
-
anySatisfyWithOccurrences
Description copied from interface:Bag
Returns true if the predicate evaluates to true for any element of the Bag. Returns false if the Bag is empty or if no element returns true for the predicate.- Specified by:
anySatisfyWithOccurrences
in interfaceBag<T>
-
allSatisfyWithOccurrences
Description copied from interface:Bag
Returns true if the predicate evaluates to true for all elements of the Bag. Returns false if the Bag is empty or if not all elements return true for the predicate.- Specified by:
allSatisfyWithOccurrences
in interfaceBag<T>
-
noneSatisfyWithOccurrences
Description copied from interface:Bag
Returns true if the Bag is empty or if the predicate evaluates to false for all elements of the Bag. Returns false if the predicate evaluates to true for at least one element of the Bag.- Specified by:
noneSatisfyWithOccurrences
in interfaceBag<T>
-
detectWithOccurrences
Description copied from interface:Bag
Returns an element of the Bag that satisfies the predicate or null if such an element does not exist- Specified by:
detectWithOccurrences
in interfaceBag<T>
-
collectWithOccurrences
public <V> ImmutableBag<V> collectWithOccurrences(ObjectIntToObjectFunction<? super T, ? extends V> function) Description copied from interface:Bag
Iterates over the unique elements and their occurrences and collects the results of applying the specified function.- Specified by:
collectWithOccurrences
in interfaceBag<T>
- Specified by:
collectWithOccurrences
in interfaceImmutableBag<T>
- Specified by:
collectWithOccurrences
in interfaceImmutableBagIterable<T>
- Specified by:
collectWithOccurrences
in interfaceUnsortedBag<T>
- Overrides:
collectWithOccurrences
in classAbstractImmutableBag<T>
-
collectWithOccurrences
public <V,R extends Collection<V>> R collectWithOccurrences(ObjectIntToObjectFunction<? super T, ? extends V> function, R target) Description copied from interface:Bag
Iterates over the unique elements and their occurrences and collects the results of applying the specified function into the target collection.- Specified by:
collectWithOccurrences
in interfaceBag<T>
- Since:
- 9.1.
-
toMapOfItemToCount
Description copied from interface:Bag
Converts the Bag to a Map of the Item type to its count as an Integer.- Specified by:
toMapOfItemToCount
in interfaceBag<T>
- Specified by:
toMapOfItemToCount
in interfaceImmutableBagIterable<T>
-
hashCode
public int hashCode()Description copied from interface:Bag
Returns the hash code for this Bag, defined as this.Bag.toMapOfItemToCount()
.hashCode(). -
size
public int size()Description copied from interface:RichIterable
Returns the number of items in this iterable.- Specified by:
size
in interfaceCollection<T>
- Specified by:
size
in interfaceRichIterable<T>
-
isEmpty
public boolean isEmpty()Description copied from interface:RichIterable
Returns true if this iterable has zero items.- Specified by:
isEmpty
in interfaceCollection<T>
- Specified by:
isEmpty
in interfaceRichIterable<T>
- Overrides:
isEmpty
in classAbstractRichIterable<T>
-
notEmpty
public boolean notEmpty()Description copied from interface:RichIterable
The English equivalent of !this.isEmpty()- Specified by:
notEmpty
in interfaceRichIterable<T>
-
contains
Description copied from interface:RichIterable
Returns true if the iterable has an element which responds true to element.equals(object).- Specified by:
contains
in interfaceCollection<T>
- Specified by:
contains
in interfaceRichIterable<T>
- Overrides:
contains
in classAbstractRichIterable<T>
-
containsAllIterable
Description copied from interface:RichIterable
Returns true if all elements in source are contained in this collection.- Specified by:
containsAllIterable
in interfaceRichIterable<T>
- Overrides:
containsAllIterable
in classAbstractRichIterable<T>
-
containsAllArguments
Description copied from interface:RichIterable
Returns true if all elements in the specified var arg array are contained in this collection.- Specified by:
containsAllArguments
in interfaceRichIterable<T>
- Overrides:
containsAllArguments
in classAbstractRichIterable<T>
-
tap
Description copied from interface:RichIterable
Executes the Procedure for each element in the iterable and returnsthis
.Example using a Java 8 lambda expression:
RichIterable<Person> tapped = people.tap(person -> LOGGER.info(person.getName()));
Example using an anonymous inner class:
RichIterable<Person> tapped = people.tap(new Procedure<Person>() { public void value(Person person) { LOGGER.info(person.getName()); } });
- Specified by:
tap
in interfaceBag<T>
- Specified by:
tap
in interfaceImmutableBag<T>
- Specified by:
tap
in interfaceImmutableBagIterable<T>
- Specified by:
tap
in interfaceImmutableCollection<T>
- Specified by:
tap
in interfaceRichIterable<T>
- Specified by:
tap
in interfaceUnsortedBag<T>
- Overrides:
tap
in classAbstractImmutableBag<T>
- See Also:
-
each
Description copied from interface:RichIterable
The procedure is executed for each element in the iterable.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 ofInternalIterable.forEach(Procedure)
that has a signature conflict withIterable.forEach(java.util.function.Consumer)
.- Specified by:
each
in interfaceRichIterable<T>
- See Also:
-
forEachWithIndex
Description copied from interface:InternalIterable
Iterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.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()); } });
- Specified by:
forEachWithIndex
in interfaceInternalIterable<T>
- Overrides:
forEachWithIndex
in classAbstractRichIterable<T>
-
forEachWith
Description copied from interface:InternalIterable
The procedure2 is evaluated for each element in the iterable with the specified parameter provided as the second argument.Example using a Java 8 lambda:
people.forEachWith((Person person, Person other) -> { if (person.isRelatedTo(other)) { LOGGER.info(person.getName()); } }, fred);
Example using an anonymous inner class:
people.forEachWith(new Procedure2<Person, Person>() { public void value(Person person, Person other) { if (person.isRelatedTo(other)) { LOGGER.info(person.getName()); } } }, fred);
- Specified by:
forEachWith
in interfaceInternalIterable<T>
- Overrides:
forEachWith
in classAbstractRichIterable<T>
-
getFirst
Description copied from interface:RichIterable
Returns the first element of an iterable. In the case of a List it is the element at the first index. In the case of any other Collection, it is the first element that would be returned during an iteration. If the iterable is empty, null is returned. If null is a valid element of the container, then a developer would need to check to see if the iterable is empty to validate that a null result was not due to the container being empty.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.
- Specified by:
getFirst
in interfaceRichIterable<T>
-
getLast
Description copied from interface:RichIterable
Returns the last element of an iterable. In the case of a List it is the element at the last index. In the case of any other Collection, it is the last element that would be returned during an iteration. If the iterable is empty, null is returned. If null is a valid element of the container, then a developer would need to check to see if the iterable is empty to validate that a null result was not due to the container being empty.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.
- Specified by:
getLast
in interfaceRichIterable<T>
-
getOnly
Description copied from interface:RichIterable
Returns the element if the iterable has exactly one element. Otherwise, throwIllegalStateException
.- Specified by:
getOnly
in interfaceRichIterable<T>
- Returns:
- an element of an iterable.
-
iterator
-
newWith
Description copied from interface:ImmutableCollection
This method is similar to thewith
method inMutableCollection
with the difference that a new copy of this collection with the element appended will be returned.- Specified by:
newWith
in interfaceImmutableBag<T>
- Specified by:
newWith
in interfaceImmutableCollection<T>
-
newWithout
Description copied from interface:ImmutableCollection
This method is similar to thewithout
method inMutableCollection
with the difference that a new copy of this collection with the element removed will be returned.- Specified by:
newWithout
in interfaceImmutableBag<T>
- Specified by:
newWithout
in interfaceImmutableCollection<T>
-
newWithAll
Description copied from interface:ImmutableCollection
This method is similar to thewithAll
method inMutableCollection
with the difference that a new copy of this collection with the elements appended will be returned.- Specified by:
newWithAll
in interfaceImmutableBag<T>
- Specified by:
newWithAll
in interfaceImmutableCollection<T>
-
selectByOccurrences
Description copied from interface:Bag
Returns all elements of the bag that have a number of occurrences that satisfy the predicate.- Specified by:
selectByOccurrences
in interfaceBag<T>
- Specified by:
selectByOccurrences
in interfaceImmutableBag<T>
- Specified by:
selectByOccurrences
in interfaceImmutableBagIterable<T>
- Specified by:
selectByOccurrences
in interfaceUnsortedBag<T>
-
select
Description copied from interface:RichIterable
Returns all elements of the source collection that return true when evaluating the predicate. This method is also commonly called filter.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"); } });
- Specified by:
select
in interfaceBag<T>
- Specified by:
select
in interfaceImmutableBag<T>
- Specified by:
select
in interfaceImmutableBagIterable<T>
- Specified by:
select
in interfaceImmutableCollection<T>
- Specified by:
select
in interfaceRichIterable<T>
- Specified by:
select
in interfaceUnsortedBag<T>
-
selectWith
Description copied from interface:RichIterable
Similar toRichIterable.select(Predicate)
, except with an evaluation parameter for the second generic argument inPredicate2
.E.g. return a
Collection
of Person elements where the person has an age greater than or equal to 18 yearsExample using a Java 8 lambda expression:
RichIterable<Person> selected = people.selectWith((Person person, Integer age) -> person.getAge()>= age, Integer.valueOf(18));
Example using an anonymous inner class:
RichIterable<Person> selected = people.selectWith(new Predicate2<Person, Integer>() { public boolean accept(Person person, Integer age) { return person.getAge()>= age; } }, Integer.valueOf(18));
- Specified by:
selectWith
in interfaceBag<T>
- Specified by:
selectWith
in interfaceImmutableBag<T>
- Specified by:
selectWith
in interfaceImmutableBagIterable<T>
- Specified by:
selectWith
in interfaceImmutableCollection<T>
- Specified by:
selectWith
in interfaceRichIterable<T>
- Specified by:
selectWith
in interfaceUnsortedBag<T>
- Overrides:
selectWith
in classAbstractImmutableBag<T>
- Parameters:
predicate
- aPredicate2
to use as the select criteriaparameter
- a parameter to pass in for evaluation of the second argumentP
inpredicate
- See Also:
-
reject
Description copied from interface:RichIterable
Returns all elements of the source collection that return false when evaluating of the predicate. This method is also sometimes called filterNot and is the equivalent of calling iterable.select(Predicates.not(predicate)).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"); } });
- Specified by:
reject
in interfaceBag<T>
- Specified by:
reject
in interfaceImmutableBag<T>
- Specified by:
reject
in interfaceImmutableBagIterable<T>
- Specified by:
reject
in interfaceImmutableCollection<T>
- Specified by:
reject
in interfaceRichIterable<T>
- Specified by:
reject
in interfaceUnsortedBag<T>
- Parameters:
predicate
- aPredicate
to use as the reject criteria- Returns:
- a RichIterable that contains elements that cause
Predicate.accept(Object)
method to evaluate to false
-
rejectWith
Description copied from interface:RichIterable
Similar toRichIterable.reject(Predicate)
, except with an evaluation parameter for the second generic argument inPredicate2
.E.g. return a
Collection
of Person elements where the person has an age greater than or equal to 18 yearsExample using a Java 8 lambda expression:
RichIterable<Person> rejected = people.rejectWith((Person person, Integer age) -> person.getAge() < age, Integer.valueOf(18));
Example using an anonymous inner class:
MutableList<Person> rejected = people.rejectWith(new Predicate2<Person, Integer>() { public boolean accept(Person person, Integer age) { return person.getAge() < age; } }, Integer.valueOf(18));
- Specified by:
rejectWith
in interfaceBag<T>
- Specified by:
rejectWith
in interfaceImmutableBag<T>
- Specified by:
rejectWith
in interfaceImmutableBagIterable<T>
- Specified by:
rejectWith
in interfaceImmutableCollection<T>
- Specified by:
rejectWith
in interfaceRichIterable<T>
- Specified by:
rejectWith
in interfaceUnsortedBag<T>
- Overrides:
rejectWith
in classAbstractImmutableBag<T>
- Parameters:
predicate
- aPredicate2
to use as the select criteriaparameter
- a parameter to pass in for evaluation of the second argumentP
inpredicate
- See Also:
-
partition
Description copied from interface:RichIterable
Filters a collection into a PartitionedIterable based on the evaluation of the predicate.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"); } });
- Specified by:
partition
in interfaceBag<T>
- Specified by:
partition
in interfaceImmutableBag<T>
- Specified by:
partition
in interfaceImmutableBagIterable<T>
- Specified by:
partition
in interfaceImmutableCollection<T>
- Specified by:
partition
in interfaceRichIterable<T>
- Specified by:
partition
in interfaceUnsortedBag<T>
- Overrides:
partition
in classAbstractImmutableBag<T>
-
partitionWith
public <P> PartitionImmutableBag<T> partitionWith(Predicate2<? super T, ? super P> predicate, P parameter) Description copied from interface:RichIterable
Filters a collection into a PartitionIterable based on the evaluation of the predicate.Example using a Java 8 lambda expression:
PartitionIterable<Person> newYorkersAndNonNewYorkers = people.partitionWith((Person person, String state) -> person.getAddress().getState().getName().equals(state), "New York");
Example using an anonymous inner class:
PartitionIterable<Person> newYorkersAndNonNewYorkers = people.partitionWith(new Predicate2<Person, String>() { public boolean accept(Person person, String state) { return person.getAddress().getState().getName().equals(state); } }, "New York");
- Specified by:
partitionWith
in interfaceBag<T>
- Specified by:
partitionWith
in interfaceImmutableBag<T>
- Specified by:
partitionWith
in interfaceImmutableBagIterable<T>
- Specified by:
partitionWith
in interfaceImmutableCollection<T>
- Specified by:
partitionWith
in interfaceRichIterable<T>
- Overrides:
partitionWith
in classAbstractImmutableBag<T>
-
selectInstancesOf
Description copied from interface:RichIterable
Returns all elements of the source collection that are instances of the Classclazz
.RichIterable<Integer> integers = List.mutable.with(new Integer(0), new Long(0L), new Double(0.0)).selectInstancesOf(Integer.class);
- Specified by:
selectInstancesOf
in interfaceBag<T>
- Specified by:
selectInstancesOf
in interfaceImmutableBag<T>
- Specified by:
selectInstancesOf
in interfaceImmutableBagIterable<T>
- Specified by:
selectInstancesOf
in interfaceImmutableCollection<T>
- Specified by:
selectInstancesOf
in interfaceRichIterable<T>
- Specified by:
selectInstancesOf
in interfaceUnsortedBag<T>
-
collect
Description copied from interface:RichIterable
Returns a new collection with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.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(); } });
- Specified by:
collect
in interfaceImmutableBag<T>
- Specified by:
collect
in interfaceImmutableCollection<T>
- Specified by:
collect
in interfaceRichIterable<T>
- Specified by:
collect
in interfaceUnsortedBag<T>
-
collectBoolean
Description copied from interface:RichIterable
Returns a new primitiveboolean
iterable with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.Example using a Java 8 lambda expression:
BooleanIterable licenses = people.collectBoolean(person -> person.hasDrivingLicense());
Example using an anonymous inner class:
BooleanIterable licenses = people.collectBoolean(new BooleanFunction<Person>() { public boolean booleanValueOf(Person person) { return person.hasDrivingLicense(); } });
- Specified by:
collectBoolean
in interfaceImmutableBag<T>
- Specified by:
collectBoolean
in interfaceImmutableCollection<T>
- Specified by:
collectBoolean
in interfaceRichIterable<T>
- Specified by:
collectBoolean
in interfaceUnsortedBag<T>
- Overrides:
collectBoolean
in classAbstractImmutableBag<T>
-
collectByte
Description copied from interface:RichIterable
Returns a new primitivebyte
iterable with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.Example using a Java 8 lambda expression:
ByteIterable bytes = people.collectByte(person -> person.getCode());
Example using an anonymous inner class:
ByteIterable bytes = people.collectByte(new ByteFunction<Person>() { public byte byteValueOf(Person person) { return person.getCode(); } });
- Specified by:
collectByte
in interfaceImmutableBag<T>
- Specified by:
collectByte
in interfaceImmutableCollection<T>
- Specified by:
collectByte
in interfaceRichIterable<T>
- Specified by:
collectByte
in interfaceUnsortedBag<T>
- Overrides:
collectByte
in classAbstractImmutableBag<T>
-
collectChar
Description copied from interface:RichIterable
Returns a new primitivechar
iterable with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.Example using a Java 8 lambda expression:
CharIterable chars = people.collectChar(person -> person.getMiddleInitial());
Example using an anonymous inner class:
CharIterable chars = people.collectChar(new CharFunction<Person>() { public char charValueOf(Person person) { return person.getMiddleInitial(); } });
- Specified by:
collectChar
in interfaceImmutableBag<T>
- Specified by:
collectChar
in interfaceImmutableCollection<T>
- Specified by:
collectChar
in interfaceRichIterable<T>
- Specified by:
collectChar
in interfaceUnsortedBag<T>
- Overrides:
collectChar
in classAbstractImmutableBag<T>
-
collectDouble
Description copied from interface:RichIterable
Returns a new primitivedouble
iterable with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.Example using a Java 8 lambda expression:
DoubleIterable doubles = people.collectDouble(person -> person.getMilesFromNorthPole());
Example using an anonymous inner class:
DoubleIterable doubles = people.collectDouble(new DoubleFunction<Person>() { public double doubleValueOf(Person person) { return person.getMilesFromNorthPole(); } });
- Specified by:
collectDouble
in interfaceImmutableBag<T>
- Specified by:
collectDouble
in interfaceImmutableCollection<T>
- Specified by:
collectDouble
in interfaceRichIterable<T>
- Specified by:
collectDouble
in interfaceUnsortedBag<T>
- Overrides:
collectDouble
in classAbstractImmutableBag<T>
-
collectFloat
Description copied from interface:RichIterable
Returns a new primitivefloat
iterable with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.Example using a Java 8 lambda expression:
FloatIterable floats = people.collectFloat(person -> person.getHeightInInches());
Example using an anonymous inner class:
FloatIterable floats = people.collectFloat(new FloatFunction<Person>() { public float floatValueOf(Person person) { return person.getHeightInInches(); } });
- Specified by:
collectFloat
in interfaceImmutableBag<T>
- Specified by:
collectFloat
in interfaceImmutableCollection<T>
- Specified by:
collectFloat
in interfaceRichIterable<T>
- Specified by:
collectFloat
in interfaceUnsortedBag<T>
- Overrides:
collectFloat
in classAbstractImmutableBag<T>
-
collectInt
Description copied from interface:RichIterable
Returns a new primitiveint
iterable with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.Example using a Java 8 lambda expression:
IntIterable ints = people.collectInt(person -> person.getAge());
Example using an anonymous inner class:
IntIterable ints = people.collectInt(new IntFunction<Person>() { public int intValueOf(Person person) { return person.getAge(); } });
- Specified by:
collectInt
in interfaceImmutableBag<T>
- Specified by:
collectInt
in interfaceImmutableCollection<T>
- Specified by:
collectInt
in interfaceRichIterable<T>
- Specified by:
collectInt
in interfaceUnsortedBag<T>
- Overrides:
collectInt
in classAbstractImmutableBag<T>
-
collectLong
Description copied from interface:RichIterable
Returns a new primitivelong
iterable with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.Example using a Java 8 lambda expression:
LongIterable longs = people.collectLong(person -> person.getGuid());
Example using an anonymous inner class:
LongIterable longs = people.collectLong(new LongFunction<Person>() { public long longValueOf(Person person) { return person.getGuid(); } });
- Specified by:
collectLong
in interfaceImmutableBag<T>
- Specified by:
collectLong
in interfaceImmutableCollection<T>
- Specified by:
collectLong
in interfaceRichIterable<T>
- Specified by:
collectLong
in interfaceUnsortedBag<T>
- Overrides:
collectLong
in classAbstractImmutableBag<T>
-
collectShort
Description copied from interface:RichIterable
Returns a new primitiveshort
iterable with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.Example using a Java 8 lambda expression:
ShortIterable shorts = people.collectShort(person -> person.getNumberOfJunkMailItemsReceivedPerMonth());
Example using an anonymous inner class:
ShortIterable shorts = people.collectShort(new ShortFunction<Person>() { public short shortValueOf(Person person) { return person.getNumberOfJunkMailItemsReceivedPerMonth(); } });
- Specified by:
collectShort
in interfaceImmutableBag<T>
- Specified by:
collectShort
in interfaceImmutableCollection<T>
- Specified by:
collectShort
in interfaceRichIterable<T>
- Specified by:
collectShort
in interfaceUnsortedBag<T>
- Overrides:
collectShort
in classAbstractImmutableBag<T>
-
collectWith
public <P,V> ImmutableBag<V> collectWith(Function2<? super T, ? super P, ? extends V> function, P parameter) Description copied from interface:RichIterable
Same asRichIterable.collect(Function)
with aFunction2
and specified parameter which is passed to the block.Example using a Java 8 lambda expression:
RichIterable<Integer> integers = Lists.mutable.with(1, 2, 3).collectWith((each, parameter) -> each + parameter, Integer.valueOf(1));
Example using an anonymous inner class:
Function2<Integer, Integer, Integer> addParameterFunction = new Function2<Integer, Integer, Integer>() { public Integer value(Integer each, Integer parameter) { return each + parameter; } }; RichIterable<Integer> integers = Lists.mutable.with(1, 2, 3).collectWith(addParameterFunction, Integer.valueOf(1));
- Specified by:
collectWith
in interfaceImmutableBag<T>
- Specified by:
collectWith
in interfaceImmutableCollection<T>
- Specified by:
collectWith
in interfaceRichIterable<T>
- Specified by:
collectWith
in interfaceUnsortedBag<T>
- Overrides:
collectWith
in classAbstractImmutableBag<T>
- Parameters:
function
- AFunction2
to use as the collect transformation functionparameter
- A parameter to pass in for evaluation of the second argumentP
infunction
- Returns:
- A new
RichIterable
that contains the transformed elements returned byFunction2.value(Object, Object)
- See Also:
-
collectIf
public <V> ImmutableBag<V> collectIf(Predicate<? super T> predicate, Function<? super T, ? extends V> function) Description copied from interface:RichIterable
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. This is the optimized equivalent of calling iterable.select(predicate).collect(function).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());
- Specified by:
collectIf
in interfaceImmutableBag<T>
- Specified by:
collectIf
in interfaceImmutableCollection<T>
- Specified by:
collectIf
in interfaceRichIterable<T>
- Specified by:
collectIf
in interfaceUnsortedBag<T>
-
flatCollect
Description copied from interface:RichIterable
flatCollect
is a special case ofRichIterable.collect(Function)
. Withcollect
, when theFunction
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 eachPerson
has a list ofAddress
objects. Take the followingFunction
:Function<Person, List<Address>> addressFunction = Person::getAddresses; RichIterable<Person> people = ...;
Usingcollect
returns a collection of collections of addresses.RichIterable<List<Address>> addresses = people.collect(addressFunction);
UsingflatCollect
returns a single flattened list of addresses.RichIterable<Address> addresses = people.flatCollect(addressFunction);
- Specified by:
flatCollect
in interfaceImmutableBag<T>
- Specified by:
flatCollect
in interfaceImmutableCollection<T>
- Specified by:
flatCollect
in interfaceRichIterable<T>
- Specified by:
flatCollect
in interfaceUnsortedBag<T>
- Parameters:
function
- TheFunction
to apply- Returns:
- a new flattened collection produced by applying the given
function
-
countBy
Description copied from interface:RichIterable
This method will count the number of occurrences of each value calculated by applying the function to each element of the collection.- Specified by:
countBy
in interfaceImmutableBag<T>
- Specified by:
countBy
in interfaceImmutableCollection<T>
- Specified by:
countBy
in interfaceRichIterable<T>
- Overrides:
countBy
in classAbstractImmutableBag<T>
- Since:
- 9.0
-
countBy
public <V,R extends MutableBagIterable<V>> R countBy(Function<? super T, ? extends V> function, R target) Description copied from interface:RichIterable
This method will count the number of occurrences of each value calculated by applying the function to each element of the collection.- Specified by:
countBy
in interfaceRichIterable<T>
- Since:
- 9.0
-
countByWith
public <V,P> ImmutableBag<V> countByWith(Function2<? super T, ? super P, ? extends V> function, P parameter) Description copied from interface:RichIterable
This method will count the number of occurrences of each value calculated by applying the function to each element of the collection with the specified parameter as the second argument.- Specified by:
countByWith
in interfaceImmutableBag<T>
- Specified by:
countByWith
in interfaceImmutableCollection<T>
- Specified by:
countByWith
in interfaceRichIterable<T>
- Overrides:
countByWith
in classAbstractImmutableBag<T>
- Since:
- 9.0
-
countByWith
public <V,P, R countByWithR extends MutableBagIterable<V>> (Function2<? super T, ? super P, ? extends V> function, P parameter, R target) Description copied from interface:RichIterable
This method will count the number of occurrences of each value calculated by applying the function to each element of the collection with the specified parameter as the second argument.- Specified by:
countByWith
in interfaceRichIterable<T>
- Since:
- 9.0
-
countByEach
Description copied from interface:RichIterable
This method will count the number of occurrences of each value calculated by applying the function to each element of the collection.- Specified by:
countByEach
in interfaceImmutableBag<T>
- Specified by:
countByEach
in interfaceImmutableCollection<T>
- Specified by:
countByEach
in interfaceRichIterable<T>
- Overrides:
countByEach
in classAbstractImmutableBag<T>
- Since:
- 10.0.0
-
countByEach
public <V,R extends MutableBagIterable<V>> R countByEach(Function<? super T, ? extends Iterable<V>> function, R target) Description copied from interface:RichIterable
This method will count the number of occurrences of each value calculated by applying the function to each element of the collection.- Specified by:
countByEach
in interfaceRichIterable<T>
- Since:
- 10.0.0
-
groupBy
Description copied from interface:RichIterable
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.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(); } });
- Specified by:
groupBy
in interfaceBag<T>
- Specified by:
groupBy
in interfaceImmutableBag<T>
- Specified by:
groupBy
in interfaceImmutableBagIterable<T>
- Specified by:
groupBy
in interfaceImmutableCollection<T>
- Specified by:
groupBy
in interfaceRichIterable<T>
- Specified by:
groupBy
in interfaceUnsortedBag<T>
-
groupByEach
public <V> ImmutableBagMultimap<V,T> groupByEach(Function<? super T, ? extends Iterable<V>> function) Description copied from interface:RichIterable
Similar toRichIterable.groupBy(Function)
, except the result of evaluating function will return a collection of keys for each value.- Specified by:
groupByEach
in interfaceBag<T>
- Specified by:
groupByEach
in interfaceImmutableBag<T>
- Specified by:
groupByEach
in interfaceImmutableBagIterable<T>
- Specified by:
groupByEach
in interfaceImmutableCollection<T>
- Specified by:
groupByEach
in interfaceRichIterable<T>
- Specified by:
groupByEach
in interfaceUnsortedBag<T>
-
groupByUniqueKey
Description copied from interface:RichIterable
For each element of the iterable, the function is evaluated, and the results of these evaluations are collected into a new map, where the transformed value is the key. The generated keys must each be unique, or else an exception is thrown.- Specified by:
groupByUniqueKey
in interfaceImmutableCollection<T>
- Specified by:
groupByUniqueKey
in interfaceRichIterable<T>
- Overrides:
groupByUniqueKey
in classAbstractImmutableBag<T>
- See Also:
-
detect
Description copied from interface:RichIterable
Returns the first element of the iterable for which the predicate evaluates to true or null in the case where no element returns true. This method is commonly called find.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"); } });
- Specified by:
detect
in interfaceRichIterable<T>
- Overrides:
detect
in classAbstractRichIterable<T>
-
detectWith
Description copied from interface:RichIterable
Returns the first element that evaluates to true for the specified predicate2 and parameter, or null if none evaluate to true.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");
- Specified by:
detectWith
in interfaceRichIterable<T>
- Overrides:
detectWith
in classAbstractRichIterable<T>
-
detectOptional
Description copied from interface:RichIterable
Returns the first element of the iterable for which the predicate evaluates to true as an Optional. This method is commonly called find.Example using a Java 8 lambda expression:
Person person = people.detectOptional(person -> person.getFirstName().equals("John") && person.getLastName().equals("Smith"));
- Specified by:
detectOptional
in interfaceRichIterable<T>
- Overrides:
detectOptional
in classAbstractRichIterable<T>
-
detectWithOptional
Description copied from interface:RichIterable
Returns the first element that evaluates to true for the specified predicate2 and parameter as an Optional.Example using a Java 8 lambda expression:
Optional<Person> person = people.detectWithOptional((person, fullName) -> person.getFullName().equals(fullName), "John Smith");
- Specified by:
detectWithOptional
in interfaceRichIterable<T>
- Overrides:
detectWithOptional
in classAbstractRichIterable<T>
-
detectIfNone
Description copied from interface:RichIterable
Returns the first element of the iterable for which the predicate evaluates to true. If no element matches the predicate, then returns the value of applying the specified function.- Specified by:
detectIfNone
in interfaceRichIterable<T>
-
detectWithIfNone
public <P> T detectWithIfNone(Predicate2<? super T, ? super P> predicate, P parameter, Function0<? extends T> function) Description copied from interface:RichIterable
Returns the first element of the iterable that evaluates to true for the specified predicate2 and parameter, or returns the value of evaluating the specified function.- Specified by:
detectWithIfNone
in interfaceRichIterable<T>
- Overrides:
detectWithIfNone
in classAbstractRichIterable<T>
-
count
Description copied from interface:RichIterable
Return the total number of elements that answer true to the specified predicate.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"); } });
- Specified by:
count
in interfaceRichIterable<T>
- Overrides:
count
in classAbstractBag<T>
-
countWith
Description copied from interface:RichIterable
Returns the total number of elements that evaluate to true for the specified predicate.e.g. return lastNames.countWith(Predicates2.equal(), "Smith");
- Specified by:
countWith
in interfaceRichIterable<T>
- Overrides:
countWith
in classAbstractRichIterable<T>
-
anySatisfy
Description copied from interface:RichIterable
Returns true if the predicate evaluates to true for any element of the iterable. Returns false if the iterable is empty, or if no element returned true when evaluating the predicate.- Specified by:
anySatisfy
in interfaceRichIterable<T>
- Overrides:
anySatisfy
in classAbstractRichIterable<T>
-
allSatisfy
Description copied from interface:RichIterable
Returns true if the predicate evaluates to true for every element of the iterable or if the iterable is empty. Otherwise, returns false.- Specified by:
allSatisfy
in interfaceRichIterable<T>
- Overrides:
allSatisfy
in classAbstractRichIterable<T>
-
noneSatisfy
Description copied from interface:RichIterable
Returns true if the predicate evaluates to false for every element of the iterable or if the iterable is empty. Otherwise, returns false.- Specified by:
noneSatisfy
in interfaceRichIterable<T>
- Overrides:
noneSatisfy
in classAbstractRichIterable<T>
-
anySatisfyWith
Description copied from interface:RichIterable
Returns true if the predicate evaluates to true for any element of the collection, or return false. Returns false if the collection is empty.- Specified by:
anySatisfyWith
in interfaceRichIterable<T>
- Overrides:
anySatisfyWith
in classAbstractRichIterable<T>
-
allSatisfyWith
Description copied from interface:RichIterable
Returns true if the predicate evaluates to true for every element of the collection, or returns false.- Specified by:
allSatisfyWith
in interfaceRichIterable<T>
- Overrides:
allSatisfyWith
in classAbstractRichIterable<T>
-
noneSatisfyWith
Description copied from interface:RichIterable
Returns true if the predicate evaluates to false for every element of the collection, or return false. Returns true if the collection is empty.- Specified by:
noneSatisfyWith
in interfaceRichIterable<T>
- Overrides:
noneSatisfyWith
in classAbstractRichIterable<T>
-
injectInto
Description copied from interface:RichIterable
Returns the final result of evaluating function using each element of the iterable and the previous evaluation result as the parameters. The injected value is used for the first parameter of the first evaluation, and the current item in the iterable is used as the second parameter. This method is commonly called fold or sometimes reduce.- Specified by:
injectInto
in interfaceRichIterable<T>
- Overrides:
injectInto
in classAbstractBag<T>
-
toList
Description copied from interface:RichIterable
Converts the collection to a MutableList implementation.- Specified by:
toList
in interfaceRichIterable<T>
- Overrides:
toList
in classAbstractBag<T>
-
toSortedList
Description copied from interface:RichIterable
Converts the collection to a MutableList implementation and sorts it using the natural order of the elements.- Specified by:
toSortedList
in interfaceRichIterable<T>
-
toSortedList
Description copied from interface:RichIterable
Converts the collection to a MutableList implementation and sorts it using the specified comparator.- Specified by:
toSortedList
in interfaceRichIterable<T>
- Overrides:
toSortedList
in classAbstractBag<T>
-
toSet
Description copied from interface:RichIterable
Converts the collection to a MutableSet implementation.- Specified by:
toSet
in interfaceRichIterable<T>
- Overrides:
toSet
in classAbstractBag<T>
-
toBag
Description copied from interface:RichIterable
Converts the collection to the default MutableBag implementation.- Specified by:
toBag
in interfaceRichIterable<T>
- Overrides:
toBag
in classAbstractBag<T>
-
toSortedBag
Description copied from interface:RichIterable
Converts the collection to a MutableSortedBag implementation and sorts it using the natural order of the elements.- Specified by:
toSortedBag
in interfaceRichIterable<T>
- Overrides:
toSortedBag
in classAbstractBag<T>
-
toSortedBag
Description copied from interface:RichIterable
Converts the collection to the MutableSortedBag implementation and sorts it using the specified comparator.- Specified by:
toSortedBag
in interfaceRichIterable<T>
- Overrides:
toSortedBag
in classAbstractBag<T>
-
toMap
public <NK,NV> MutableMap<NK,NV> toMap(Function<? super T, ? extends NK> keyFunction, Function<? super T, ? extends NV> valueFunction) Description copied from interface:RichIterable
Converts the collection to a MutableMap implementation using the specified key and value functions.- Specified by:
toMap
in interfaceRichIterable<T>
- Overrides:
toMap
in classAbstractRichIterable<T>
-
toMap
public <NK,NV, R toMapR extends Map<NK, NV>> (Function<? super T, ? extends NK> keyFunction, Function<? super T, ? extends NV> valueFunction, R target) Description copied from interface:RichIterable
Same asRichIterable.toMap(Function, Function)
, except that the results are gathered into the specifiedtarget
map.- Specified by:
toMap
in interfaceRichIterable<T>
-
toSortedMap
public <NK,NV> MutableSortedMap<NK,NV> toSortedMap(Function<? super T, ? extends NK> keyFunction, Function<? super T, ? extends NV> valueFunction) Description copied from interface:RichIterable
Converts the collection to a MutableSortedMap implementation using the specified key and value functions sorted by the key elements' natural ordering.- Specified by:
toSortedMap
in interfaceRichIterable<T>
- Overrides:
toSortedMap
in classAbstractRichIterable<T>
-
toSortedMap
public <NK,NV> MutableSortedMap<NK,NV> toSortedMap(Comparator<? super NK> comparator, Function<? super T, ? extends NK> keyFunction, Function<? super T, ? extends NV> valueFunction) Description copied from interface:RichIterable
Converts the collection to a MutableSortedMap implementation using the specified key and value functions sorted by the given comparator.- Specified by:
toSortedMap
in interfaceRichIterable<T>
- Overrides:
toSortedMap
in classAbstractRichIterable<T>
-
asLazy
Description copied from interface:RichIterable
Returns a lazy (deferred) iterable, most likely implemented by calling LazyIterate.adapt(this).- Specified by:
asLazy
in interfaceRichIterable<T>
- Overrides:
asLazy
in classAbstractRichIterable<T>
-
toArray
Description copied from interface:RichIterable
Converts this iterable to an array.- Specified by:
toArray
in interfaceCollection<T>
- Specified by:
toArray
in interfaceRichIterable<T>
- Overrides:
toArray
in classAbstractRichIterable<T>
- See Also:
-
toArray
public <T> T[] toArray(T[] a) Description copied from interface:RichIterable
Converts this iterable to an array using the specified target array, assuming the target array is as long or longer than the iterable.- Specified by:
toArray
in interfaceCollection<T>
- Specified by:
toArray
in interfaceRichIterable<T>
- Overrides:
toArray
in classAbstractRichIterable<T>
- See Also:
-
min
Description copied from interface:RichIterable
Returns the minimum element out of this container based on the comparator.- Specified by:
min
in interfaceRichIterable<T>
- Overrides:
min
in classAbstractRichIterable<T>
-
max
Description copied from interface:RichIterable
Returns the maximum element out of this container based on the comparator.- Specified by:
max
in interfaceRichIterable<T>
- Overrides:
max
in classAbstractRichIterable<T>
-
min
Description copied from interface:RichIterable
Returns the minimum element out of this container based on the natural order.- Specified by:
min
in interfaceRichIterable<T>
- Overrides:
min
in classAbstractRichIterable<T>
-
max
Description copied from interface:RichIterable
Returns the maximum element out of this container based on the natural order.- Specified by:
max
in interfaceRichIterable<T>
- Overrides:
max
in classAbstractRichIterable<T>
-
minBy
Description copied from interface:RichIterable
Returns the minimum elements out of this container based on the natural order of the attribute returned by Function.- Specified by:
minBy
in interfaceRichIterable<T>
- Overrides:
minBy
in classAbstractRichIterable<T>
-
maxBy
Description copied from interface:RichIterable
Returns the maximum elements out of this container based on the natural order of the attribute returned by Function.- Specified by:
maxBy
in interfaceRichIterable<T>
- Overrides:
maxBy
in classAbstractRichIterable<T>
-
toString
Description copied from class:AbstractRichIterable
Returns a string with the elements of the iterable separated by commas with spaces and enclosed in square brackets.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());
- Specified by:
toString
in interfaceRichIterable<T>
- Overrides:
toString
in classAbstractRichIterable<T>
- Returns:
- a string representation of this collection.
- See Also:
-
makeString
Description copied from interface:RichIterable
Returns a string representation of this collection by delegating toRichIterable.makeString(String)
and defaulting the separator parameter to the characters", "
(comma and space).- Specified by:
makeString
in interfaceRichIterable<T>
- Returns:
- a string representation of this collection.
-
makeString
Description copied from interface:RichIterable
Returns a string representation of this collection by delegating toRichIterable.makeString(String, String, String)
and defaulting the start and end parameters to""
(the empty String).- Specified by:
makeString
in interfaceRichIterable<T>
- Returns:
- a string representation of this collection.
-
makeString
Description copied from interface:RichIterable
Returns a string representation of this collection with the elements separated by the specified separator and enclosed between the start and end strings.- Specified by:
makeString
in interfaceRichIterable<T>
- Returns:
- a string representation of this collection.
-
appendString
Description copied from interface:RichIterable
Prints a string representation of this collection onto the givenAppendable
. Prints the string returned byRichIterable.makeString()
.- Specified by:
appendString
in interfaceRichIterable<T>
-
appendString
Description copied from interface:RichIterable
Prints a string representation of this collection onto the givenAppendable
. Prints the string returned byRichIterable.makeString(String)
.- Specified by:
appendString
in interfaceRichIterable<T>
- Overrides:
appendString
in classAbstractRichIterable<T>
-
appendString
Description copied from interface:RichIterable
Prints a string representation of this collection onto the givenAppendable
. Prints the string returned byRichIterable.makeString(String, String, String)
.- Specified by:
appendString
in interfaceRichIterable<T>
- Overrides:
appendString
in classAbstractRichIterable<T>
-
zip
Deprecated.in 6.0. UseOrderedIterable.zip(Iterable)
instead.Description copied from interface:RichIterable
Returns aRichIterable
formed from thisRichIterable
and anotherRichIterable
by combining corresponding elements in pairs. If one of the twoRichIterable
s is longer than the other, its remaining elements are ignored.- Specified by:
zip
in interfaceImmutableBag<T>
- Specified by:
zip
in interfaceImmutableCollection<T>
- Specified by:
zip
in interfaceRichIterable<T>
- Specified by:
zip
in interfaceUnsortedBag<T>
- Type Parameters:
S
- the type of the second half of the returned pairs- Parameters:
that
- TheRichIterable
providing the second half of each result pair- Returns:
- A new
RichIterable
containing pairs consisting of corresponding elements of thisRichIterable
and that. The length of the returnedRichIterable
is the minimum of the lengths of thisRichIterable
and that.
-
zipWithIndex
Deprecated.in 6.0. UseOrderedIterable.zipWithIndex()
instead.Description copied from interface:RichIterable
Zips thisRichIterable
with its indices.- Specified by:
zipWithIndex
in interfaceBag<T>
- Specified by:
zipWithIndex
in interfaceImmutableBag<T>
- Specified by:
zipWithIndex
in interfaceImmutableBagIterable<T>
- Specified by:
zipWithIndex
in interfaceImmutableCollection<T>
- Specified by:
zipWithIndex
in interfaceRichIterable<T>
- Specified by:
zipWithIndex
in interfaceUnsortedBag<T>
- Returns:
- A new
RichIterable
containing pairs consisting of all elements of thisRichIterable
paired with their index. Indices start at 0. - See Also:
-
chunk
Description copied from interface:RichIterable
Partitions elements in fixed size chunks.- Specified by:
chunk
in interfaceRichIterable<T>
- Overrides:
chunk
in classAbstractImmutableBag<T>
- Parameters:
size
- the number of elements per chunk- Returns:
- A
RichIterable
containingRichIterable
s of sizesize
, except the last will be truncated if the elements don't divide evenly.
-
writeReplace
-
selectUnique
Description copied from interface:Bag
Returns a set containing all elements of the bag that have exactly one occurrence.- Specified by:
selectUnique
in interfaceBag<T>
- Specified by:
selectUnique
in interfaceImmutableBag<T>
- Specified by:
selectUnique
in interfaceImmutableBagIterable<T>
- Specified by:
selectUnique
in interfaceUnsortedBag<T>
-
distinctView
Description copied from interface:Bag
Returns an unmodifiable view on the distinct elements with the same complexity as the Bag implementation.- Specified by:
distinctView
in interfaceBag<T>
- Returns:
- an unmodifiable view on the distinct elements of the Bag.
-