@GwtIncompatible final class RegularImmutableSortedMultiset<E> extends ImmutableSortedMultiset<E>
ImmutableSortedMultiset.Builder<E>
ImmutableMultiset.ElementSet<E>, ImmutableMultiset.EntrySetSerializedForm<E>
Multiset.Entry<E>
Modifier and Type | Field and Description |
---|---|
private long[] |
cumulativeCounts |
(package private) RegularImmutableSortedSet<E> |
elementSet |
private int |
length |
(package private) static ImmutableSortedMultiset<java.lang.Comparable> |
NATURAL_EMPTY_MULTISET |
private int |
offset |
private static long[] |
ZERO_CUMULATIVE_COUNTS |
descendingMultiset
SPLITERATOR_CHARACTERISTICS
Constructor and Description |
---|
RegularImmutableSortedMultiset(java.util.Comparator<? super E> comparator) |
RegularImmutableSortedMultiset(RegularImmutableSortedSet<E> elementSet,
long[] cumulativeCounts,
int offset,
int length) |
Modifier and Type | Method and Description |
---|---|
int |
count(java.lang.Object element)
Returns the number of occurrences of an element in this multiset (the count of the
element).
|
ImmutableSortedSet<E> |
elementSet()
Returns the set of distinct elements contained in this multiset.
|
Multiset.Entry<E> |
firstEntry()
Returns the entry of the first element in this multiset, or
null if this multiset is
empty. |
void |
forEachEntry(java.util.function.ObjIntConsumer<? super E> action)
Runs the specified action for each distinct element in this multiset, and the number of
occurrences of that element.
|
private int |
getCount(int index) |
(package private) Multiset.Entry<E> |
getEntry(int index) |
(package private) ImmutableSortedMultiset<E> |
getSubMultiset(int from,
int to) |
ImmutableSortedMultiset<E> |
headMultiset(E upperBound,
BoundType boundType)
Returns a view of this multiset restricted to the elements less than
upperBound ,
optionally including upperBound itself. |
(package private) boolean |
isPartialView()
Returns
true if this immutable collection's implementation contains references to
user-created objects that aren't accessible via this collection's methods. |
Multiset.Entry<E> |
lastEntry()
Returns the entry of the last element in this multiset, or
null if this multiset is
empty. |
int |
size()
Returns the total number of all occurrences of all elements in this multiset.
|
ImmutableSortedMultiset<E> |
tailMultiset(E lowerBound,
BoundType boundType)
Returns a view of this multiset restricted to the elements greater than
lowerBound ,
optionally including lowerBound itself. |
comparator, copyOf, copyOf, copyOf, copyOf, copyOf, copyOfSorted, descendingMultiset, emptyMultiset, naturalOrder, of, of, of, of, of, of, of, orderedBy, pollFirstEntry, pollLastEntry, reverseOrder, subMultiset, toImmutableSortedMultiset, toImmutableSortedMultiset, writeReplace
builder, toImmutableMultiset, toImmutableMultiset
add, asList, contains, copyFromEntries, copyIntoArray, entrySet, equals, hashCode, iterator, remove, setCount, setCount, toString
add, addAll, clear, internalArray, internalArrayEnd, internalArrayStart, remove, removeAll, removeIf, retainAll, spliterator, toArray, toArray
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
entrySet, iterator
private static final long[] ZERO_CUMULATIVE_COUNTS
static final ImmutableSortedMultiset<java.lang.Comparable> NATURAL_EMPTY_MULTISET
final transient RegularImmutableSortedSet<E> elementSet
private final transient long[] cumulativeCounts
private final transient int offset
private final transient int length
RegularImmutableSortedMultiset(java.util.Comparator<? super E> comparator)
RegularImmutableSortedMultiset(RegularImmutableSortedSet<E> elementSet, long[] cumulativeCounts, int offset, int length)
private int getCount(int index)
Multiset.Entry<E> getEntry(int index)
getEntry
in class ImmutableMultiset<E>
public void forEachEntry(java.util.function.ObjIntConsumer<? super E> action)
Multiset
Multiset
implementations, this may be more
efficient than iterating over the Multiset.entrySet()
either explicitly or with entrySet().forEach(action)
.public Multiset.Entry<E> firstEntry()
SortedMultiset
null
if this multiset is
empty.public Multiset.Entry<E> lastEntry()
SortedMultiset
null
if this multiset is
empty.public int count(java.lang.Object element)
Multiset
Object.equals(java.lang.Object)
-based multiset, this gives the same result as
Collections.frequency(java.util.Collection<?>, java.lang.Object)
(which would presumably perform more poorly).
Note: the utility method Iterables.frequency(java.lang.Iterable<?>, java.lang.Object)
generalizes this operation; it
correctly delegates to this method when dealing with a multiset, but it can also accept any
other iterable type.
element
- the element to count occurrences ofpublic int size()
Multiset
Note: this method does not return the number of distinct elements in the
multiset, which is given by entrySet().size()
.
public ImmutableSortedSet<E> elementSet()
Multiset
If the element set supports any removal operations, these necessarily cause all occurrences of the removed element(s) to be removed from the multiset. Implementations are not expected to support the add operations, although this is possible.
A common use for the element set is to find the number of distinct elements in the multiset:
elementSet().size()
.
elementSet
in interface Multiset<E>
elementSet
in interface SortedMultiset<E>
elementSet
in interface SortedMultisetBridge<E>
elementSet
in class ImmutableSortedMultiset<E>
public ImmutableSortedMultiset<E> headMultiset(E upperBound, BoundType boundType)
SortedMultiset
upperBound
,
optionally including upperBound
itself. The returned multiset is a view of this
multiset, so changes to one will be reflected in the other. The returned multiset supports all
operations that this multiset supports.
The returned multiset will throw an IllegalArgumentException
on attempts to add
elements outside its range.
headMultiset
in interface SortedMultiset<E>
headMultiset
in class ImmutableSortedMultiset<E>
public ImmutableSortedMultiset<E> tailMultiset(E lowerBound, BoundType boundType)
SortedMultiset
lowerBound
,
optionally including lowerBound
itself. The returned multiset is a view of this
multiset, so changes to one will be reflected in the other. The returned multiset supports all
operations that this multiset supports.
The returned multiset will throw an IllegalArgumentException
on attempts to add
elements outside its range.
tailMultiset
in interface SortedMultiset<E>
tailMultiset
in class ImmutableSortedMultiset<E>
ImmutableSortedMultiset<E> getSubMultiset(int from, int to)
boolean isPartialView()
ImmutableCollection
true
if this immutable collection's implementation contains references to
user-created objects that aren't accessible via this collection's methods. This is generally
used to determine whether copyOf
implementations should make an explicit copy to avoid
memory leaks.isPartialView
in class ImmutableCollection<E>