Package com.google.common.collect
Class JdkBackedImmutableMultiset<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- com.google.common.collect.ImmutableCollection<E>
-
- com.google.common.collect.ImmutableMultisetGwtSerializationDependencies<E>
-
- com.google.common.collect.ImmutableMultiset<E>
-
- com.google.common.collect.JdkBackedImmutableMultiset<E>
-
- All Implemented Interfaces:
Multiset<E>,java.io.Serializable,java.lang.Iterable<E>,java.util.Collection<E>
final class JdkBackedImmutableMultiset<E> extends ImmutableMultiset<E>
An implementation of ImmutableMultiset backed by a JDK Map and a list of entries. Used to protect against hash flooding attacks.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.common.collect.ImmutableMultiset
ImmutableMultiset.Builder<E>, ImmutableMultiset.ElementSet<E>, ImmutableMultiset.EntrySetSerializedForm<E>, ImmutableMultiset.SerializedForm
-
Nested classes/interfaces inherited from interface com.google.common.collect.Multiset
Multiset.Entry<E>
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<E,java.lang.Integer>delegateMapprivate ImmutableSet<E>elementSetprivate ImmutableList<Multiset.Entry<E>>entriesprivate longsize-
Fields inherited from class com.google.common.collect.ImmutableCollection
SPLITERATOR_CHARACTERISTICS
-
-
Constructor Summary
Constructors Modifier Constructor Description privateJdkBackedImmutableMultiset(java.util.Map<E,java.lang.Integer> delegateMap, ImmutableList<Multiset.Entry<E>> entries, long size)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcount(java.lang.Object element)Returns the number of occurrences of an element in this multiset (the count of the element).(package private) static <E> ImmutableMultiset<E>create(java.util.Collection<? extends Multiset.Entry<? extends E>> entries)ImmutableSet<E>elementSet()Returns the set of distinct elements contained in this multiset.(package private) Multiset.Entry<E>getEntry(int index)(package private) booleanisPartialView()Returnstrueif this immutable collection's implementation contains references to user-created objects that aren't accessible via this collection's methods.intsize()Returns the total number of all occurrences of all elements in this multiset.-
Methods inherited from class com.google.common.collect.ImmutableMultiset
add, asList, builder, contains, copyFromEntries, copyIntoArray, copyOf, copyOf, copyOf, entrySet, equals, hashCode, iterator, of, of, of, of, of, of, of, remove, setCount, setCount, toImmutableMultiset, toImmutableMultiset, toString, writeReplace
-
Methods inherited from class com.google.common.collect.ImmutableCollection
add, addAll, clear, internalArray, internalArrayEnd, internalArrayStart, remove, removeAll, removeIf, retainAll, spliterator, toArray, toArray
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
addAll, clear, isEmpty, parallelStream, removeIf, stream, toArray, toArray, toArray
-
Methods inherited from interface com.google.common.collect.Multiset
add, containsAll, forEach, forEachEntry, remove, removeAll, retainAll, spliterator
-
-
-
-
Field Detail
-
delegateMap
private final java.util.Map<E,java.lang.Integer> delegateMap
-
entries
private final ImmutableList<Multiset.Entry<E>> entries
-
size
private final long size
-
elementSet
private transient ImmutableSet<E> elementSet
-
-
Constructor Detail
-
JdkBackedImmutableMultiset
private JdkBackedImmutableMultiset(java.util.Map<E,java.lang.Integer> delegateMap, ImmutableList<Multiset.Entry<E>> entries, long size)
-
-
Method Detail
-
create
static <E> ImmutableMultiset<E> create(java.util.Collection<? extends Multiset.Entry<? extends E>> entries)
-
count
public int count(java.lang.Object element)
Description copied from interface:MultisetReturns 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
-
elementSet
public ImmutableSet<E> elementSet()
Description copied from interface:MultisetReturns 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().- Specified by:
elementSetin interfaceMultiset<E>- Specified by:
elementSetin classImmutableMultiset<E>- Returns:
- a view of the set of distinct elements in this multiset
-
getEntry
Multiset.Entry<E> getEntry(int index)
- Specified by:
getEntryin classImmutableMultiset<E>
-
isPartialView
boolean isPartialView()
Description copied from class:ImmutableCollectionReturnstrueif 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 whethercopyOfimplementations should make an explicit copy to avoid memory leaks.- Specified by:
isPartialViewin classImmutableCollection<E>
-
size
public int size()
Description copied from interface:MultisetReturns the total number of all occurrences of all elements in this multiset.Note: this method does not return the number of distinct elements in the multiset, which is given by
entrySet().size().
-
-