Class ImmutableArrayBag<T>
- All Implemented Interfaces:
Serializable
,Iterable<T>
,Collection<T>
,Bag<T>
,ImmutableBag<T>
,ImmutableBagIterable<T>
,UnsortedBag<T>
,ImmutableCollection<T>
,InternalIterable<T>
,RichIterable<T>
public class ImmutableArrayBag<T> extends AbstractImmutableBag<T> implements Serializable
- Since:
- 1.0
- See Also:
- Serialized Form
-
Method Summary
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.<V> ImmutableBag<V>
collect(Function<? super T,? extends V> function)
Returns a new collection with the results of applying the specified function on each element of the source collection.<V> ImmutableBag<V>
collectIf(Predicate<? super T> predicate, Function<? super T,? extends V> function)
Returns a new collection with the results of applying the specified function on each element of the source collection, but only for those elements which return true upon evaluation of the predicate.static <T> ImmutableArrayBag<T>
copyFrom(Bag<? extends T> bag)
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.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> 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(Object other)
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)
.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> 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.int
hashCode()
Returns the hash code for this Bag, defined as this.Bag.toMapOfItemToCount()
.hashCode().Iterator<T>
iterator()
T
max()
Returns the maximum element out of this container based on the natural order.T
max(Comparator<? super T> comparator)
Returns the maximum element out of this container based on the comparator.<V extends Comparable<? super V>>
TmaxBy(Function<? super T,? extends V> function)
Returns the maximum elements out of this container based on the natural order of the attribute returned by Function.T
min()
Returns the minimum element out of this container based on the natural order.T
min(Comparator<? super T> comparator)
Returns the minimum element out of this container based on the comparator.<V extends Comparable<? super V>>
TminBy(Function<? super T,? extends V> function)
Returns the minimum elements out of this container based on the natural order of the attribute returned by Function.static <T> ImmutableArrayBag<T>
newBagWith(T... elements)
ImmutableBag<T>
newWith(T element)
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.ImmutableBag<T>
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.ImmutableBag<T>
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.int
occurrencesOf(Object item)
The occurrences of a distinct item in the bag.ImmutableBag<T>
reject(Predicate<? super T> predicate)
Returns all elements of the source collection that return false when evaluating of the predicate.ImmutableBag<T>
select(Predicate<? super T> predicate)
Returns all elements of the source collection that return true when evaluating the predicate.ImmutableBag<T>
selectByOccurrences(IntPredicate predicate)
Returns all elements of the bag that have a number of occurrences that satisfy the predicate.<S> ImmutableBag<S>
selectInstancesOf(Class<S> clazz)
Returns all elements of the source collection that are instances of the Classclazz
.int
size()
Returns the number of items in this iterable.int
sizeDistinct()
The size of the Bag when counting only distinct elements.MutableMap<T,Integer>
toMapOfItemToCount()
Converts the Bag to a Map of the Item type to its count as an Integer.<S> ImmutableBag<Pair<T,S>>
zip(Iterable<S> that)
Deprecated.in 6.0.ImmutableSet<Pair<T,Integer>>
zipWithIndex()
Deprecated.in 6.0.Methods inherited from class org.eclipse.collections.impl.bag.immutable.AbstractImmutableBag
bottomOccurrences, chunk, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectInt, collectLong, collectShort, collectWith, collectWithOccurrences, countBy, countByEach, countByWith, groupByUniqueKey, newWithoutAll, partition, partitionWith, rejectWith, selectWith, tap, toImmutable, topOccurrences
Methods inherited from class org.eclipse.collections.impl.bag.immutable.AbstractImmutableBagIterable
add, addAll, aggregateInPlaceBy, castToCollection, clear, parallelStream, remove, removeAll, retainAll, 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, count, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, groupBy, groupByEach, injectInto, injectInto, injectInto, injectInto, injectInto, injectIntoWith, reject, rejectWith, select, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toBag, toList, toSet, toSortedBag, toSortedBag, toSortedList, toSortedSet, toSortedSet, toStringOfItemToCount
Methods inherited from class org.eclipse.collections.impl.AbstractRichIterable
appendString, appendString, asLazy, contains, containsAll, containsAllArguments, containsAllIterable, countWith, detectWithIfNone, forEach, forEachWith, forEachWithIndex, groupByUniqueKey, into, isEmpty, toArray, toArray, toBiMap, toMap, toSortedBagBy, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSetBy, toString, zip, zipWithIndex
Methods inherited from interface org.eclipse.collections.api.bag.Bag
aggregateBy, collectWithOccurrences, reduceInPlace, reduceInPlace, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, toStringOfItemToCount
Methods inherited from interface java.util.Collection
contains, containsAll, isEmpty, removeIf, toArray, toArray, toArray
Methods inherited from interface org.eclipse.collections.api.bag.ImmutableBag
flatCollectWith, selectDuplicates, selectUnique
Methods inherited from interface org.eclipse.collections.api.bag.ImmutableBagIterable
selectDuplicates, selectUnique
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, forEachWith, forEachWithIndex
Methods inherited from interface org.eclipse.collections.api.RichIterable
appendString, appendString, appendString, asLazy, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, contains, containsAll, containsAllArguments, containsAllIterable, containsBy, count, countBy, countByEach, countByWith, countWith, detectIfNone, detectWithIfNone, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, flatCollectWith, forEach, getAny, groupBy, groupByAndCollect, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, into, isEmpty, makeString, makeString, makeString, maxByOptional, maxOptional, maxOptional, minByOptional, minOptional, minOptional, notEmpty, reduce, reject, rejectWith, select, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toBiMap, toList, toMap, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, toString, zip, zipWithIndex
-
Method Details
-
newBagWith
-
copyFrom
-
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>
-
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>
-
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>
-
occurrencesOf
Description copied from interface:Bag
The occurrences of a distinct item in the bag.- Specified by:
occurrencesOf
in interfaceBag<T>
-
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>
-
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>
-
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>
-
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>
-
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>
-
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.
-
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>
-
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
-
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>
-
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 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
-
equals
Description copied from interface:Bag
Two bagsb1
andb2
are equal ifm1.toMapOfItemToCount().equals(m2.toMapOfItemToCount())
.- Specified by:
equals
in interfaceBag<T>
- Specified by:
equals
in interfaceCollection<T>
- Overrides:
equals
in classObject
- See Also:
Map.equals(Object)
-
hashCode
public int hashCode()Description copied from interface:Bag
Returns the hash code for this Bag, defined as this.Bag.toMapOfItemToCount()
.hashCode().- Specified by:
hashCode
in interfaceBag<T>
- Specified by:
hashCode
in interfaceCollection<T>
- Overrides:
hashCode
in classObject
- See Also:
Map.hashCode()
-
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:
InternalIterable.forEach(Procedure)
,Iterable.forEach(java.util.function.Consumer)
-
iterator
-
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>
-
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>
-
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>
-
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>
-
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>
-
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>
-
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>
-
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>
-
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:
RichIterable.zip(Iterable)
-