Class RegularImmutableMultiset<E>
- All Implemented Interfaces:
Multiset<E>
,Serializable
,Iterable<E>
,Collection<E>
ImmutableMultiset
with zero or more elements.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
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
FieldsModifier and TypeFieldDescriptionprivate ImmutableSet
<E> (package private) static final ImmutableMultiset
<Object> private static final Multisets.ImmutableEntry<?>[]
private final Multisets.ImmutableEntry<E>[]
(package private) static final double
Maximum allowed false positive probability of detecting a hash flooding attack given random input.private final int
private final Multisets.ImmutableEntry<?>[]
(package private) static final int
Maximum allowed length of a hash table bucket before falling back to a j.u.HashMap based implementation.(package private) static final double
Closed addressing tends to perform well even with high load factors.private final int
Fields inherited from class com.google.common.collect.ImmutableCollection
SPLITERATOR_CHARACTERISTICS
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
RegularImmutableMultiset
(Multisets.ImmutableEntry<E>[] entries, Multisets.ImmutableEntry<?>[] hashTable, int size, int hashCode, ImmutableSet<E> elementSet) -
Method Summary
Modifier and TypeMethodDescriptionint
Returns the number of occurrences of an element in this multiset (the count of the element).(package private) static <E> ImmutableMultiset
<E> create
(Collection<? extends Multiset.Entry<? extends E>> entries) 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.private static boolean
hashFloodingDetected
(Multisets.ImmutableEntry<?>[] hashTable) (package private) boolean
Returnstrue
if this immutable collection's implementation contains references to user-created objects that aren't accessible via this collection's methods.int
size()
Returns the total number of all occurrences of all elements in this multiset.(package private) Object
Methods inherited from class com.google.common.collect.ImmutableMultiset
add, asList, builder, contains, copyFromEntries, copyIntoArray, copyOf, copyOf, copyOf, entrySet, equals, iterator, of, of, of, of, of, of, of, remove, setCount, setCount, toImmutableMultiset, toImmutableMultiset, toString
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.util.AbstractCollection
containsAll, isEmpty
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 Details
-
EMPTY_ARRAY
-
EMPTY
-
MAX_LOAD_FACTOR
static final double MAX_LOAD_FACTORClosed addressing tends to perform well even with high load factors. Being conservative here ensures that the table is still likely to be relatively sparse (hence it misses fast) while saving space.- See Also:
-
HASH_FLOODING_FPP
static final double HASH_FLOODING_FPPMaximum allowed false positive probability of detecting a hash flooding attack given random input.- See Also:
-
MAX_HASH_BUCKET_LENGTH
static final int MAX_HASH_BUCKET_LENGTHMaximum allowed length of a hash table bucket before falling back to a j.u.HashMap based implementation. Experimentally determined.- See Also:
-
entries
-
hashTable
-
size
private final transient int size -
hashCode
private final transient int hashCode -
elementSet
-
-
Constructor Details
-
RegularImmutableMultiset
private RegularImmutableMultiset(Multisets.ImmutableEntry<E>[] entries, Multisets.ImmutableEntry<?>[] hashTable, int size, int hashCode, @CheckForNull ImmutableSet<E> elementSet)
-
-
Method Details
-
create
-
hashFloodingDetected
-
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
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()Description copied from interface:Multiset
Returns 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()
.- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceMultiset<E>
- Specified by:
size
in classAbstractCollection<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()
.- Specified by:
elementSet
in interfaceMultiset<E>
- Specified by:
elementSet
in classImmutableMultiset<E>
- Returns:
- a view of the set of distinct elements in this multiset
-
getEntry
- 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.
- Specified by:
hashCode
in interfaceCollection<E>
- Specified by:
hashCode
in interfaceMultiset<E>
- Overrides:
hashCode
in classImmutableMultiset<E>
-
writeReplace
Object writeReplace()- Overrides:
writeReplace
in classImmutableMultiset<E>
-