Top Description Inners Fields Constructors Methods
com.google.common.collect

public final Class TreeMultiset<E extends @Nullable Object>

extends AbstractSortedMultiset<E extends @Nullable Object>
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Annotations
@GwtCompatible
emulated:true
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument, .Preconditions.checkNotNull, .Preconditions.checkState, com.google.common.collect.CollectPreconditions.checkNonnegative, .NullnessCasts.uncheckedCastNullableTToT, java.util.Objects.requireNonNull

A multiset which maintains the ordering of its elements, according to either their natural order or an explicit Comparator. In all cases, this implementation uses Comparable#compareTo or Comparator#compare instead of Object#equals to determine equivalence of instances.

Warning

The comparison must be consistent with equals as explained by the Comparable class specification. Otherwise, the resulting multiset will violate the java.util.Collection contract, which is specified in terms of Object#equals.

See the Guava User Guide article on Multiset.

Authors
Louis Wasserman, Jared Levy
Since
2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum
TreeMultiset.Aggregate

A function which can be summed across a subtree.

private static class
private static class

Field Summary

Modifier and TypeField and Description
private final transient TreeMultiset.AvlNode<E>
private final transient GeneralRange<E>
private final transient TreeMultiset.Reference<TreeMultiset.AvlNode<E>>
private static final long
Inherited from com.google.common.collect.AbstractSortedMultiset:
comparator

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv
TreeMultiset(Comparator<? super E> comparator)

Method Summary

Modifier and TypeMethod and Description
public int
add(E
the element to add occurrences of; may be null only if explicitly allowed by the implementation
element
,
int
the number of occurrences of the element to add. May be zero, in which case no change will be made.
occurrences
)

Overrides com.google.common.collect.AbstractMultiset.add.

Implements com.google.common.collect.Multiset.add.

Adds a number of occurrences of an element to this multiset.
private long
private long
private long
public void
clear()

Implements abstract com.google.common.collect.AbstractMultiset.clear.

Implements java.util.Collection.clear.

Removes all of the elements from this collection (optional operation).
public int
count(Object
the element to count occurrences of
element
)

Implements com.google.common.collect.Multiset.count.

Returns the number of occurrences of an element in this multiset (the count of the element).
public static <E extends Comparable<T>> TreeMultiset<E>
create()

Creates a new, empty multiset, sorted according to the elements' natural order.

public static <E extends @Nullable Object> TreeMultiset<E>
create(Comparator<? super E>
the comparator that will be used to sort this multiset. A null value indicates that the elements' natural ordering should be used.
comparator
)

Creates a new, empty multiset, sorted according to the specified comparator.

public static <E extends Comparable<T>> TreeMultiset<E>
create(Iterable<? extends E> elements)

Creates an empty multiset containing the given initial elements, sorted according to the elements' natural order.

pack-priv Iterator<Multiset.Entry<E>>
pack-priv int
pack-priv static int
pack-priv Iterator<E>
pack-priv Iterator<Multiset.Entry<E>>
private TreeMultiset.AvlNode<E>
firstNode()

Returns the first node in the tree that is in range.

public void
forEachEntry(ObjIntConsumer<? super E> action)

Overrides default com.google.common.collect.Multiset.forEachEntry.

Runs the specified action for each distinct element in this multiset, and the number of occurrences of that element.
public SortedMultiset<E>
headMultiset(E upperBound, BoundType boundType)

Implements com.google.common.collect.SortedMultiset.headMultiset.

Returns a view of this multiset restricted to the elements less than upperBound, optionally including upperBound itself.
public Iterator<E>
private TreeMultiset.AvlNode<E>
private void
public int
remove(Object
the element to conditionally remove occurrences of
element
,
int
the number of occurrences of the element to remove. May be zero, in which case no change will be made.
occurrences
)

Overrides com.google.common.collect.AbstractMultiset.remove.

Implements com.google.common.collect.Multiset.remove.

Removes a number of occurrences of the specified element from this multiset.
public int
setCount(E
the element to add or remove occurrences of; may be null only if explicitly allowed by the implementation
element
,
int
the desired count of the element in this multiset
count
)

Overrides com.google.common.collect.AbstractMultiset.setCount.

Implements com.google.common.collect.Multiset.setCount.

Adds or removes the necessary occurrences of an element such that the element attains the desired count.
public boolean
setCount(E
the element to conditionally set the count of; may be null only if explicitly allowed by the implementation
element
,
int
the expected present count of the element in this multiset
oldCount
,
int
the desired count of the element in this multiset
newCount
)

Overrides com.google.common.collect.AbstractMultiset.setCount.

Implements com.google.common.collect.Multiset.setCount.

Conditionally sets the count of an element to a new value, as described in setCount(Object, int), provided that the element has the expected current count.
public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements com.google.common.collect.Multiset.size, java.util.Collection.size.

Returns the total number of all occurrences of all elements in this multiset.
private static <T extends @Nullable Object> void
private static <T extends @Nullable Object> void
public SortedMultiset<E>
tailMultiset(E lowerBound, BoundType boundType)

Implements com.google.common.collect.SortedMultiset.tailMultiset.

Returns a view of this multiset restricted to the elements greater than lowerBound, optionally including lowerBound itself.
private Multiset.Entry<E>
wrapEntry(final TreeMultiset.AvlNode<E> baseEntry)

private void
Inherited from com.google.common.collect.AbstractSortedMultiset:
comparatorcreateDescendingMultisetcreateElementSetdescendingIteratordescendingMultisetelementSetfirstEntrylastEntrypollFirstEntrypollLastEntrysubMultiset