Class TreeBag<T>
java.lang.Object
org.eclipse.collections.impl.AbstractRichIterable<T>
org.eclipse.collections.impl.bag.AbstractBag<T>
org.eclipse.collections.impl.bag.mutable.AbstractMutableBagIterable<T>
org.eclipse.collections.impl.bag.sorted.mutable.AbstractMutableSortedBag<T>
org.eclipse.collections.impl.bag.sorted.mutable.TreeBag<T>
- All Implemented Interfaces:
Externalizable
,Serializable
,Cloneable
,Comparable<SortedBag<T>>
,Iterable<T>
,Collection<T>
,Bag<T>
,MutableBagIterable<T>
,MutableSortedBag<T>
,SortedBag<T>
,MutableCollection<T>
,InternalIterable<T>
,OrderedIterable<T>
,ReversibleIterable<T>
,SortedIterable<T>
,RichIterable<T>
public class TreeBag<T> extends AbstractMutableSortedBag<T> implements Externalizable
A TreeBag is a MutableSortedBag which uses a SortedMap as its underlying data store. Each key in the SortedMap represents some item,
and the value in the map represents the current number of occurrences of that item.
- Since:
- 4.2
- See Also:
- Serialized Form
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description boolean
add(T item)
int
addOccurrences(T item, int occurrences)
Add number ofoccurrences
for anitem
.void
clear()
TreeBag<T>
clone()
Comparator<? super T>
comparator()
Returns the comparator used to order the elements in this bag, or null if this bag uses the natural ordering of its elements.int
compareTo(SortedBag<T> otherBag)
boolean
contains(Object o)
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
detectIndex(Predicate<? super T> predicate)
Returns the index of the first element of theOrderedIterable
for which thepredicate
evaluates to true.MutableSortedSet<T>
distinct()
Returns a newSortedIterable
containing the distinct elements in this iterable.MutableSortedBag<T>
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.void
each(Procedure<? super T> procedure)
The procedure is executed for each element in the iterable.boolean
equals(Object other)
Two bagsb1
andb2
are equal ifm1.toMapOfItemToCount().equals(m2.toMapOfItemToCount())
.void
forEach(int fromIndex, int toIndex, Procedure<? super T> procedure)
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
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> procedure)
For each distinct item, with the number of occurrences, execute the specified procedure.<V> TreeBagMultimap<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> TreeBagMultimap<V,T>
groupByEach(Function<? super T,? extends Iterable<V>> function)
Similar toRichIterable.groupBy(Function)
, except the result of evaluating function will return a collection of keys for each value.int
hashCode()
Returns the hash code for this Bag, defined as this.Bag.toMapOfItemToCount()
.hashCode().int
indexOf(Object object)
Returns the index of the first occurrence of the specified item in this iterable, or -1 if this iterable does not contain the item.boolean
isEmpty()
Returns true if this iterable has zero items.Iterator<T>
iterator()
static <E> TreeBag<E>
newBag()
static <E> TreeBag<E>
newBag(Iterable<? extends E> source)
static <E> TreeBag<E>
newBag(Comparator<? super E> comparator)
static <E> TreeBag<E>
newBag(Comparator<? super E> comparator, Iterable<? extends E> iterable)
static <E> TreeBag<E>
newBagWith(E... elements)
static <E> TreeBag<E>
newBagWith(Comparator<? super E> comparator, E... elements)
MutableSortedBag<T>
newEmpty()
Creates a new empty mutable version of the same collection type.int
occurrencesOf(Object item)
The occurrences of a distinct item in the bag.void
readExternal(ObjectInput in)
boolean
remove(Object item)
boolean
removeAllIterable(Iterable<?> iterable)
boolean
removeIf(Predicate<? super T> predicate)
Removes all elements in the collection that evaluate to true for the specified predicate.<P> boolean
removeIfWith(Predicate2<? super T,? super P> predicate, P parameter)
Removes all elements in the collection that evaluate to true for the specified predicate2 and parameter.boolean
removeOccurrences(Object item, int occurrences)
MutableSortedBag<T>
selectByOccurrences(IntPredicate predicate)
Returns all elements of the bag that have a number of occurrences that satisfy the predicate.boolean
setOccurrences(T item, int occurrences)
int
size()
Returns the number of items in this iterable.int
sizeDistinct()
The size of the Bag when counting only distinct elements.MutableSortedBag<T>
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.MutableStack<T>
toStack()
Converts the OrderedIterable to a mutable MutableStack implementation.TreeBag<T>
with(T element)
This method allows mutable and fixed size collections the ability to add elements to their existing elements.TreeBag<T>
with(T... elements)
TreeBag<T>
with(T element1, T element2)
TreeBag<T>
with(T element1, T element2, T element3)
TreeBag<T>
withAll(Iterable<? extends T> iterable)
This method allows mutable and fixed size collections the ability to add multiple elements to their existing elements.TreeBag<T>
without(T element)
This method allows mutable and fixed size collections the ability to remove elements from their existing elements.TreeBag<T>
withoutAll(Iterable<? extends T> iterable)
This method allows mutable and fixed size collections the ability to remove multiple elements from their existing elements.void
writeExternal(ObjectOutput out)
MutableSortedSet<Pair<T,Integer>>
zipWithIndex()
Zips thisRichIterable
with its indices.Methods inherited from class org.eclipse.collections.impl.bag.sorted.mutable.AbstractMutableSortedBag
asParallel, asSynchronized, asUnmodifiable, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, collectWithIndex, collectWithIndex, collectWithOccurrences, countBy, countByEach, countByWith, detectLastIndex, dropWhile, flatCollect, partition, partitionWhile, partitionWith, reject, rejectWith, select, selectInstancesOf, selectWith, takeWhile, tap, toImmutable, toMapOfItemToCount, toReversed, zip
Methods inherited from class org.eclipse.collections.impl.bag.mutable.AbstractMutableBagIterable
addAll, addAllIterable, aggregateInPlaceBy, allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, bottomOccurrences, chunk, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, getFirst, getLast, groupByUniqueKey, max, max, maxBy, min, min, minBy, noneSatisfy, noneSatisfyWith, removeAll, retainAll, retainAllIterable, selectAndRejectWith, sumByDouble, sumByFloat, sumByInt, sumByLong, topOccurrences
Methods inherited from class org.eclipse.collections.impl.bag.AbstractBag
collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, count, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, groupBy, groupByEach, injectInto, injectInto, injectInto, injectInto, injectInto, injectIntoWith, reject, rejectWith, select, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toBag, toList, toSet, toSortedBag, toSortedBag, toSortedList, toSortedSet, toSortedSet, toStringOfItemToCount
Methods inherited from class org.eclipse.collections.impl.AbstractRichIterable
appendString, appendString, asLazy, containsAll, containsAllArguments, containsAllIterable, countWith, forEach, groupByUniqueKey, into, toArray, toArray, toBiMap, toMap, toSortedBagBy, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSetBy, toString, zip, zipWithIndex
Methods inherited from interface org.eclipse.collections.api.bag.Bag
aggregateBy, collectWithOccurrences, reduceInPlace, reduceInPlace, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, toStringOfItemToCount
Methods inherited from interface java.util.Collection
addAll, containsAll, parallelStream, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray, toArray
Methods inherited from interface org.eclipse.collections.api.bag.MutableBagIterable
bottomOccurrences, selectDuplicates, selectUnique, topOccurrences
Methods inherited from interface org.eclipse.collections.api.collection.MutableCollection
addAllIterable, aggregateBy, aggregateInPlaceBy, flatCollectWith, groupByUniqueKey, injectIntoWith, retainAllIterable, selectAndRejectWith, sumByDouble, sumByFloat, sumByInt, sumByLong
Methods inherited from interface org.eclipse.collections.api.bag.sorted.MutableSortedBag
flatCollectWith, selectDuplicates, selectUnique
Methods inherited from interface org.eclipse.collections.api.ordered.OrderedIterable
getFirst, getFirstOptional, getLast, getLastOptional, zip, zipWithIndex
Methods inherited from interface org.eclipse.collections.api.ordered.ReversibleIterable
asReversed, reverseForEach, reverseForEachWithIndex
Methods inherited from interface org.eclipse.collections.api.RichIterable
allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, appendString, asLazy, chunk, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, containsAll, containsAllArguments, containsAllIterable, containsBy, count, countBy, countByEach, countByWith, countWith, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, flatCollectWith, forEach, getAny, getOnly, groupBy, groupByAndCollect, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, into, makeString, makeString, makeString, max, maxBy, maxByOptional, maxOptional, maxOptional, min, minBy, minByOptional, minOptional, minOptional, noneSatisfy, noneSatisfyWith, notEmpty, reduce, reject, rejectWith, select, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toBiMap, toList, toMap, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, toString
-
Constructor Details
-
Method Details
-
newBag
-
newBag
-
newBag
-
newBag
public static <E> TreeBag<E> newBag(Comparator<? super E> comparator, Iterable<? extends E> iterable) -
newBagWith
-
newBagWith
-
clone
- Specified by:
clone
in interfaceMutableSortedBag<T>
- Specified by:
clone
in classAbstractMutableSortedBag<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()
-
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>
-
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>
-
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 interfaceMutableBagIterable<T>
- Specified by:
selectByOccurrences
in interfaceMutableSortedBag<T>
- Specified by:
selectByOccurrences
in interfaceSortedBag<T>
-
occurrencesOf
Description copied from interface:Bag
The occurrences of a distinct item in the bag.- Specified by:
occurrencesOf
in interfaceBag<T>
-
isEmpty
public boolean isEmpty()Description copied from interface:RichIterable
Returns true if this iterable has zero items.- Specified by:
isEmpty
in interfaceCollection<T>
- Specified by:
isEmpty
in interfaceRichIterable<T>
- Overrides:
isEmpty
in classAbstractRichIterable<T>
-
remove
- Specified by:
remove
in interfaceCollection<T>
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<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>
-
compareTo
- Specified by:
compareTo
in interfaceComparable<T>
-
writeExternal
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readExternal
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-
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>
- Specified by:
forEachWithIndex
in interfaceOrderedIterable<T>
- Overrides:
forEachWithIndex
in classAbstractRichIterable<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>
-
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>
-
iterator
-
addOccurrences
Description copied from interface:MutableBagIterable
Add number ofoccurrences
for anitem
. If theitem
does not exist, then theitem
is added to the bag.For Example:
MutableBagIterable<String> names = Bags.mutable.of("A", "B", "B"); Assert.assertEquals(4, names.addOccurrences("A", 3));
- Specified by:
addOccurrences
in interfaceMutableBagIterable<T>
- Returns:
- updated number of occurrences.
-
removeOccurrences
- Specified by:
removeOccurrences
in interfaceMutableBagIterable<T>
-
setOccurrences
- Specified by:
setOccurrences
in interfaceMutableBagIterable<T>
-
without
Description copied from interface:MutableCollection
This method allows mutable and fixed size collections the ability to remove elements from their existing elements. In order to support fixed size a new instance of a collection would have to be returned containing the elements that would be left from the original collection after calling remove. In the case of mutable collections, the original collection is modified, and is returned. In order to use this method properly with mutable and fixed size collections the following approach must be taken:MutableCollection<String> list = list.without("1"); list = list.without("2"); return list;
In the case ofFixedSizeCollection
a new instance of MutableCollection will be returned by without, and any variables that previously referenced the original collection will need to be redirected to reference the new instance. For other MutableCollection types you will replace the reference to collection with the same collection, since the instance will return "this" after calling remove on itself.- Specified by:
without
in interfaceMutableBagIterable<T>
- Specified by:
without
in interfaceMutableCollection<T>
- Specified by:
without
in interfaceMutableSortedBag<T>
- See Also:
Collection.remove(Object)
-
withAll
Description copied from interface:MutableCollection
This method allows mutable and fixed size collections the ability to add multiple elements to their existing elements. In order to support fixed size a new instance of a collection would have to be returned taking the elements of the original collection and appending the new elements to form the new collection. In the case of mutable collections, the original collection is modified, and is returned. In order to use this method properly with mutable and fixed size collections the following approach must be taken:MutableCollection<String> list = list.withAll(FastList.newListWith("1", "2"));
In the case ofFixedSizeCollection
a new instance of MutableCollection will be returned by withAll, and any variables that previously referenced the original collection will need to be redirected to reference the new instance. For other MutableCollection types you will replace the reference to collection with the same collection, since the instance will return "this" after calling addAll on itself.- Specified by:
withAll
in interfaceMutableBagIterable<T>
- Specified by:
withAll
in interfaceMutableCollection<T>
- Specified by:
withAll
in interfaceMutableSortedBag<T>
- See Also:
Collection.addAll(Collection)
-
withoutAll
Description copied from interface:MutableCollection
This method allows mutable and fixed size collections the ability to remove multiple elements from their existing elements. In order to support fixed size a new instance of a collection would have to be returned containing the elements that would be left from the original collection after calling removeAll. In the case of mutable collections, the original collection is modified, and is returned. In order to use this method properly with mutable and fixed size collections the following approach must be taken:MutableCollection<String> list = list.withoutAll(FastList.newListWith("1", "2"));
In the case ofFixedSizeCollection
a new instance of MutableCollection will be returned by withoutAll, and any variables that previously referenced the original collection will need to be redirected to reference the new instance. For other MutableCollection types you will replace the reference to collection with the same collection, since the instance will return "this" after calling removeAll on itself.- Specified by:
withoutAll
in interfaceMutableBagIterable<T>
- Specified by:
withoutAll
in interfaceMutableCollection<T>
- Specified by:
withoutAll
in interfaceMutableSortedBag<T>
- See Also:
Collection.removeAll(Collection)
-
with
Description copied from interface:MutableCollection
This method allows mutable and fixed size collections the ability to add elements to their existing elements. In order to support fixed size a new instance of a collection would have to be returned taking the elements of the original collection and appending the new element to form the new collection. In the case of mutable collections, the original collection is modified, and is returned. In order to use this method properly with mutable and fixed size collections the following approach must be taken:MutableCollection<String> list = list.with("1"); list = list.with("2"); return list;
In the case ofFixedSizeCollection
a new instance of MutableCollection will be returned by with, and any variables that previously referenced the original collection will need to be redirected to reference the new instance. For other MutableCollection types you will replace the reference to collection with the same collection, since the instance will return "this" after calling add on itself.- Specified by:
with
in interfaceMutableBagIterable<T>
- Specified by:
with
in interfaceMutableCollection<T>
- Specified by:
with
in interfaceMutableSortedBag<T>
- See Also:
Collection.add(Object)
-
newEmpty
Description copied from interface:MutableCollection
Creates a new empty mutable version of the same collection type. For example, if this instance is a FastList, this method will return a new empty FastList. If the class of this instance is immutable or fixed size (i.e. SingletonList) then a mutable alternative to the class will be provided.- Specified by:
newEmpty
in interfaceMutableCollection<T>
- Specified by:
newEmpty
in interfaceMutableSortedBag<T>
-
removeIf
Description copied from interface:MutableCollection
Removes all elements in the collection that evaluate to true for the specified predicate.e.g. return lastNames.removeIf(Predicates.isNull());
- Specified by:
removeIf
in interfaceMutableCollection<T>
-
removeIfWith
Description copied from interface:MutableCollection
Removes all elements in the collection that evaluate to true for the specified predicate2 and parameter.return lastNames.removeIfWith(Predicates2.isNull(), null);
- Specified by:
removeIfWith
in interfaceMutableCollection<T>
-
removeAllIterable
- Specified by:
removeAllIterable
in interfaceMutableCollection<T>
- See Also:
Collection.removeAll(Collection)
-
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>
-
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:
List.indexOf(Object)
-
zipWithIndex
Description copied from interface:RichIterable
Zips thisRichIterable
with its indices.- Specified by:
zipWithIndex
in interfaceBag<T>
- Specified by:
zipWithIndex
in interfaceMutableBagIterable<T>
- Specified by:
zipWithIndex
in interfaceMutableCollection<T>
- Specified by:
zipWithIndex
in interfaceMutableSortedBag<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>
- 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)
-
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 interfaceMutableSortedBag<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
-
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 interfaceMutableBagIterable<T>
- Specified by:
groupBy
in interfaceMutableCollection<T>
- Specified by:
groupBy
in interfaceMutableSortedBag<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>
-
groupByEach
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 interfaceMutableBagIterable<T>
- Specified by:
groupByEach
in interfaceMutableCollection<T>
- Specified by:
groupByEach
in interfaceMutableSortedBag<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>
-
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>
-
corresponds
public <S> boolean corresponds(OrderedIterable<S> other, Predicate2<? super T,? super S> predicate)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>
-
toStack
Description copied from interface:OrderedIterable
Converts the OrderedIterable to a mutable MutableStack implementation.- Specified by:
toStack
in interfaceOrderedIterable<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 interfaceMutableSortedBag<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 interfaceMutableSortedBag<T>
- Specified by:
drop
in interfaceReversibleIterable<T>
- Specified by:
drop
in interfaceSortedBag<T>
- Parameters:
count
- the number of items to drop.
-
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>
-
with
-
with
-
add
- Specified by:
add
in interfaceCollection<T>
-
with
-