Top Description Inners Fields Constructors Methods
org.eclipse.collections.impl.bag.sorted.mutable

public Class TreeBag<T>

extends AbstractMutableSortedBag<T>
implements Externalizable
Class Inheritance
All Implemented Interfaces
java.io.Externalizable, java.io.Serializable
Imports
java.io.Externalizable, .IOException, .ObjectInput, .ObjectOutput, java.util.Arrays, .Comparator, .Iterator, .Map, .Set, org.eclipse.collections.api.RichIterable, org.eclipse.collections.api.bag.Bag, org.eclipse.collections.api.bag.sorted.MutableSortedBag, .SortedBag, org.eclipse.collections.api.block.function.Function, org.eclipse.collections.api.block.predicate.Predicate, .Predicate2, org.eclipse.collections.api.block.predicate.primitive.IntPredicate, .ObjectIntPredicate, org.eclipse.collections.api.block.procedure.Procedure, .Procedure2, org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure, org.eclipse.collections.api.factory.SortedMaps, .SortedSets, org.eclipse.collections.api.map.sorted.MutableSortedMap, org.eclipse.collections.api.ordered.OrderedIterable, org.eclipse.collections.api.set.sorted.MutableSortedSet, org.eclipse.collections.api.stack.MutableStack, org.eclipse.collections.api.tuple.Pair, org.eclipse.collections.impl.Counter, org.eclipse.collections.impl.block.factory.Comparators, org.eclipse.collections.impl.block.procedure.checked.CheckedProcedure2, org.eclipse.collections.impl.map.sorted.mutable.TreeSortedMap, org.eclipse.collections.impl.multimap.bag.sorted.mutable.TreeBagMultimap, org.eclipse.collections.impl.set.sorted.mutable.TreeSortedSet, org.eclipse.collections.impl.stack.mutable.ArrayStack, org.eclipse.collections.impl.utility.Iterate, .ListIterate, .OrderedIterate, org.eclipse.collections.impl.utility.internal.IterableIterate, .SortedBagIterables

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private MutableSortedMap<T, Counter>
private static final long
private int

Constructor Summary

AccessConstructor and Description
public
private
public
TreeBag(Comparator<? super T> comparator)

public
TreeBag(SortedBag<T> sortedBag)

public
TreeBag(Comparator<? super T> comparator, Iterable<? extends T> iterable)

Method Summary

Modifier and TypeMethod and Description
public boolean
add(T item)

Implements java.util.Collection.add.

Ensures that this collection contains the specified element (optional operation).

public int
addOccurrences(T item, int occurrences)

Implements org.eclipse.collections.api.bag.MutableBagIterable.addOccurrences.

Add number of occurrences for an item.

public boolean
allSatisfyWithOccurrences(ObjectIntPredicate<? super T> predicate)

Implements org.eclipse.collections.api.bag.Bag.allSatisfyWithOccurrences.

Returns true if the predicate evaluates to true for all elements of the Bag.

public boolean
anySatisfyWithOccurrences(ObjectIntPredicate<? super T> predicate)

Implements org.eclipse.collections.api.bag.Bag.anySatisfyWithOccurrences.

Returns true if the predicate evaluates to true for any element of the Bag.

public void
clear()

Implements java.util.Collection.clear.

Removes all of the elements from this collection (optional operation).

public TreeBag<T>
public Comparator<? super T>
comparator()

Implements org.eclipse.collections.api.bag.sorted.SortedBag.comparator.

Returns the comparator used to order the elements in this bag, or null if this bag uses the natural ordering of its elements.

public int
compareTo(SortedBag<T> otherBag)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.

public boolean
contains(Object o)

Overrides org.eclipse.collections.impl.AbstractRichIterable.contains.

Implements org.eclipse.collections.api.RichIterable.contains, java.util.Collection.contains.

Returns true if the iterable has an element which responds true to element.equals(object).

public <S> boolean
corresponds(OrderedIterable<S> other, Predicate2<? super T, ? super S> predicate)

Implements org.eclipse.collections.api.ordered.OrderedIterable.corresponds.

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.

public int
detectIndex(Predicate<? super T> predicate)

Implements org.eclipse.collections.api.ordered.OrderedIterable.detectIndex.

Returns the index of the first element of the OrderedIterable for which the predicate evaluates to true.

public T
detectWithOccurrences(ObjectIntPredicate<? super T> predicate)

Implements org.eclipse.collections.api.bag.Bag.detectWithOccurrences.

Returns an element of the Bag that satisfies the predicate or null if such an element does not exist

public MutableSortedSet<T>
distinct()

Implements org.eclipse.collections.api.bag.sorted.MutableSortedBag.distinct.

Returns a new SortedIterable containing the distinct elements in this iterable.

public RichIterable<T>
distinctView()

Overrides default org.eclipse.collections.api.bag.Bag.distinctView.

Returns an unmodifiable view on the distinct elements with the same complexity as the Bag implementation.

public MutableSortedBag<T>
drop(int count)

Implements org.eclipse.collections.api.bag.sorted.MutableSortedBag.drop.

Returns an iterable after skipping the first count elements or an empty iterable if the count is greater than the length of the iterable.

public void
each(Procedure<? super T> procedure)

Implements org.eclipse.collections.api.RichIterable.each.

The procedure is executed for each element in the iterable.

public boolean
equals(Object other)

Overrides java.lang.Object.equals.

Implements org.eclipse.collections.api.bag.Bag.equals, java.util.Collection.equals.

Two bags b1 and b2 are equal if m1.toMapOfItemToCount().equals(m2.toMapOfItemToCount()).

public void
forEach(int fromIndex, int toIndex, Procedure<? super T> procedure)

Implements org.eclipse.collections.api.ordered.OrderedIterable.forEach.

Iterates over the section of the iterable covered by the specified inclusive indexes.

public <P> void
forEachWith(Procedure2<? super T, ? super P> procedure, P parameter)

Overrides org.eclipse.collections.impl.AbstractRichIterable.forEachWith.

Implements org.eclipse.collections.api.InternalIterable.forEachWith.

The procedure2 is evaluated for each element in the iterable with the specified parameter provided as the second argument.

public void
forEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure)

Overrides org.eclipse.collections.impl.AbstractRichIterable.forEachWithIndex.

Implements org.eclipse.collections.api.InternalIterable.forEachWithIndex, org.eclipse.collections.api.ordered.OrderedIterable.forEachWithIndex.

Iterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.

public void
forEachWithIndex(int fromIndex, int toIndex, ObjectIntProcedure<? super T> objectIntProcedure)

Implements org.eclipse.collections.api.ordered.OrderedIterable.forEachWithIndex.

Iterates over the section of the iterable covered by the specified inclusive indexes.

public void
forEachWithOccurrences(ObjectIntProcedure<? super T> procedure)

Implements org.eclipse.collections.api.bag.Bag.forEachWithOccurrences.

For each distinct item, with the number of occurrences, execute the specified procedure.

protected RichIterable<T>
public <V> TreeBagMultimap<V, T>
groupBy(Function<? super T, ? extends V> function)

Implements org.eclipse.collections.api.bag.sorted.MutableSortedBag.groupBy, org.eclipse.collections.api.bag.MutableBagIterable.groupBy, org.eclipse.collections.api.bag.Bag.groupBy, org.eclipse.collections.api.RichIterable.groupBy.

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.

public <V> TreeBagMultimap<V, T>
public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements org.eclipse.collections.api.bag.Bag.hashCode, java.util.Collection.hashCode.

Returns the hash code for this Bag, defined as this.

public int
indexOf(Object object)

Overrides default org.eclipse.collections.api.ordered.OrderedIterable.indexOf.

Returns the index of the first occurrence of the specified item in this iterable, or -1 if this iterable does not contain the item.

public boolean
public Iterator<T>
iterator()

Implements java.lang.Iterable.iterator, java.util.Collection.iterator.

Returns an iterator over elements of type T.

public static <E> TreeBag<E>
public static <E> TreeBag<E>
newBag(Comparator<? super E> comparator)

public static <E> TreeBag<E>
newBag(Iterable<? extends E> source)

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 MutableSortedBag<T>
public boolean
noneSatisfyWithOccurrences(ObjectIntPredicate<? super T> predicate)

Implements org.eclipse.collections.api.bag.Bag.noneSatisfyWithOccurrences.

Returns true if the Bag is empty or if the predicate evaluates to false for all elements of the Bag.

public int
occurrencesOf(Object item)

Implements org.eclipse.collections.api.bag.Bag.occurrencesOf.

The occurrences of a distinct item in the bag.

public void
readExternal(ObjectInput in)

Implements java.io.Externalizable.readExternal.

The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays.

public boolean
remove(Object item)

Implements java.util.Collection.remove.

Removes a single instance of the specified element from this collection, if it is present (optional operation).

public boolean
public boolean
removeIf(Predicate<? super T> predicate)

Implements org.eclipse.collections.api.collection.MutableCollection.removeIf.

Removes all elements in the collection that evaluate to true for the specified predicate.

public <P> boolean
removeIfWith(Predicate2<? super T, ? super P> predicate, P parameter)

Implements org.eclipse.collections.api.collection.MutableCollection.removeIfWith.

Removes all elements in the collection that evaluate to true for the specified predicate2 and parameter.

public boolean
public MutableSortedBag<T>
public boolean
public int
size()

Implements org.eclipse.collections.api.RichIterable.size, java.util.Collection.size.

Returns the number of items in this iterable.

public int
sizeDistinct()

Implements org.eclipse.collections.api.bag.Bag.sizeDistinct.

The size of the Bag when counting only distinct elements.

public MutableSortedBag<T>
take(int count)

Implements org.eclipse.collections.api.bag.sorted.MutableSortedBag.take.

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.

public MutableStack<T>
toStack()

Overrides default org.eclipse.collections.api.ordered.OrderedIterable.toStack.

Converts the OrderedIterable to a mutable MutableStack implementation.

public TreeBag<T>
with(T element)

Overrides default org.eclipse.collections.api.bag.sorted.MutableSortedBag.with, org.eclipse.collections.api.bag.MutableBagIterable.with.

This method allows mutable and fixed size collections the ability to add elements to their existing elements.

public TreeBag<T>
with(T... elements)

Overrides default org.eclipse.collections.api.bag.sorted.MutableSortedBag.with, org.eclipse.collections.api.bag.MutableBagIterable.with.

This method allows mutable and fixed size collections the ability to add elements to their existing elements.

public TreeBag<T>
with(T element1, T element2)

public TreeBag<T>
with(T element1, T element2, T element3)

public TreeBag<T>
withAll(Iterable<? extends T> iterable)

Overrides default org.eclipse.collections.api.bag.sorted.MutableSortedBag.withAll, org.eclipse.collections.api.bag.MutableBagIterable.withAll.

This method allows mutable and fixed size collections the ability to add multiple elements to their existing elements.

public TreeBag<T>
without(T element)

Overrides default org.eclipse.collections.api.bag.sorted.MutableSortedBag.without, org.eclipse.collections.api.bag.MutableBagIterable.without.

This method allows mutable and fixed size collections the ability to remove elements from their existing elements.

public TreeBag<T>
withoutAll(Iterable<? extends T> iterable)

Overrides default org.eclipse.collections.api.bag.sorted.MutableSortedBag.withoutAll, org.eclipse.collections.api.bag.MutableBagIterable.withoutAll.

This method allows mutable and fixed size collections the ability to remove multiple elements from their existing elements.

public void
writeExternal(ObjectOutput out)

Implements java.io.Externalizable.writeExternal.

The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.

public MutableSortedSet<Pair<T, Integer>>
Inherited from org.eclipse.collections.impl.bag.sorted.mutable.AbstractMutableSortedBag:
asParallelasSynchronizedasUnmodifiablecollectcollectBooleancollectBytecollectCharcollectDoublecollectFloatcollectIfcollectIntcollectLongcollectShortcollectWithcollectWithIndexcollectWithIndexcollectWithOccurrencescountBycountByEachcountByWithdetectLastIndexdropWhileflatCollectpartitionpartitionWhilepartitionWithrejectrejectWithselectselectInstancesOfselectWithtakeWhiletaptoImmutabletoMapOfItemToCounttoReversedzip