Class ImmutableHashBag<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 ImmutableHashBag<T> extends AbstractImmutableBag<T> implements Serializable
- Since:
- 1.0
- See Also:
- Serialized Form
-
Constructor Summary
Constructors Constructor Description ImmutableHashBag()
ImmutableHashBag(Iterable<? extends T> source)
ImmutableHashBag(Bag<? extends T> source)
-
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.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
.LazyIterable<T>
asLazy()
Returns a lazy (deferred) iterable, most likely implemented by calling LazyIterate.adapt(this).<V> ImmutableBag<V>
collect(Function<? super T,? extends V> function)
Returns a new collection with the results of applying the specified function on each element of the source collection.<V, R extends Collection<V>>
Rcollect(Function<? super T,? extends V> function, R target)
Same asRichIterable.collect(Function)
, except that the results are gathered into the specifiedtarget
collection.<V> ImmutableBag<V>
collectIf(Predicate<? super T> predicate, Function<? super T,? extends V> function)
Returns a new collection with the results of applying the specified function on each element of the source collection, but only for those elements which return true upon evaluation of the predicate.<V, R extends Collection<V>>
RcollectIf(Predicate<? super T> predicate, Function<? super T,? extends V> function, R target)
Same as the collectIf method with two parameters but uses the specified target collection for the results.boolean
contains(Object object)
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
count(Predicate<? super T> predicate)
Return the total number of elements that answer true to the specified predicate.T
detect(Predicate<? super T> predicate)
Returns the first element of the iterable for which the predicate evaluates to true or null in the case where no element returns true.T
detectIfNone(Predicate<? super T> predicate, Function0<? extends T> function)
Returns the first element of the iterable for which the predicate evaluates to true.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 obj)
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)
.<V, R extends Collection<V>>
RflatCollect(Function<? super T,? extends Iterable<V>> function, R target)
Same as flatCollect, only the results are collected into the target collection.void
forEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure)
Iterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.void
forEachWithOccurrences(ObjectIntProcedure<? super T> objectIntProcedure)
For each distinct item, with the number of occurrences, execute the specified procedure.T
getFirst()
Returns the first element of an iterable.T
getLast()
Returns the last element of an iterable.T
getOnly()
Returns the element if the iterable has exactly one element.<V> ImmutableBagMultimap<V,T>
groupBy(Function<? super T,? extends V> function)
For each element of the iterable, the function is evaluated and the results of these evaluations are collected into a new multimap, where the transformed value is the key and the original values are added to the same (or similar) species of collection as the source iterable.<V, R extends MutableMultimap<V, T>>
RgroupBy(Function<? super T,? extends V> function, R target)
Same asRichIterable.groupBy(Function)
, except that the results are gathered into the specifiedtarget
multimap.<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, R extends MutableMultimap<V, T>>
RgroupByEach(Function<? super T,? extends Iterable<V>> function, R target)
Same asRichIterable.groupByEach(Function)
, except that the results are gathered into the specifiedtarget
multimap.<V> ImmutableMap<V,T>
groupByUniqueKey(Function<? super T,? extends V> function)
For each element of the iterable, the function is evaluated and he results of these evaluations are collected into a new map, where the transformed value is the key.int
hashCode()
Returns the hash code for this Bag, defined as this.Bag.toMapOfItemToCount()
.hashCode().double
injectInto(double injectedValue, DoubleObjectToDoubleFunction<? super T> function)
Returns the final double result of evaluating function using each element of the iterable and the previous evaluation result as the parameters.float
injectInto(float injectedValue, FloatObjectToFloatFunction<? super T> function)
Returns the final float result of evaluating function using each element of the iterable and the previous evaluation result as the parameters.int
injectInto(int injectedValue, IntObjectToIntFunction<? super T> function)
Returns the final int result of evaluating function using each element of the iterable and the previous evaluation result as the parameters.long
injectInto(long injectedValue, LongObjectToLongFunction<? super T> function)
Returns the final long result of evaluating function using each element of the iterable and the previous evaluation result as the parameters.<IV> IV
injectInto(IV injectedValue, Function2<? super IV,? super T,? extends IV> function)
Returns the final result of evaluating function using each element of the iterable and the previous evaluation result as the parameters.boolean
isEmpty()
Returns true if this iterable has zero items.Iterator<T>
iterator()
String
makeString()
Returns a string representation of this collection by delegating toRichIterable.makeString(String)
and defaulting the separator parameter to the characters", "
(comma and space).String
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).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.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> ImmutableHashBag<T>
newBag()
static <T> ImmutableHashBag<T>
newBag(Iterable<? extends T> source)
static <T> ImmutableHashBag<T>
newBagWith(Bag<? extends T> bag)
static <T> ImmutableHashBag<T>
newBagWith(T... elements)
ImmutableBag<T>
newWith(T element)
This method is similar to 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.boolean
notEmpty()
The English equivalent of !this.isEmpty()int
occurrencesOf(Object item)
The occurrences of a distinct item in the bag.PartitionImmutableBag<T>
partition(Predicate<? super T> predicate)
Filters a collection into a PartitionedIterable based on the evaluation of the predicate.ImmutableBag<T>
reject(Predicate<? super T> predicate)
Returns all elements of the source collection that return false when evaluating of the predicate.<R extends Collection<T>>
Rreject(Predicate<? super T> predicate, R target)
Same as the reject method with one parameter but uses the specified target collection for the results.ImmutableBag<T>
select(Predicate<? super T> predicate)
Returns all elements of the source collection that return true when evaluating the predicate.<R extends Collection<T>>
Rselect(Predicate<? super T> predicate, R target)
Same as the select method with one parameter but uses the specified target collection for the results.ImmutableBag<T>
selectByOccurrences(IntPredicate predicate)
Returns all elements of the bag that have a number of occurrences that satisfy the predicate.<S> ImmutableBag<S>
selectInstancesOf(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.Object[]
toArray()
Converts this iterable to an array.<T> T[]
toArray(T[] a)
Converts this iterable to an array using the specified target array, assuming the target array is as long or longer than the iterable.MutableBag<T>
toBag()
Converts the collection to the default MutableBag implementation.MutableList<T>
toList()
Converts the collection to a MutableList implementation.<K, V> MutableMap<K,V>
toMap(Function<? super T,? extends K> keyFunction, Function<? super T,? extends V> valueFunction)
Converts the collection to a MutableMap implementation using the specified key and value functions.<K, V, R extends Map<K, V>>
RtoMap(Function<? super T,? extends K> keyFunction, Function<? super T,? extends V> valueFunction, R target)
Same asRichIterable.toMap(Function, Function)
, except that the results are gathered into the specifiedtarget
map.MutableMap<T,Integer>
toMapOfItemToCount()
Converts the Bag to a Map of the Item type to its count as an Integer.MutableSet<T>
toSet()
Converts the collection to a MutableSet implementation.MutableSortedBag<T>
toSortedBag()
Converts the collection to a MutableSortedBag implementation and sorts it using the natural order of the elements.MutableSortedBag<T>
toSortedBag(Comparator<? super T> comparator)
Converts the collection to the MutableSortedBag implementation and sorts it using the specified comparator.<V extends Comparable<? super V>>
MutableSortedBag<T>toSortedBagBy(Function<? super T,? extends V> function)
Converts the collection to a MutableSortedBag implementation and sorts it based on the natural order of the attribute returned byfunction
.MutableList<T>
toSortedList()
Converts the collection to a MutableList implementation and sorts it using the natural order of the elements.MutableList<T>
toSortedList(Comparator<? super T> comparator)
Converts the collection to a MutableList implementation and sorts it using the specified comparator.<K, V> MutableSortedMap<K,V>
toSortedMap(Comparator<? super K> comparator, Function<? super T,? extends K> keyFunction, Function<? super T,? extends V> valueFunction)
Converts the collection to a MutableSortedMap implementation using the specified key and value functions sorted by the given comparator.<K, V> MutableSortedMap<K,V>
toSortedMap(Function<? super T,? extends K> keyFunction, Function<? super T,? extends V> valueFunction)
Converts the collection to a MutableSortedMap implementation using the specified key and value functions sorted by the key elements' natural ordering.<KK extends Comparable<? super KK>, K, V>
MutableSortedMap<K,V>toSortedMapBy(Function<? super K,KK> sortBy, Function<? super T,? extends K> keyFunction, Function<? super T,? extends V> valueFunction)
Converts the collection to a MutableSortedMap implementation using the specified key and value functions and sorts it based on the natural order of the attribute returned bysortBy
function.MutableSortedSet<T>
toSortedSet()
Converts the collection to a MutableSortedSet implementation and sorts it using the natural order of the elements.MutableSortedSet<T>
toSortedSet(Comparator<? super T> comparator)
Converts the collection to a MutableSortedSet implementation and sorts it using the specified comparator.String
toString()
Returns a string with the elements of the iterable separated by commas with spaces and enclosed in square brackets.<S> ImmutableBag<Pair<T,S>>
zip(Iterable<S> that)
Deprecated.in 6.0.<S, R extends Collection<Pair<T, S>>>
Rzip(Iterable<S> that, R target)
Same asRichIterable.zip(Iterable)
but usestarget
for output.ImmutableSet<Pair<T,Integer>>
zipWithIndex()
Deprecated.in 6.0.<R extends Collection<Pair<T, Integer>>>
RzipWithIndex(R target)
Same asRichIterable.zipWithIndex()
but usestarget
for output.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, newWithoutAll, 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
collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectInt, collectLong, collectShort, collectWith, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, injectIntoWith, rejectWith, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toStringOfItemToCount
Methods inherited from class org.eclipse.collections.impl.AbstractRichIterable
containsAll, countWith, detectWithIfNone, forEach, forEachWith, groupByUniqueKey, into, toBiMap, toSortedListBy, toSortedSetBy
Methods inherited from interface org.eclipse.collections.api.bag.Bag
aggregateBy, collectWithOccurrences, reduceInPlace, reduceInPlace, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, toStringOfItemToCount
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.RichIterable
collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectInt, collectLong, collectShort, collectWith, containsAll, containsBy, countBy, countByEach, countByWith, countWith, detectWithIfNone, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, flatCollectWith, forEach, getAny, groupByAndCollect, groupByUniqueKey, into, maxByOptional, maxOptional, maxOptional, minByOptional, minOptional, minOptional, reduce, rejectWith, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toBiMap, toSortedListBy, toSortedSetBy
-
Constructor Details
-
ImmutableHashBag
public ImmutableHashBag() -
ImmutableHashBag
-
ImmutableHashBag
-
-
Method Details
-
newBag
-
newBag
-
newBagWith
-
newBagWith
-
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>
-
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>
-
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>
-
groupBy
public <V, R extends MutableMultimap<V, T>> R groupBy(Function<? super T,? extends V> function, R target)Description copied from interface:RichIterable
Same asRichIterable.groupBy(Function)
, except that the results are gathered into the specifiedtarget
multimap.Example using a Java 8 method reference:
FastListMultimap<String, Person> peopleByLastName = people.groupBy(Person::getLastName, new FastListMultimap<String, Person>());
Example using an anonymous inner class:
FastListMultimap<String, Person> peopleByLastName = people.groupBy(new Function<Person, String>() { public String valueOf(Person person) { return person.getLastName(); } }, new FastListMultimap<String, Person>());
- Specified by:
groupBy
in interfaceRichIterable<T>
- Overrides:
groupBy
in classAbstractBag<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>
-
groupByEach
public <V, R extends MutableMultimap<V, T>> R groupByEach(Function<? super T,? extends Iterable<V>> function, R target)Description copied from interface:RichIterable
Same asRichIterable.groupByEach(Function)
, except that the results are gathered into the specifiedtarget
multimap.- Specified by:
groupByEach
in interfaceRichIterable<T>
- Overrides:
groupByEach
in classAbstractBag<T>
-
groupByUniqueKey
Description copied from interface:RichIterable
For each element of the iterable, the function is evaluated and he results of these evaluations are collected into a new map, where the transformed value is the key. 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:
RichIterable.groupBy(Function)
-
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>
-
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.
-
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>
-
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>
-
toMap
public <K, V> MutableMap<K,V> toMap(Function<? super T,? extends K> keyFunction, Function<? super T,? extends V> 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 <K, V, R extends Map<K, V>> R toMap(Function<? super T,? extends K> keyFunction, Function<? super T,? extends V> 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>
-
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)
-
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>
-
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>
-
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>
-
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>
-
occurrencesOf
Description copied from interface:Bag
The occurrences of a distinct item in the bag.- Specified by:
occurrencesOf
in interfaceBag<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>
-
toSortedSet
Description copied from interface:RichIterable
Converts the collection to a MutableSortedSet implementation and sorts it using the natural order of the elements.- Specified by:
toSortedSet
in interfaceRichIterable<T>
- Overrides:
toSortedSet
in classAbstractBag<T>
-
toSortedSet
Description copied from interface:RichIterable
Converts the collection to a MutableSortedSet implementation and sorts it using the specified comparator.- Specified by:
toSortedSet
in interfaceRichIterable<T>
- Overrides:
toSortedSet
in classAbstractBag<T>
-
toSortedMap
public <K, V> MutableSortedMap<K,V> toSortedMap(Function<? super T,? extends K> keyFunction, Function<? super T,? extends V> 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 <K, V> MutableSortedMap<K,V> toSortedMap(Comparator<? super K> comparator, Function<? super T,? extends K> keyFunction, Function<? super T,? extends V> 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>
-
toSortedMapBy
public <KK extends Comparable<? super KK>, K, V> MutableSortedMap<K,V> toSortedMapBy(Function<? super K,KK> sortBy, Function<? super T,? extends K> keyFunction, Function<? super T,? extends V> valueFunction)Description copied from interface:RichIterable
Converts the collection to a MutableSortedMap implementation using the specified key and value functions and sorts it based on the natural order of the attribute returned bysortBy
function.- Specified by:
toSortedMapBy
in interfaceRichIterable<T>
- Overrides:
toSortedMapBy
in classAbstractRichIterable<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>
-
select
Description copied from interface:RichIterable
Same as the select method with one parameter but uses the specified target collection for the results.Example using a Java 8 lambda expression:
MutableList<Person> selected = people.select(person -> person.person.getLastName().equals("Smith"), Lists.mutable.empty());
Example using an anonymous inner class:
MutableList<Person> selected = people.select(new Predicate<Person>() { public boolean accept(Person person) { return person.person.getLastName().equals("Smith"); } }, Lists.mutable.empty());
- Specified by:
select
in interfaceRichIterable<T>
- Overrides:
select
in classAbstractBag<T>
- Parameters:
predicate
- aPredicate
to use as the select criteriatarget
- the Collection to append to for all elements in thisRichIterable
that meet select criteriapredicate
- Returns:
target
, which contains appended elements as a result of the select criteria- See Also:
RichIterable.select(Predicate)
-
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
-
reject
Description copied from interface:RichIterable
Same as the reject method with one parameter but uses the specified target collection for the results.Example using a Java 8 lambda expression:
MutableList<Person> rejected = people.reject(person -> person.person.getLastName().equals("Smith"), Lists.mutable.empty());
Example using an anonymous inner class:
MutableList<Person> rejected = people.reject(new Predicate<Person>() { public boolean accept(Person person) { return person.person.getLastName().equals("Smith"); } }, Lists.mutable.empty());
- Specified by:
reject
in interfaceRichIterable<T>
- Overrides:
reject
in classAbstractBag<T>
- Parameters:
predicate
- aPredicate
to use as the reject criteriatarget
- the Collection to append to for all elements in thisRichIterable
that causePredicate#accept(Object)
method to evaluate to false- Returns:
target
, which contains appended elements as a result of the reject criteria
-
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>
-
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>
-
collect
public <V, R extends Collection<V>> R collect(Function<? super T,? extends V> function, R target)Description copied from interface:RichIterable
Same asRichIterable.collect(Function)
, except that the results are gathered into the specifiedtarget
collection.Example using a Java 8 lambda expression:
MutableList<String> names = people.collect(person -> person.getFirstName() + " " + person.getLastName(), Lists.mutable.empty());
Example using an anonymous inner class:
MutableList<String> names = people.collect(new Function<Person, String>() { public String valueOf(Person person) { return person.getFirstName() + " " + person.getLastName(); } }, Lists.mutable.empty());
- Specified by:
collect
in interfaceRichIterable<T>
- Overrides:
collect
in classAbstractBag<T>
- Parameters:
function
- aFunction
to use as the collect transformation functiontarget
- the Collection to append to for all elements in thisRichIterable
that meet select criteriafunction
- Returns:
target
, which contains appended elements as a result of the collect transformation- See Also:
RichIterable.collect(Function)
-
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>
-
collectIf
public <V, R extends Collection<V>> R collectIf(Predicate<? super T> predicate, Function<? super T,? extends V> function, R target)Description copied from interface:RichIterable
Same as the collectIf method with two parameters but uses the specified target collection for the results.- Specified by:
collectIf
in interfaceRichIterable<T>
- Overrides:
collectIf
in classAbstractBag<T>
- Parameters:
predicate
- aPredicate
to use as the select criteriafunction
- aFunction
to use as the collect transformation functiontarget
- the Collection to append to for all elements in thisRichIterable
that meet the collect criteriapredicate
- Returns:
targetCollection
, which contains appended elements as a result of the collect criteria and transformation- See Also:
RichIterable.collectIf(Predicate, Function)
-
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
-
flatCollect
public <V, R extends Collection<V>> R flatCollect(Function<? super T,? extends Iterable<V>> function, R target)Description copied from interface:RichIterable
Same as flatCollect, only the results are collected into the target collection.- Specified by:
flatCollect
in interfaceRichIterable<T>
- Overrides:
flatCollect
in classAbstractBag<T>
- Parameters:
function
- TheFunction
to applytarget
- The collection into which results should be added.- Returns:
target
, which will contain a flattened collection of results produced by applying the givenfunction
- See Also:
RichIterable.flatCollect(Function)
-
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>
-
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>
-
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>
-
injectInto
public <IV> IV injectInto(IV injectedValue, Function2<? super IV,? super T,? extends IV> function)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>
-
injectInto
Description copied from interface:RichIterable
Returns the final int 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.- Specified by:
injectInto
in interfaceRichIterable<T>
- Overrides:
injectInto
in classAbstractBag<T>
-
injectInto
Description copied from interface:RichIterable
Returns the final long 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.- Specified by:
injectInto
in interfaceRichIterable<T>
- Overrides:
injectInto
in classAbstractBag<T>
-
injectInto
Description copied from interface:RichIterable
Returns the final double 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.- Specified by:
injectInto
in interfaceRichIterable<T>
- Overrides:
injectInto
in classAbstractBag<T>
-
injectInto
Description copied from interface:RichIterable
Returns the final float 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.- Specified by:
injectInto
in interfaceRichIterable<T>
- Overrides:
injectInto
in classAbstractBag<T>
-
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()
-
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>
-
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>
-
toSortedBagBy
public <V extends Comparable<? super V>> MutableSortedBag<T> toSortedBagBy(Function<? super T,? extends V> function)Description copied from interface:RichIterable
Converts the collection to a MutableSortedBag implementation and sorts it based on the natural order of the attribute returned byfunction
.- Specified by:
toSortedBagBy
in interfaceRichIterable<T>
- Overrides:
toSortedBagBy
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:
Collection.toArray()
-
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:
Collection.toArray(Object[])
-
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:
AbstractCollection.toString()
-
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.
-
zip
Description copied from interface:RichIterable
Same asRichIterable.zip(Iterable)
but usestarget
for output.- Specified by:
zip
in interfaceRichIterable<T>
- Overrides:
zip
in classAbstractRichIterable<T>
-
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)
-
zipWithIndex
Description copied from interface:RichIterable
Same asRichIterable.zipWithIndex()
but usestarget
for output.- Specified by:
zipWithIndex
in interfaceRichIterable<T>
- Overrides:
zipWithIndex
in classAbstractRichIterable<T>
-
iterator
-