public final class EnumMultiset<E extends java.lang.Enum<E>> extends AbstractMultiset<E> implements java.io.Serializable
See the Guava User Guide article on Multiset.
| Modifier and Type | Class and Description |
|---|---|
(package private) class |
EnumMultiset.Itr<T> |
AbstractMultiset.ElementSet, AbstractMultiset.EntrySetMultiset.Entry<E>| Modifier and Type | Field and Description |
|---|---|
private int[] |
counts |
private int |
distinctElements |
private E[] |
enumConstants |
private static long |
serialVersionUID |
private long |
size |
private java.lang.Class<E> |
type |
| Modifier | Constructor and Description |
|---|---|
private |
EnumMultiset(java.lang.Class<E> type)
Creates an empty
EnumMultiset. |
| Modifier and Type | Method and Description |
|---|---|
int |
add(E element,
int occurrences)
Adds a number of occurrences of an element to this multiset.
|
private void |
checkIsE(java.lang.Object element)
Returns
element cast to E, if it actually is a nonnull E. |
void |
clear() |
int |
count(java.lang.Object element)
Returns the number of occurrences of an element in this multiset (the count of the
element).
|
static <E extends java.lang.Enum<E>> |
create(java.lang.Class<E> type)
Creates an empty
EnumMultiset. |
static <E extends java.lang.Enum<E>> |
create(java.lang.Iterable<E> elements)
Creates a new
EnumMultiset containing the specified elements. |
static <E extends java.lang.Enum<E>> |
create(java.lang.Iterable<E> elements,
java.lang.Class<E> type)
Returns a new
EnumMultiset instance containing the given elements. |
(package private) int |
distinctElements() |
(package private) java.util.Iterator<E> |
elementIterator() |
(package private) java.util.Iterator<Multiset.Entry<E>> |
entryIterator() |
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 boolean |
isActuallyE(java.lang.Object o) |
java.util.Iterator<E> |
iterator() |
private void |
readObject(java.io.ObjectInputStream stream) |
int |
remove(java.lang.Object element,
int occurrences)
Removes a number of occurrences of the specified element from this multiset.
|
int |
setCount(E element,
int count)
Adds or removes the necessary occurrences of an element such that the element attains the
desired count.
|
int |
size()
Returns the total number of all occurrences of all elements in this multiset.
|
private void |
writeObject(java.io.ObjectOutputStream stream) |
add, addAll, contains, createElementSet, createEntrySet, elementSet, entrySet, equals, hashCode, isEmpty, remove, removeAll, retainAll, setCount, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitcontainsAll, forEach, spliteratorprivate transient int[] counts
private transient int distinctElements
private transient long size
private static final long serialVersionUID
private EnumMultiset(java.lang.Class<E> type)
EnumMultiset.public static <E extends java.lang.Enum<E>> EnumMultiset<E> create(java.lang.Class<E> type)
EnumMultiset.public static <E extends java.lang.Enum<E>> EnumMultiset<E> create(java.lang.Iterable<E> elements)
EnumMultiset containing the specified elements.
This implementation is highly efficient when elements is itself a Multiset.
elements - the elements that the multiset should containjava.lang.IllegalArgumentException - if elements is emptypublic static <E extends java.lang.Enum<E>> EnumMultiset<E> create(java.lang.Iterable<E> elements, java.lang.Class<E> type)
EnumMultiset instance containing the given elements. Unlike create(Iterable), this method does not produce an exception on an empty iterable.private boolean isActuallyE(@CheckForNull
java.lang.Object o)
private void checkIsE(java.lang.Object element)
element cast to E, if it actually is a nonnull E. Otherwise, throws
either a NullPointerException or a ClassCastException as appropriate.int distinctElements()
distinctElements in class AbstractMultiset<E extends java.lang.Enum<E>>public int size()
MultisetNote: this method does not return the number of distinct elements in the
multiset, which is given by entrySet().size().
public int count(@CheckForNull
java.lang.Object element)
MultisetObject.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.
public int add(E element, int occurrences)
Multisetoccurrences ==
1, this method has the identical effect to Multiset.add(Object). This method is functionally
equivalent (except in the case of overflow) to the call addAll(Collections.nCopies(element, occurrences)), which would presumably perform much more
poorly.add in interface Multiset<E extends java.lang.Enum<E>>add in class AbstractMultiset<E extends java.lang.Enum<E>>element - the element to add occurrences of; may be null only if explicitly allowed by the
implementationoccurrences - the number of occurrences of the element to add. May be zero, in which case
no change will be made.public int remove(@CheckForNull
java.lang.Object element,
int occurrences)
Multisetoccurrences == 1, this is functionally equivalent to the call remove(element).remove in interface Multiset<E extends java.lang.Enum<E>>remove in class AbstractMultiset<E extends java.lang.Enum<E>>element - the element to conditionally remove occurrences ofoccurrences - the number of occurrences of the element to remove. May be zero, in which
case no change will be made.public int setCount(E element, int count)
MultisetsetCount in interface Multiset<E extends java.lang.Enum<E>>setCount in class AbstractMultiset<E extends java.lang.Enum<E>>element - the element to add or remove occurrences of; may be null only if explicitly
allowed by the implementationcount - the desired count of the element in this multisetpublic void clear()
java.util.Iterator<E> elementIterator()
elementIterator in class AbstractMultiset<E extends java.lang.Enum<E>>java.util.Iterator<Multiset.Entry<E>> entryIterator()
entryIterator in class AbstractMultiset<E extends java.lang.Enum<E>>public void forEachEntry(java.util.function.ObjIntConsumer<? super E> action)
MultisetMultiset implementations, this may be more
efficient than iterating over the Multiset.entrySet() either explicitly or with entrySet().forEach(action).forEachEntry in interface Multiset<E extends java.lang.Enum<E>>public java.util.Iterator<E> iterator()
MultisetElements that occur multiple times in the multiset will appear multiple times in this iterator, though not necessarily sequentially.
iterator in interface Multiset<E extends java.lang.Enum<E>>iterator in interface java.lang.Iterable<E extends java.lang.Enum<E>>iterator in interface java.util.Collection<E extends java.lang.Enum<E>>iterator in class java.util.AbstractCollection<E extends java.lang.Enum<E>>private void writeObject(java.io.ObjectOutputStream stream)
throws java.io.IOException
java.io.IOExceptionprivate void readObject(java.io.ObjectInputStream stream)
throws java.io.IOException,
java.lang.ClassNotFoundException
java.io.IOExceptionjava.lang.ClassNotFoundException