Class ImmutableEmptySortedBag<T>
- All Implemented Interfaces:
Serializable
,Comparable<SortedBag<T>>
,Iterable<T>
,Collection<T>
,Bag<T>
,ImmutableBagIterable<T>
,ImmutableSortedBag<T>
,SortedBag<T>
,ImmutableCollection<T>
,InternalIterable<T>
,OrderedIterable<T>
,ReversibleIterable<T>
,SortedIterable<T>
,RichIterable<T>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Comparator
<? super T> (package private) static final ImmutableSortedBag
<?> private static final long
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
(package private)
ImmutableEmptySortedBag
(Comparator<? super T> comparator) -
Method Summary
Modifier and TypeMethodDescriptionboolean
allSatisfyWithOccurrences
(ObjectIntPredicate<? super T> predicate) Returns true if the predicate evaluates to true for all elements of the Bag.boolean
anySatisfyWithOccurrences
(ObjectIntPredicate<? super T> predicate) Returns true if the predicate evaluates to true for any element of the Bag.chunk
(int size) Partitions elements in fixed size chunks.<V> ImmutableList
<V> Returns a new collection with the results of applying the specified function on each element of the source collection.<V> ImmutableList
<V> collectWithIndex
(ObjectIntToObjectFunction<? super T, ? extends V> function) Returns a new OrderedIterable using results obtained by applying the specified function to each element and its corresponding index.<V,
R extends Collection<V>>
RcollectWithIndex
(ObjectIntToObjectFunction<? super T, ? extends V> function, R target) Adds elements to the target Collection using results obtained by applying the specified function to each element and its corresponding index.<V> ImmutableList
<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.Comparator
<? super T> Returns the comparator used to order the elements in this bag, or null if this bag uses the natural ordering of its elements.int
boolean
Returns true if the iterable has an element which responds true to element.equals(object).<S> boolean
corresponds
(OrderedIterable<S> other, Predicate2<? super T, ? super S> predicate) Returns true if both OrderedIterables have the same length andpredicate
returns true for all corresponding elements e1 of thisOrderedIterable
and e2 ofother
.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.int
detectIndex
(Predicate<? super T> predicate) Returns the index of the first element of theOrderedIterable
for which thepredicate
evaluates to true.detectWithOccurrences
(ObjectIntPredicate<? super T> predicate) Returns an element of the Bag that satisfies the predicate or null if such an element does not existdistinct()
Returns a newSortedIterable
containing the distinct elements in this iterable.Returns an unmodifiable view on the distinct elements with the same complexity as the Bag implementation.drop
(int count) Returns an iterable after skipping the firstcount
elements or an empty iterable if thecount
is greater than the length of the iterable.Returns the final elements that do not satisfy the Predicate.void
The procedure is executed for each element in the iterable.boolean
Two bagsb1
andb2
are equal ifm1.toMapOfItemToCount().equals(m2.toMapOfItemToCount())
.void
Iterates over the section of the iterable covered by the specified inclusive indexes.<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
(int fromIndex, int toIndex, ObjectIntProcedure<? super T> objectIntProcedure) Iterates over the section of the iterable covered by the specified inclusive indexes.void
forEachWithOccurrences
(ObjectIntProcedure<? super T> procedure) 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> ImmutableSortedBagMultimap
<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> ImmutableSortedBagMultimap
<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().int
Returns the index of the first occurrence of the specified item in this iterable, or -1 if this iterable does not contain the item.iterator()
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.newWithoutAll
(Iterable<? extends T> elements) This method is similar to thewithoutAll
method inMutableCollection
with the difference that a new copy of this collection with the elements removed will be returned.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.int
occurrencesOf
(Object item) The occurrences of a distinct item in the bag.partitionWhile
(Predicate<? super T> predicate) Returns a Partition of the initial elements that satisfy the Predicate and the remaining elements.Returns all elements of the source collection that return false when evaluating of the predicate.<P> ImmutableSortedBag
<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> ImmutableSortedBag
<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> ImmutableSortedBag
<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.take
(int count) Returns the firstcount
elements of the iterable or all the elements in the iterable ifcount
is greater than the length of the iterable.Returns the initial elements that satisfy the Predicate.Executes the Procedure for each element in the iterable and returnsthis
.Converts the Bag to a Map of the Item type to its count as an Integer.toStack()
Converts the OrderedIterable to a mutable MutableStack implementation.Zips thisRichIterable
with its indices.Methods inherited from class org.eclipse.collections.impl.bag.sorted.immutable.AbstractImmutableSortedBag
asReversed, bottomOccurrences, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, detectLastIndex, flatCollect, partition, partitionWith, toImmutable, topOccurrences, toReversed, writeReplace, zip, zip
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, injectInto, injectIntoWith, occurrencesSortingBy, reject, rejectWith, select, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toBag, toList, toListWithOccurrences, toSet, toSortedBag, toSortedBag, toSortedList, toSortedSet, toSortedSet, toStringOfItemToCount
Methods inherited from class org.eclipse.collections.impl.AbstractRichIterable
allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, asLazy, containsAll, containsAllArguments, containsAllIterable, countWith, detect, detectOptional, detectWith, detectWithIfNone, detectWithOptional, forEach, forEachWithIndex, groupByUniqueKey, into, isEmpty, noneSatisfy, noneSatisfyWith, toArray, toArray, toBiMap, toMap, toSortedBagBy, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSetBy, toString, 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, collectWithOccurrences, reduceInPlace, reduceInPlace, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, toStringOfItemToCount
Methods inherited from interface java.util.Collection
containsAll, isEmpty, removeIf, toArray, toArray, toArray
Methods inherited from interface org.eclipse.collections.api.collection.ImmutableCollection
aggregateBy, aggregateInPlaceBy, castToCollection, parallelStream, spliterator, stream, sumByDouble, sumByFloat, sumByInt, sumByLong
Methods inherited from interface org.eclipse.collections.api.bag.sorted.ImmutableSortedBag
flatCollectWith, selectDuplicates, toImmutableSortedBag
Methods inherited from interface org.eclipse.collections.api.InternalIterable
forEach
Methods inherited from interface org.eclipse.collections.api.ordered.OrderedIterable
forEachWithIndex, getFirstOptional, getLastOptional, rejectWithIndex, selectWithIndex, zipWithIndex
Methods inherited from interface org.eclipse.collections.api.ordered.ReversibleIterable
reverseForEach, reverseForEachWithIndex
Methods inherited from interface org.eclipse.collections.api.RichIterable
allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, appendString, asLazy, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, containsAll, containsAllArguments, containsAllIterable, containsAny, containsAnyIterable, containsBy, containsNone, containsNoneIterable, countWith, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, flatCollectWith, forEach, getAny, groupBy, groupByAndCollect, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, injectIntoDouble, injectIntoFloat, injectIntoInt, injectIntoLong, into, isEmpty, makeString, makeString, makeString, makeString, maxByOptional, maxOptional, maxOptional, minByOptional, minOptional, minOptional, noneSatisfy, noneSatisfyWith, notEmpty, reduce, reject, rejectWith, select, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toBiMap, toImmutableBag, toImmutableBiMap, toImmutableList, toImmutableMap, toImmutableSet, toImmutableSortedBag, toImmutableSortedBagBy, toImmutableSortedList, toImmutableSortedList, toImmutableSortedListBy, toImmutableSortedSet, toImmutableSortedSet, toImmutableSortedSetBy, toList, toMap, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, toString
-
Field Details
-
INSTANCE
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
comparator
-
-
Constructor Details
-
ImmutableEmptySortedBag
private ImmutableEmptySortedBag() -
ImmutableEmptySortedBag
ImmutableEmptySortedBag(Comparator<? super T> comparator)
-
-
Method Details
-
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 interfaceImmutableCollection<T>
- Specified by:
newWith
in interfaceImmutableSortedBag<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 interfaceImmutableCollection<T>
- Specified by:
newWithAll
in interfaceImmutableSortedBag<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 interfaceImmutableCollection<T>
- Specified by:
newWithout
in interfaceImmutableSortedBag<T>
-
newWithoutAll
Description copied from interface:ImmutableCollection
This method is similar to thewithoutAll
method inMutableCollection
with the difference that a new copy of this collection with the elements removed will be returned.- Specified by:
newWithoutAll
in interfaceImmutableCollection<T>
- Specified by:
newWithoutAll
in interfaceImmutableSortedBag<T>
- Overrides:
newWithoutAll
in classAbstractImmutableSortedBag<T>
-
equals
Description copied from interface:Bag
Two bagsb1
andb2
are equal ifm1.toMapOfItemToCount().equals(m2.toMapOfItemToCount())
. -
hashCode
public int hashCode()Description copied from interface:Bag
Returns the hash code for this Bag, defined as this.Bag.toMapOfItemToCount()
.hashCode(). -
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>
-
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>
-
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 interfaceImmutableCollection<T>
- Specified by:
collect
in interfaceImmutableSortedBag<T>
- Specified by:
collect
in interfaceOrderedIterable<T>
- Specified by:
collect
in interfaceReversibleIterable<T>
- Specified by:
collect
in interfaceRichIterable<T>
- Specified by:
collect
in interfaceSortedBag<T>
- Overrides:
collect
in classAbstractImmutableSortedBag<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 interfaceImmutableBagIterable<T>
- Specified by:
select
in interfaceImmutableCollection<T>
- Specified by:
select
in interfaceImmutableSortedBag<T>
- Specified by:
select
in interfaceOrderedIterable<T>
- Specified by:
select
in interfaceReversibleIterable<T>
- Specified by:
select
in interfaceRichIterable<T>
- Specified by:
select
in interfaceSortedBag<T>
- Specified by:
select
in interfaceSortedIterable<T>
- Overrides:
select
in classAbstractImmutableSortedBag<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 interfaceImmutableBagIterable<T>
- Specified by:
reject
in interfaceImmutableCollection<T>
- Specified by:
reject
in interfaceImmutableSortedBag<T>
- Specified by:
reject
in interfaceOrderedIterable<T>
- Specified by:
reject
in interfaceReversibleIterable<T>
- Specified by:
reject
in interfaceRichIterable<T>
- Specified by:
reject
in interfaceSortedBag<T>
- Specified by:
reject
in interfaceSortedIterable<T>
- Overrides:
reject
in classAbstractImmutableSortedBag<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
-
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 interfaceImmutableBagIterable<T>
- Specified by:
selectWith
in interfaceImmutableCollection<T>
- Specified by:
selectWith
in interfaceImmutableSortedBag<T>
- Specified by:
selectWith
in interfaceOrderedIterable<T>
- Specified by:
selectWith
in interfaceReversibleIterable<T>
- Specified by:
selectWith
in interfaceRichIterable<T>
- Specified by:
selectWith
in interfaceSortedBag<T>
- Specified by:
selectWith
in interfaceSortedIterable<T>
- Overrides:
selectWith
in classAbstractImmutableSortedBag<T>
- Parameters:
predicate
- aPredicate2
to use as the select criteriaparameter
- a parameter to pass in for evaluation of the second argumentP
inpredicate
- See Also:
-
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 interfaceImmutableBagIterable<T>
- Specified by:
rejectWith
in interfaceImmutableCollection<T>
- Specified by:
rejectWith
in interfaceImmutableSortedBag<T>
- Specified by:
rejectWith
in interfaceOrderedIterable<T>
- Specified by:
rejectWith
in interfaceReversibleIterable<T>
- Specified by:
rejectWith
in interfaceRichIterable<T>
- Specified by:
rejectWith
in interfaceSortedBag<T>
- Specified by:
rejectWith
in interfaceSortedIterable<T>
- Overrides:
rejectWith
in classAbstractImmutableSortedBag<T>
- Parameters:
predicate
- aPredicate2
to use as the select criteriaparameter
- a parameter to pass in for evaluation of the second argumentP
inpredicate
- See Also:
-
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 interfaceImmutableBagIterable<T>
- Specified by:
selectInstancesOf
in interfaceImmutableCollection<T>
- Specified by:
selectInstancesOf
in interfaceImmutableSortedBag<T>
- Specified by:
selectInstancesOf
in interfaceOrderedIterable<T>
- Specified by:
selectInstancesOf
in interfaceReversibleIterable<T>
- Specified by:
selectInstancesOf
in interfaceRichIterable<T>
- Specified by:
selectInstancesOf
in interfaceSortedBag<T>
- Specified by:
selectInstancesOf
in interfaceSortedIterable<T>
- Overrides:
selectInstancesOf
in classAbstractImmutableSortedBag<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 interfaceImmutableBagIterable<T>
- Specified by:
groupBy
in interfaceImmutableCollection<T>
- Specified by:
groupBy
in interfaceImmutableSortedBag<T>
- Specified by:
groupBy
in interfaceOrderedIterable<T>
- Specified by:
groupBy
in interfaceReversibleIterable<T>
- Specified by:
groupBy
in interfaceRichIterable<T>
- Specified by:
groupBy
in interfaceSortedBag<T>
- Specified by:
groupBy
in interfaceSortedIterable<T>
- Overrides:
groupBy
in classAbstractImmutableSortedBag<T>
-
groupByEach
public <V> ImmutableSortedBagMultimap<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 interfaceImmutableBagIterable<T>
- Specified by:
groupByEach
in interfaceImmutableCollection<T>
- Specified by:
groupByEach
in interfaceImmutableSortedBag<T>
- Specified by:
groupByEach
in interfaceOrderedIterable<T>
- Specified by:
groupByEach
in interfaceReversibleIterable<T>
- Specified by:
groupByEach
in interfaceRichIterable<T>
- Specified by:
groupByEach
in interfaceSortedBag<T>
- Specified by:
groupByEach
in interfaceSortedIterable<T>
- Overrides:
groupByEach
in classAbstractImmutableSortedBag<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 classAbstractImmutableSortedBag<T>
- See Also:
-
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>
-
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 interfaceImmutableBagIterable<T>
- Specified by:
tap
in interfaceImmutableCollection<T>
- Specified by:
tap
in interfaceImmutableSortedBag<T>
- Specified by:
tap
in interfaceOrderedIterable<T>
- Specified by:
tap
in interfaceReversibleIterable<T>
- Specified by:
tap
in interfaceRichIterable<T>
- Specified by:
tap
in interfaceSortedBag<T>
- Specified by:
tap
in interfaceSortedIterable<T>
- Overrides:
tap
in classAbstractImmutableSortedBag<T>
- See Also:
-
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 interfaceImmutableCollection<T>
- Specified by:
countBy
in interfaceImmutableSortedBag<T>
- Specified by:
countBy
in interfaceRichIterable<T>
- Overrides:
countBy
in classAbstractImmutableSortedBag<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 interfaceImmutableCollection<T>
- Specified by:
countByWith
in interfaceImmutableSortedBag<T>
- Specified by:
countByWith
in interfaceRichIterable<T>
- Overrides:
countByWith
in classAbstractImmutableSortedBag<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 interfaceImmutableCollection<T>
- Specified by:
countByEach
in interfaceImmutableSortedBag<T>
- Specified by:
countByEach
in interfaceRichIterable<T>
- Overrides:
countByEach
in classAbstractImmutableSortedBag<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
-
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 interfaceImmutableBagIterable<T>
- Specified by:
selectByOccurrences
in interfaceImmutableSortedBag<T>
- Specified by:
selectByOccurrences
in interfaceSortedBag<T>
- Overrides:
selectByOccurrences
in classAbstractImmutableSortedBag<T>
-
corresponds
Description copied from interface:OrderedIterable
Returns true if both OrderedIterables have the same length andpredicate
returns true for all corresponding elements e1 of thisOrderedIterable
and e2 ofother
. Thepredicate
is evaluated for each element at the same position of eachOrderedIterable
in a forward iteration order. This is a short circuit pattern.- Specified by:
corresponds
in interfaceOrderedIterable<T>
-
forEach
Description copied from interface:OrderedIterable
Iterates over the section of the iterable covered by the specified inclusive indexes. The indexes are both inclusive.e.g. OrderedIterable<People> people = FastList.newListWith(ted, mary, bob, sally) people.forEach(0, 1, new Procedure<Person>() { public void value(Person person) { LOGGER.info(person.getName()); } });
This code would output ted and mary's names.
- Specified by:
forEach
in interfaceOrderedIterable<T>
-
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
public void forEachWithIndex(int fromIndex, int toIndex, ObjectIntProcedure<? super T> objectIntProcedure) Description copied from interface:OrderedIterable
Iterates over the section of the iterable covered by the specified inclusive indexes. The indexes are both inclusive.e.g. OrderedIterable<People> people = FastList.newListWith(ted, mary, bob, sally) people.forEachWithIndex(0, 1, new ObjectIntProcedure<Person>() { public void value(Person person, int index) { LOGGER.info(person.getName()); } });
This code would output ted and mary's names.
- Specified by:
forEachWithIndex
in interfaceOrderedIterable<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>
-
occurrencesOf
Description copied from interface:Bag
The occurrences of a distinct item in the bag.- Specified by:
occurrencesOf
in interfaceBag<T>
-
iterator
-
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 interfaceOrderedIterable<T>
- Specified by:
min
in interfaceRichIterable<T>
- Specified by:
min
in interfaceSortedBag<T>
- Specified by:
min
in interfaceSortedIterable<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 interfaceOrderedIterable<T>
- Specified by:
max
in interfaceRichIterable<T>
- Specified by:
max
in interfaceSortedBag<T>
- Specified by:
max
in interfaceSortedIterable<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>
-
comparator
Description copied from interface:SortedBag
Returns the comparator used to order the elements in this bag, or null if this bag uses the natural ordering of its elements.- Specified by:
comparator
in interfaceSortedBag<T>
- Specified by:
comparator
in interfaceSortedIterable<T>
-
zipWithIndex
Description copied from interface:RichIterable
Zips thisRichIterable
with its indices.- Specified by:
zipWithIndex
in interfaceBag<T>
- Specified by:
zipWithIndex
in interfaceImmutableBagIterable<T>
- Specified by:
zipWithIndex
in interfaceImmutableCollection<T>
- Specified by:
zipWithIndex
in interfaceImmutableSortedBag<T>
- Specified by:
zipWithIndex
in interfaceOrderedIterable<T>
- Specified by:
zipWithIndex
in interfaceReversibleIterable<T>
- Specified by:
zipWithIndex
in interfaceRichIterable<T>
- Specified by:
zipWithIndex
in interfaceSortedBag<T>
- Specified by:
zipWithIndex
in interfaceSortedIterable<T>
- Overrides:
zipWithIndex
in classAbstractImmutableSortedBag<T>
- Returns:
- A new
RichIterable
containing pairs consisting of all elements of thisRichIterable
paired with their index. Indices start at 0. - See Also:
-
collectWithIndex
public <V> ImmutableList<V> collectWithIndex(ObjectIntToObjectFunction<? super T, ? extends V> function) Description copied from interface:OrderedIterable
Returns a new OrderedIterable using results obtained by applying the specified function to each element and its corresponding index.- Specified by:
collectWithIndex
in interfaceImmutableSortedBag<T>
- Specified by:
collectWithIndex
in interfaceOrderedIterable<T>
- Specified by:
collectWithIndex
in interfaceReversibleIterable<T>
- Specified by:
collectWithIndex
in interfaceSortedBag<T>
- Since:
- 9.1.
-
collectWithIndex
public <V,R extends Collection<V>> R collectWithIndex(ObjectIntToObjectFunction<? super T, ? extends V> function, R target) Description copied from interface:OrderedIterable
Adds elements to the target Collection using results obtained by applying the specified function to each element and its corresponding index.- Specified by:
collectWithIndex
in interfaceOrderedIterable<T>
- Since:
- 9.1.
-
collectWithOccurrences
public <V> ImmutableList<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 interfaceImmutableBagIterable<T>
- Specified by:
collectWithOccurrences
in interfaceImmutableSortedBag<T>
- Specified by:
collectWithOccurrences
in interfaceSortedBag<T>
- Overrides:
collectWithOccurrences
in classAbstractImmutableSortedBag<T>
-
partitionWhile
Description copied from interface:SortedIterable
Returns a Partition of the initial elements that satisfy the Predicate and the remaining elements. Short circuits at the first element which does satisfy the Predicate.- Specified by:
partitionWhile
in interfaceOrderedIterable<T>
- Specified by:
partitionWhile
in interfaceReversibleIterable<T>
- Specified by:
partitionWhile
in interfaceSortedBag<T>
- Specified by:
partitionWhile
in interfaceSortedIterable<T>
-
distinct
Description copied from interface:SortedIterable
Returns a newSortedIterable
containing the distinct elements in this iterable.Conceptually similar to
RichIterable.toSet()
.RichIterable.toList()
but retains the original order. If an element appears multiple times in this iterable, the first one will be copied into the result.- Specified by:
distinct
in interfaceImmutableSortedBag<T>
- Specified by:
distinct
in interfaceOrderedIterable<T>
- Specified by:
distinct
in interfaceReversibleIterable<T>
- Specified by:
distinct
in interfaceSortedBag<T>
- Specified by:
distinct
in interfaceSortedIterable<T>
- Returns:
SortedIterable
of distinct elements
-
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 interfaceOrderedIterable<T>
- 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 interfaceOrderedIterable<T>
- 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.
-
takeWhile
Description copied from interface:SortedIterable
Returns the initial elements that satisfy the Predicate. Short circuits at the first element which does not satisfy the Predicate.- Specified by:
takeWhile
in interfaceImmutableSortedBag<T>
- Specified by:
takeWhile
in interfaceOrderedIterable<T>
- Specified by:
takeWhile
in interfaceReversibleIterable<T>
- Specified by:
takeWhile
in interfaceSortedBag<T>
- Specified by:
takeWhile
in interfaceSortedIterable<T>
-
dropWhile
Description copied from interface:SortedIterable
Returns the final elements that do not satisfy the Predicate. Short circuits at the first element which does satisfy the Predicate.- Specified by:
dropWhile
in interfaceImmutableSortedBag<T>
- Specified by:
dropWhile
in interfaceOrderedIterable<T>
- Specified by:
dropWhile
in interfaceReversibleIterable<T>
- Specified by:
dropWhile
in interfaceSortedBag<T>
- Specified by:
dropWhile
in interfaceSortedIterable<T>
-
detectIndex
Description copied from interface:OrderedIterable
Returns the index of the first element of theOrderedIterable
for which thepredicate
evaluates to true. Returns -1 if no element evaluates true for thepredicate
.- Specified by:
detectIndex
in interfaceOrderedIterable<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>
-
toStack
Description copied from interface:OrderedIterable
Converts the OrderedIterable to a mutable MutableStack implementation.- Specified by:
toStack
in interfaceOrderedIterable<T>
- Overrides:
toStack
in classAbstractImmutableSortedBag<T>
-
indexOf
Description copied from interface:OrderedIterable
Returns the index of the first occurrence of the specified item in this iterable, or -1 if this iterable does not contain the item.- Specified by:
indexOf
in interfaceOrderedIterable<T>
- See Also:
-
compareTo
- Specified by:
compareTo
in interfaceComparable<T>
-
chunk
Description copied from interface:RichIterable
Partitions elements in fixed size chunks.- Specified by:
chunk
in interfaceRichIterable<T>
- Overrides:
chunk
in classAbstractImmutableSortedBag<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.
-
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>
- Specified by:
toMapOfItemToCount
in interfaceImmutableSortedBag<T>
- Specified by:
toMapOfItemToCount
in interfaceSortedBag<T>
-
take
Description copied from interface:ReversibleIterable
Returns the firstcount
elements of the iterable or all the elements in the iterable ifcount
is greater than the length of the iterable.- Specified by:
take
in interfaceImmutableSortedBag<T>
- Specified by:
take
in interfaceReversibleIterable<T>
- Specified by:
take
in interfaceSortedBag<T>
- Parameters:
count
- the number of items to take.
-
drop
Description copied from interface:ReversibleIterable
Returns an iterable after skipping the firstcount
elements or an empty iterable if thecount
is greater than the length of the iterable.- Specified by:
drop
in interfaceImmutableSortedBag<T>
- Specified by:
drop
in interfaceReversibleIterable<T>
- Specified by:
drop
in interfaceSortedBag<T>
- Parameters:
count
- the number of items to drop.
-
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 interfaceImmutableBagIterable<T>
- Specified by:
selectUnique
in interfaceImmutableSortedBag<T>
- Specified by:
selectUnique
in interfaceSortedBag<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.
-