Package com.google.common.collect
Class RegularImmutableMultiset<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- com.google.common.collect.ImmutableCollection<E>
-
- com.google.common.collect.ImmutableMultiset<E>
-
- com.google.common.collect.RegularImmutableMultiset<E>
-
- All Implemented Interfaces:
Multiset<E>
,java.io.Serializable
,java.lang.Iterable<E>
,java.util.Collection<E>
@GwtCompatible(serializable=true) class RegularImmutableMultiset<E> extends ImmutableMultiset<E>
Implementation ofImmutableMultiset
with zero or more elements.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
RegularImmutableMultiset.ElementSet
private static class
RegularImmutableMultiset.NonTerminalEntry<E>
-
Nested classes/interfaces inherited from class com.google.common.collect.ImmutableMultiset
ImmutableMultiset.Builder<E>, ImmutableMultiset.EntrySetSerializedForm<E>
-
Nested classes/interfaces inherited from class com.google.common.collect.ImmutableCollection
ImmutableCollection.ArrayBasedBuilder<E>
-
Nested classes/interfaces inherited from interface com.google.common.collect.Multiset
Multiset.Entry<E>
-
-
Field Summary
Fields Modifier and Type Field Description private ImmutableSet<E>
elementSet
(package private) static RegularImmutableMultiset<java.lang.Object>
EMPTY
private Multisets.ImmutableEntry<E>[]
entries
private int
hashCode
private Multisets.ImmutableEntry<E>[]
hashTable
private int
size
-
Constructor Summary
Constructors Constructor Description RegularImmutableMultiset(java.util.Collection<? extends Multiset.Entry<? extends E>> entries)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
count(java.lang.Object element)
Returns the number of occurrences of an element in this multiset (the count of the element).ImmutableSet<E>
elementSet()
Returns the set of distinct elements contained in this multiset.(package private) Multiset.Entry<E>
getEntry(int index)
int
hashCode()
Returns the hash code for this multiset.(package private) boolean
isPartialView()
Returnstrue
if this immutable collection's implementation contains references to user-created objects that aren't accessible via this collection's methods.int
size()
-
Methods inherited from class com.google.common.collect.ImmutableMultiset
add, asList, builder, contains, copyFromEntries, copyIntoArray, copyOf, copyOf, copyOf, createAsList, entrySet, equals, iterator, of, of, of, of, of, of, of, remove, setCount, setCount, toString, writeReplace
-
Methods inherited from class com.google.common.collect.ImmutableCollection
add, addAll, clear, remove, removeAll, retainAll, toArray, toArray
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
-
-
-
Field Detail
-
EMPTY
static final RegularImmutableMultiset<java.lang.Object> EMPTY
-
entries
private final transient Multisets.ImmutableEntry<E>[] entries
-
hashTable
private final transient Multisets.ImmutableEntry<E>[] hashTable
-
size
private final transient int size
-
hashCode
private final transient int hashCode
-
elementSet
private transient ImmutableSet<E> elementSet
-
-
Constructor Detail
-
RegularImmutableMultiset
RegularImmutableMultiset(java.util.Collection<? extends Multiset.Entry<? extends E>> entries)
-
-
Method Detail
-
isPartialView
boolean isPartialView()
Description copied from class:ImmutableCollection
Returnstrue
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 whethercopyOf
implementations should make an explicit copy to avoid memory leaks.- Specified by:
isPartialView
in classImmutableCollection<E>
-
count
public int count(@Nullable java.lang.Object element)
Description copied from interface:Multiset
Returns the number of occurrences of an element in this multiset (the count of the element). Note that for anObject.equals(java.lang.Object)
-based multiset, this gives the same result asCollections.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.- Parameters:
element
- the element to count occurrences of- Returns:
- the number of occurrences of the element in this multiset; possibly zero but never negative
-
size
public int size()
-
elementSet
public ImmutableSet<E> elementSet()
Description copied from interface:Multiset
Returns the set of distinct elements contained in this multiset. The element set is backed by the same data as the multiset, so any change to either is immediately reflected in the other. The order of the elements in the element set is unspecified.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()
.- Returns:
- a view of the set of distinct elements in this multiset
-
getEntry
Multiset.Entry<E> getEntry(int index)
- Specified by:
getEntry
in classImmutableMultiset<E>
-
hashCode
public int hashCode()
Description copied from interface:Multiset
Returns the hash code for this multiset. This is defined as the sum of((element == null) ? 0 : element.hashCode()) ^ count(element)
over all distinct elements in the multiset. It follows that a multiset and its entry set always have the same hash code.
-
-