public class TreeBag<T> extends AbstractMutableSortedBag<T> implements Externalizable
| Constructor and Description |
|---|
TreeBag() |
TreeBag(Comparator<? super T> comparator) |
TreeBag(Comparator<? super T> comparator,
Iterable<? extends T> iterable) |
TreeBag(SortedBag<T> sortedBag) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(T item) |
int |
addOccurrences(T item,
int occurrences)
Add number of
occurrences for an item. |
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
and
predicate returns true for all corresponding elements e1 of
this OrderedIterable and e2 of other. |
int |
detectIndex(Predicate<? super T> predicate)
Returns the index of the first element of the
OrderedIterable for which the predicate evaluates to true. |
MutableSortedSet<T> |
distinct()
Returns a new
SortedIterable containing the distinct elements in this iterable. |
MutableSortedBag<T> |
drop(int count)
Returns an iterable after skipping the first
count elements
or an empty iterable if the count 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 and b2 are equal if m1.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 to
RichIterable.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(Comparator<? super E> comparator) |
static <E> TreeBag<E> |
newBag(Comparator<? super E> comparator,
Iterable<? extends E> iterable) |
static <E> TreeBag<E> |
newBag(Iterable<? extends E> source) |
static <E> TreeBag<E> |
newBagWith(Comparator<? super E> comparator,
E... elements) |
static <E> TreeBag<E> |
newBagWith(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 first
count elements of the iterable
or all the elements in the iterable if count is greater than the length of
the iterable. |
MutableStack<T> |
toStack()
Converts the OrderedIterable to a mutable MutableStack implementation.
|
TreeBag<T> |
with(T... elements) |
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 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 this
RichIterable with its indices. |
asParallel, asSynchronized, asUnmodifiable, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, detectLastIndex, dropWhile, flatCollect, partition, partitionWhile, partitionWith, reject, rejectWith, reverseForEach, select, selectInstancesOf, selectWith, takeWhile, tap, toImmutable, toMapOfItemToCount, toReversed, zipaddAll, addAllIterable, aggregateBy, 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, topOccurrencescollect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, count, flatCollect, groupBy, groupByEach, injectInto, injectInto, injectInto, injectInto, injectInto, injectIntoWith, reject, rejectWith, select, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toBag, toList, toSet, toSortedBag, toSortedBag, toSortedList, toSortedSet, toSortedSet, toStringOfItemToCountappendString, appendString, asLazy, containsAll, containsAllArguments, containsAllIterable, countWith, forEach, groupByUniqueKey, into, toArray, toArray, toMap, toSortedBagBy, toSortedListBy, toSortedMap, toSortedMap, toSortedSetBy, toString, zip, zipWithIndexaggregateBy, aggregateInPlaceByasReversedgetFirst, getLast, zip, zipWithIndexallSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, appendString, asLazy, chunk, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, containsAll, containsAllArguments, containsAllIterable, count, countWith, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, flatCollect, getOnly, groupBy, groupByEach, groupByUniqueKey, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, into, makeString, makeString, makeString, max, maxBy, min, minBy, noneSatisfy, noneSatisfyWith, notEmpty, reduce, reject, rejectWith, select, selectWith, sumByDouble, sumByFloat, sumByInt, sumByLong, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toList, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toSortedSetBy, toStringforEachforEach, spliteratorbottomOccurrences, topOccurrencesreduceInPlace, reduceInPlace, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, toStringOfItemToCountaddAllIterable, groupByUniqueKey, injectIntoWith, retainAllIterable, selectAndRejectWith, sumByDouble, sumByFloat, sumByInt, sumByLongaddAll, containsAll, parallelStream, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArraypublic TreeBag()
public TreeBag(Comparator<? super T> comparator)
public TreeBag(Comparator<? super T> comparator, Iterable<? extends T> iterable)
public static <E> TreeBag<E> newBag()
public static <E> TreeBag<E> newBag(Comparator<? super E> comparator)
public static <E> TreeBag<E> newBag(Comparator<? super E> comparator, Iterable<? extends E> iterable)
public static <E> TreeBag<E> newBagWith(E... elements)
public static <E> TreeBag<E> newBagWith(Comparator<? super E> comparator, E... elements)
public TreeBag<T> clone()
clone in interface MutableSortedBag<T>clone in class AbstractMutableSortedBag<T>public boolean equals(Object other)
Bagequals in interface Collection<T>equals in interface Bag<T>equals in class ObjectMap.equals(Object)public int hashCode()
BagBag.toMapOfItemToCount().hashCode().hashCode in interface Collection<T>hashCode in interface Bag<T>hashCode in class ObjectMap.hashCode()public int sizeDistinct()
BagsizeDistinct in interface Bag<T>public void forEachWithOccurrences(ObjectIntProcedure<? super T> procedure)
BagforEachWithOccurrences in interface Bag<T>public MutableSortedBag<T> selectByOccurrences(IntPredicate predicate)
BagselectByOccurrences in interface Bag<T>selectByOccurrences in interface MutableBagIterable<T>selectByOccurrences in interface MutableSortedBag<T>selectByOccurrences in interface SortedBag<T>public int occurrencesOf(Object item)
BagoccurrencesOf in interface Bag<T>public boolean isEmpty()
RichIterableisEmpty in interface Collection<T>isEmpty in interface RichIterable<T>isEmpty in class AbstractRichIterable<T>public boolean remove(Object item)
remove in interface Collection<T>public void clear()
clear in interface Collection<T>public boolean contains(Object o)
RichIterablecontains in interface Collection<T>contains in interface RichIterable<T>contains in class AbstractRichIterable<T>public int compareTo(SortedBag<T> otherBag)
compareTo in interface Comparable<SortedBag<T>>public void writeExternal(ObjectOutput out) throws IOException
writeExternal in interface ExternalizableIOExceptionpublic void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal in interface ExternalizableIOExceptionClassNotFoundExceptionpublic void each(Procedure<? super T> procedure)
RichIterableExample using a Java 8 lambda expression:
people.each(person -> LOGGER.info(person.getName()));
Example using an anonymous inner class:
people.each(new ProcedureThis method is a variant of() { public void value(Person person) { LOGGER.info(person.getName()); } });
InternalIterable.forEach(Procedure)
that has a signature conflict with Iterable.forEach(java.util.function.Consumer).each in interface RichIterable<T>InternalIterable.forEach(Procedure),
Iterable.forEach(java.util.function.Consumer)public void forEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure)
InternalIterableExample 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() { public void value(Person person, int index) { LOGGER.info("Index: " + index + " person: " + person.getName()); } });
forEachWithIndex in interface InternalIterable<T>forEachWithIndex in interface OrderedIterable<T>forEachWithIndex in class AbstractRichIterable<T>public void forEach(int fromIndex,
int toIndex,
Procedure<? super T> procedure)
OrderedIterable
e.g. OrderedIterablepeople = FastList.newListWith(ted, mary, bob, sally) people.forEach(0, 1, new Procedure () { public void value(Person person) { LOGGER.info(person.getName()); } });
This code would output ted and mary's names.
forEach in interface OrderedIterable<T>public void forEachWithIndex(int fromIndex,
int toIndex,
ObjectIntProcedure<? super T> objectIntProcedure)
OrderedIterable
e.g. OrderedIterablepeople = FastList.newListWith(ted, mary, bob, sally) people.forEachWithIndex(0, 1, new ObjectIntProcedure () { public void value(Person person, int index) { LOGGER.info(person.getName()); } });
This code would output ted and mary's names.
forEachWithIndex in interface OrderedIterable<T>public <P> void forEachWith(Procedure2<? super T,? super P> procedure, P parameter)
InternalIterableExample 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() { public void value(Person person, Person other) { if (person.isRelatedTo(other)) { LOGGER.info(person.getName()); } } }, fred);
forEachWith in interface InternalIterable<T>forEachWith in class AbstractRichIterable<T>public int addOccurrences(T item, int occurrences)
MutableBagIterableoccurrences for an item. If the item does not exist, then the item is added to the bag.
For Example:
MutableBagIterable<String> names = Bags.mutable.of("A", "B", "B");
Assert.assertEquals(4, names.addOccurrences("A", 3));
addOccurrences in interface MutableBagIterable<T>public boolean removeOccurrences(Object item, int occurrences)
removeOccurrences in interface MutableBagIterable<T>public boolean setOccurrences(T item, int occurrences)
setOccurrences in interface MutableBagIterable<T>public TreeBag<T> without(T element)
MutableCollection
MutableCollectionIn the case oflist; list = list.without("1"); list = list.without("2"); return list;
FixedSizeCollection 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.without in interface MutableBagIterable<T>without in interface MutableSortedBag<T>without in interface MutableCollection<T>Collection.remove(Object)public TreeBag<T> withAll(Iterable<? extends T> iterable)
MutableCollection
MutableCollectionIn the case oflist; list = list.withAll(FastList.newListWith("1", "2")); return list;
FixedSizeCollection 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.withAll in interface MutableBagIterable<T>withAll in interface MutableSortedBag<T>withAll in interface MutableCollection<T>Collection.addAll(Collection)public TreeBag<T> withoutAll(Iterable<? extends T> iterable)
MutableCollection
MutableCollectionIn the case oflist; list = list.withoutAll(FastList.newListWith("1", "2")); return list;
FixedSizeCollection 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.withoutAll in interface MutableBagIterable<T>withoutAll in interface MutableSortedBag<T>withoutAll in interface MutableCollection<T>Collection.removeAll(Collection)public TreeBag<T> with(T element)
MutableCollection
MutableCollectionIn the case oflist; list = list.with("1"); list = list.with("2"); return list;
FixedSizeCollection 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.with in interface MutableBagIterable<T>with in interface MutableSortedBag<T>with in interface MutableCollection<T>Collection.add(Object)public MutableSortedBag<T> newEmpty()
MutableCollectionnewEmpty in interface MutableSortedBag<T>newEmpty in interface MutableCollection<T>public boolean removeIf(Predicate<? super T> predicate)
MutableCollection
e.g. return lastNames.removeIf(Predicates.isNull());
removeIf in interface MutableCollection<T>public <P> boolean removeIfWith(Predicate2<? super T,? super P> predicate, P parameter)
MutableCollection
e.g. return lastNames.removeIfWith(PredicatesLite.isNull(), null);
removeIfWith in interface MutableCollection<T>public boolean removeAllIterable(Iterable<?> iterable)
removeAllIterable in interface MutableCollection<T>Collection.removeAll(Collection)public int size()
RichIterablesize in interface Collection<T>size in interface RichIterable<T>public int indexOf(Object object)
OrderedIterableindexOf in interface OrderedIterable<T>List.indexOf(Object)public MutableSortedSet<Pair<T,Integer>> zipWithIndex()
RichIterableRichIterable with its indices.zipWithIndex in interface Bag<T>zipWithIndex in interface MutableBagIterable<T>zipWithIndex in interface MutableSortedBag<T>zipWithIndex in interface SortedBag<T>zipWithIndex in interface MutableCollection<T>zipWithIndex in interface OrderedIterable<T>zipWithIndex in interface ReversibleIterable<T>zipWithIndex in interface SortedIterable<T>zipWithIndex in interface RichIterable<T>RichIterable containing pairs consisting of all elements of this RichIterable
paired with their index. Indices start at 0.RichIterable.zip(Iterable)public MutableSortedSet<T> distinct()
SortedIterableSortedIterable 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.
distinct in interface MutableSortedBag<T>distinct in interface SortedBag<T>distinct in interface OrderedIterable<T>distinct in interface ReversibleIterable<T>distinct in interface SortedIterable<T>SortedIterable of distinct elementspublic <V> TreeBagMultimap<V,T> groupBy(Function<? super T,? extends V> function)
RichIterableExample 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();
}
});
groupBy in interface Bag<T>groupBy in interface MutableBagIterable<T>groupBy in interface MutableSortedBag<T>groupBy in interface SortedBag<T>groupBy in interface MutableCollection<T>groupBy in interface OrderedIterable<T>groupBy in interface ReversibleIterable<T>groupBy in interface SortedIterable<T>groupBy in interface RichIterable<T>public <V> TreeBagMultimap<V,T> groupByEach(Function<? super T,? extends Iterable<V>> function)
RichIterableRichIterable.groupBy(Function), except the result of evaluating function will return a collection of keys
for each value.groupByEach in interface Bag<T>groupByEach in interface MutableBagIterable<T>groupByEach in interface MutableSortedBag<T>groupByEach in interface SortedBag<T>groupByEach in interface MutableCollection<T>groupByEach in interface OrderedIterable<T>groupByEach in interface ReversibleIterable<T>groupByEach in interface SortedIterable<T>groupByEach in interface RichIterable<T>public int detectIndex(Predicate<? super T> predicate)
OrderedIterableOrderedIterable for which the predicate evaluates to true.
Returns -1 if no element evaluates true for the predicate.detectIndex in interface OrderedIterable<T>public <S> boolean corresponds(OrderedIterable<S> other, Predicate2<? super T,? super S> predicate)
OrderedIterablepredicate returns true for all corresponding elements e1 of
this OrderedIterable and e2 of other.
The predicate is evaluated for each element at the same position of each OrderedIterable in a forward iteration order.
This is a short circuit pattern.corresponds in interface OrderedIterable<T>public MutableStack<T> toStack()
OrderedIterabletoStack in interface OrderedIterable<T>toStack in interface SortedIterable<T>public MutableSortedBag<T> take(int count)
ReversibleIterablecount elements of the iterable
or all the elements in the iterable if count is greater than the length of
the iterable.take in interface MutableSortedBag<T>take in interface SortedBag<T>take in interface ReversibleIterable<T>count - the number of items to take.public MutableSortedBag<T> drop(int count)
ReversibleIterablecount elements
or an empty iterable if the count is greater than the length of the iterable.drop in interface MutableSortedBag<T>drop in interface SortedBag<T>drop in interface ReversibleIterable<T>count - the number of items to drop.public Comparator<? super T> comparator()
SortedBagcomparator in interface SortedBag<T>comparator in interface SortedIterable<T>public boolean add(T item)
add in interface Collection<T>Copyright © 2004–2016. All rights reserved.