Top Description Inners Fields Constructors Methods
com.google.common.collect

pack-priv final Class RegularImmutableMap<K, V>

extends ImmutableMap<K, V>
Class Inheritance
Annotations
@GwtCompatible
serializable:true
emulated:true
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkNotNull, .Preconditions.checkPositionIndex, com.google.common.collect.CollectPreconditions.checkEntryNotNull, .ImmutableMapEntry.createEntryArray, java.util.Objects.requireNonNull

Implementation of ImmutableMap with two or more entries.
Authors
Jesse Wilson, Kevin Bourrillion, Gregory Kick

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
pack-priv static final ImmutableMap<Object, Object>
pack-priv final transient Map.Entry<K, V>[]
pack-priv static final double
HASH_FLOODING_FPP

Maximum allowed false positive probability of detecting a hash flooding attack given random input.

private final transient int
pack-priv static final int
MAX_HASH_BUCKET_LENGTH

Maximum allowed length of a hash table bucket before falling back to a j.u.HashMap based implementation.

pack-priv static final double
MAX_LOAD_FACTOR

Closed addressing tends to perform well even with high load factors.

private static final long
private final transient @Nullable ImmutableMapEntry<K, V>[]
Inherited from com.google.common.collect.ImmutableMap:
EMPTY_ENTRY_ARRAY

Constructor Summary

AccessConstructor and Description
private
RegularImmutableMap(Map.Entry<K, V>[] entries, @Nullable ImmutableMapEntry<K, V>[] table, int mask)

Method Summary

Modifier and TypeMethod and Description
pack-priv static <K, V> ImmutableMapEntry<K, V>
checkNoConflictInKeyBucket(Object key, Object newValue, ImmutableMapEntry<K, V> keyBucketHead, boolean throwIfDuplicateKeys)

Checks if the given key already appears in the hash chain starting at keyBucketHead.

pack-priv ImmutableSet<Map.Entry<K, V>>
pack-priv ImmutableSet<K>
pack-priv ImmutableCollection<V>
public void
forEach(BiConsumer<? super K, ? super V>
The action to be performed for each entry
action
)

Overrides default java.util.Map.forEach.

Performs the given action for each entry in this map until all entries have been processed or the action throws an exception.
pack-priv static <K, V> ImmutableMap<K, V>
fromEntries(Map.Entry<K, V>... entries)

pack-priv static <K, V> ImmutableMap<K, V>
fromEntryArray(int n, @Nullable Map.Entry<K, V>[] entryArray, boolean throwIfDuplicateKeys)

Creates an ImmutableMap from the first n entries in entryArray.

private static <K, V> ImmutableMap<K, V>
fromEntryArrayCheckingBucketOverflow(int n, @Nullable Map.Entry<K, V>[] entryArray, boolean throwIfDuplicateKeys)

public V
get(Object
the key whose associated value is to be returned
key
)

Implements abstract com.google.common.collect.ImmutableMap.get.

Implements java.util.Map.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
pack-priv static <V> V
get(Object key, @Nullable ImmutableMapEntry<?, V>[] keyTable, int mask)

pack-priv boolean
pack-priv static <K, V> ImmutableMapEntry<K, V>
makeImmutable(Map.Entry<K, V> entry, K key, V value)

Makes an entry usable internally by a new ImmutableMap without rereading its contents.

pack-priv static <K, V> ImmutableMapEntry<K, V>
makeImmutable(Map.Entry<K, V> entry)

Makes an entry usable internally by a new ImmutableMap.

pack-priv static <K, V> Map.Entry<K, V>[]

Returns:

an array of newN entries where no key appears more than once.
removeDuplicates
(Map.Entry<K, V>[]
the original array of entries including duplicates
entries
,
int
the number of valid entries in entries
n
,
int
the expected number of entries once duplicates are removed
newN
,
IdentityHashMap<Map.Entry<K, V>, Boolean>
a map of canonical Entry objects for each duplicate key. This map will be updated by the method, setting each value to false as soon as the Entry has been included in the new entry array.
duplicates
)

Constructs a new entry array where each duplicated key from the original appears only once, at its first position but with its final value.

public int
size()

Implements java.util.Map.size.

Returns the number of key-value mappings in this map.
pack-priv Object
writeReplace()

Overrides com.google.common.collect.ImmutableMap.writeReplace.

Returns a serializable form of this object.
Inherited from com.google.common.collect.ImmutableMap:
asMultimapbuilderbuilderWithExpectedSizecheckNoConflictclearcomputecomputeIfAbsentcomputeIfPresentconflictExceptioncontainsKeycontainsValuecopyOfcopyOfentryOfentrySetequalsgetOrDefaulthashCodeisEmptyisHashCodeFastkeyIteratorkeySetkeySpliteratormergeofofofofofofofofofofofofEntriesputputAllputIfAbsentremoveremovereplacereplacereplaceAlltoImmutableMaptoImmutableMaptoStringvalues

Field Detail

EMPTYback to summary
pack-priv static final ImmutableMap<Object, Object> EMPTY
Annotations
@SuppressWarnings:unchecked
entriesback to summary
pack-priv final transient Map.Entry<K, V>[] entries
Annotations
@VisibleForTesting
HASH_FLOODING_FPPback to summary
pack-priv static final double HASH_FLOODING_FPP

Maximum allowed false positive probability of detecting a hash flooding attack given random input.

Annotations
@VisibleForTesting
maskback to summary
private final transient int mask
MAX_HASH_BUCKET_LENGTHback to summary
pack-priv static final int MAX_HASH_BUCKET_LENGTH

Maximum allowed length of a hash table bucket before falling back to a j.u.HashMap based implementation. Experimentally determined.

Annotations
@VisibleForTesting
MAX_LOAD_FACTORback to summary
pack-priv static final double MAX_LOAD_FACTOR

Closed 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.

Annotations
@VisibleForTesting
serialVersionUIDback to summary
private static final long serialVersionUID

Hides com.google.common.collect.ImmutableMap.serialVersionUID.

Annotations
@J2ktIncompatible
tableback to summary
private final transient @Nullable ImmutableMapEntry<K, V>[] table
Annotations
@CheckForNull

Constructor Detail

RegularImmutableMapback to summary
private RegularImmutableMap(Map.Entry<K, V>[] entries, @Nullable ImmutableMapEntry<K, V>[] table, int mask)

Method Detail

checkNoConflictInKeyBucketback to summary
pack-priv static <K, V> ImmutableMapEntry<K, V> checkNoConflictInKeyBucket(Object key, Object newValue, ImmutableMapEntry<K, V> keyBucketHead, boolean throwIfDuplicateKeys) throws BucketOverflowException

Checks if the given key already appears in the hash chain starting at keyBucketHead. If it does not, then null is returned. If it does, then if throwIfDuplicateKeys is true an IllegalArgumentException is thrown, and otherwise the existing Entry is returned.

Annotations
@CanIgnoreReturnValue
@CheckForNull
Exceptions
BucketOverflowException:
if this bucket has too many entries, which may indicate a hash flooding attack
IllegalArgumentException:
if another entry in the bucket has the same key and throwIfDuplicateKeys is true
createEntrySetback to summary
pack-priv ImmutableSet<Map.Entry<K, V>> createEntrySet()

Implements abstract com.google.common.collect.ImmutableMap.createEntrySet.

Annotations
@Override
createKeySetback to summary
pack-priv ImmutableSet<K> createKeySet()

Implements abstract com.google.common.collect.ImmutableMap.createKeySet.

Annotations
@Override
createValuesback to summary
pack-priv ImmutableCollection<V> createValues()

Implements abstract com.google.common.collect.ImmutableMap.createValues.

Annotations
@Override
forEachback to summary
public void forEach(BiConsumer<? super K, ? super V> action)

Overrides default java.util.Map.forEach.

Doc from java.util.Map.forEach.

Performs the given action for each entry in this map until all entries have been processed or the action throws an exception. Unless otherwise specified by the implementing class, actions are performed in the order of entry set iteration (if an iteration order is specified.) Exceptions thrown by the action are relayed to the caller.

Parameters
action:BiConsumer<? super K, ? super V>

The action to be performed for each entry

Annotations
@Override
fromEntriesback to summary
pack-priv static <K, V> ImmutableMap<K, V> fromEntries(Map.Entry<K, V>... entries)
fromEntryArrayback to summary
pack-priv static <K, V> ImmutableMap<K, V> fromEntryArray(int n, @Nullable Map.Entry<K, V>[] entryArray, boolean throwIfDuplicateKeys)

Creates an ImmutableMap from the first n entries in entryArray. This implementation may replace the entries in entryArray with its own entry objects (though they will have the same key/value contents), and may take ownership of entryArray.

fromEntryArrayCheckingBucketOverflowback to summary
private static <K, V> ImmutableMap<K, V> fromEntryArrayCheckingBucketOverflow(int n, @Nullable Map.Entry<K, V>[] entryArray, boolean throwIfDuplicateKeys) throws BucketOverflowException
getback to summary
public V get(Object key)

Implements abstract com.google.common.collect.ImmutableMap.get.

Implements java.util.Map.get.

Doc from java.util.Map.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

More formally, if this map contains a mapping from a key k to a value v such that Objects.equals(key, k), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

If this map permits null values, then a return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

Parameters
key:Object

the key whose associated value is to be returned

Returns:V

the value to which the specified key is mapped, or null if this map contains no mapping for the key

Annotations
@Override
@CheckForNull
getback to summary
pack-priv static <V> V get(Object key, @Nullable ImmutableMapEntry<?, V>[] keyTable, int mask)
Annotations
@CheckForNull
isPartialViewback to summary
pack-priv boolean isPartialView()

Implements abstract com.google.common.collect.ImmutableMap.isPartialView.

Annotations
@Override
makeImmutableback to summary
pack-priv static <K, V> ImmutableMapEntry<K, V> makeImmutable(Map.Entry<K, V> entry, K key, V value)

Makes an entry usable internally by a new ImmutableMap without rereading its contents.

makeImmutableback to summary
pack-priv static <K, V> ImmutableMapEntry<K, V> makeImmutable(Map.Entry<K, V> entry)

Makes an entry usable internally by a new ImmutableMap.

removeDuplicatesback to summary
pack-priv static <K, V> Map.Entry<K, V>[] removeDuplicates(Map.Entry<K, V>[] entries, int n, int newN, IdentityHashMap<Map.Entry<K, V>, Boolean> duplicates)

Constructs a new entry array where each duplicated key from the original appears only once, at its first position but with its final value. The duplicates map is modified.

Parameters
entries:Map.Entry<K, V>[]

the original array of entries including duplicates

n:int

the number of valid entries in entries

newN:int

the expected number of entries once duplicates are removed

duplicates:IdentityHashMap<Map.Entry<K, V>, Boolean>

a map of canonical Entry objects for each duplicate key. This map will be updated by the method, setting each value to false as soon as the Entry has been included in the new entry array.

Returns:Map.Entry<K, V>[]

an array of newN entries where no key appears more than once.

sizeback to summary
public int size()

Implements java.util.Map.size.

Doc from java.util.Map.size.

Returns the number of key-value mappings in this map. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of key-value mappings in this map

Annotations
@Override
writeReplaceback to summary
pack-priv Object writeReplace()

Overrides com.google.common.collect.ImmutableMap.writeReplace.

Doc from com.google.common.collect.ImmutableMap.writeReplace.

Returns a serializable form of this object. Non-public subclasses should not override this method. Publicly-accessible subclasses must override this method and should return a subclass of SerializedForm whose readResolve() method returns objects of the subclass type.

Annotations
@SuppressWarnings:RedundantOverride
@Override
@J2ktIncompatible
@GwtIncompatible
com.google.common.collect back to summary

pack-priv Class RegularImmutableMap.BucketOverflowException

extends Exception
Class Inheritance

Constructor Summary

AccessConstructor and Description
pack-priv

Constructor Detail

BucketOverflowExceptionback to summary
pack-priv BucketOverflowException()
com.google.common.collect back to summary

private final Class RegularImmutableMap.KeySet<K>

extends IndexedImmutableSet<K>
Class Inheritance
Annotations
@GwtCompatible
emulated:true

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final RegularImmutableMap<K, ?>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
contains(Object
element whose presence in this set is to be tested
object
)

Implements abstract com.google.common.collect.ImmutableCollection.contains.

Implements java.util.Set.contains, java.util.Collection.contains.

Returns true if this set contains the specified element.
pack-priv K
pack-priv boolean
isPartialView()

Implements abstract com.google.common.collect.ImmutableCollection.isPartialView.

Returns true if this immutable collection's implementation contains references to user-created objects that aren't accessible via this collection's methods.
public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Set.size, java.util.Collection.size.

Returns the number of elements in this set (its cardinality).
pack-priv Object
Inherited from com.google.common.collect.IndexedImmutableSet:
copyIntoArraycreateAsListforEachiteratorspliterator

Field Detail

mapback to summary
private final RegularImmutableMap<K, ?> map

Constructor Detail

KeySetback to summary
pack-priv KeySet(RegularImmutableMap<K, ?> map)

Method Detail

containsback to summary
public boolean contains(Object object)

Implements abstract com.google.common.collect.ImmutableCollection.contains.

Implements java.util.Set.contains, java.util.Collection.contains.

Doc from java.util.Set.contains.

Returns true if this set contains the specified element. More formally, returns true if and only if this set contains an element e such that Objects.equals(o, e).

Parameters
object:Object

element whose presence in this set is to be tested

Returns:boolean

true if this set contains the specified element

Annotations
@Override
getback to summary
pack-priv K get(int index)

Implements abstract com.google.common.collect.IndexedImmutableSet.get.

Annotations
@Override
isPartialViewback to summary
pack-priv boolean isPartialView()

Implements abstract com.google.common.collect.ImmutableCollection.isPartialView.

Doc from com.google.common.collect.ImmutableCollection.isPartialView.

Returns 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.

Annotations
@Override
sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Set.size, java.util.Collection.size.

Doc from java.util.Set.size.

Returns the number of elements in this set (its cardinality). If this set contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of elements in this set (its cardinality)

Annotations
@Override
writeReplaceback to summary
pack-priv Object writeReplace()

Overrides com.google.common.collect.IndexedImmutableSet.writeReplace.

Annotations
@SuppressWarnings:RedundantOverride
@Override
@J2ktIncompatible
@GwtIncompatible
com.google.common.collect back to summary

private Class RegularImmutableMap.KeySet.SerializedForm<K>

extends Object
implements Serializable
Class Inheritance
  • java.lang.Object
  • com.google.common.collect.RegularImmutableMap.KeySet.SerializedForm
All Implemented Interfaces
java.io.Serializable
Annotations
@GwtIncompatible
@J2ktIncompatible
@SuppressWarnings:unused

Field Summary

Modifier and TypeField and Description
pack-priv final ImmutableMap<K, ?>
private static final long

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv Object
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

mapback to summary
pack-priv final ImmutableMap<K, ?> map
serialVersionUIDback to summary
private static final long serialVersionUID
Annotations
@J2ktIncompatible

Constructor Detail

SerializedFormback to summary
pack-priv SerializedForm(ImmutableMap<K, ?> map)

Method Detail

readResolveback to summary
pack-priv Object readResolve()
com.google.common.collect back to summary

private final Class RegularImmutableMap.Values<K, V>

extends ImmutableList<V>
Class Inheritance
Annotations
@GwtCompatible
emulated:true

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
pack-priv final RegularImmutableMap<K, V>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public V
get(int
index of the element to return
index
)

Implements java.util.List.get.

Returns the element at the specified position in this list.
pack-priv boolean
isPartialView()

Implements abstract com.google.common.collect.ImmutableCollection.isPartialView.

Returns true if this immutable collection's implementation contains references to user-created objects that aren't accessible via this collection's methods.
public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Returns the number of elements in this list.
pack-priv Object
Inherited from com.google.common.collect.ImmutableList:
addaddAllasImmutableListasImmutableListasListbuilderbuilderWithExpectedSizecontainscopyIntoArraycopyOfcopyOfcopyOfcopyOfequalsforEachhashCodeindexOfiteratorlastIndexOflistIteratorlistIteratorofofofofofofofofofofofofofremovereplaceAllreversesetsortsortedCopyOfsortedCopyOfspliteratorsubListsubListUncheckedtoImmutableList

Field Detail

mapback to summary
pack-priv final RegularImmutableMap<K, V> map

Constructor Detail

Valuesback to summary
pack-priv Values(RegularImmutableMap<K, V> map)

Method Detail

getback to summary
public V get(int index)

Implements java.util.List.get.

Doc from java.util.List.get.

Returns the element at the specified position in this list.

Parameters
index:int

index of the element to return

Returns:V

the element at the specified position in this list

Annotations
@Override
isPartialViewback to summary
pack-priv boolean isPartialView()

Implements abstract com.google.common.collect.ImmutableCollection.isPartialView.

Doc from com.google.common.collect.ImmutableCollection.isPartialView.

Returns 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.

Annotations
@Override
sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Doc from java.util.List.size.

Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of elements in this list

Annotations
@Override
writeReplaceback to summary
pack-priv Object writeReplace()

Overrides com.google.common.collect.ImmutableList.writeReplace.

Annotations
@SuppressWarnings:RedundantOverride
@Override
@J2ktIncompatible
@GwtIncompatible
com.google.common.collect back to summary

private Class RegularImmutableMap.Values.SerializedForm<V>

extends Object
implements Serializable
Class Inheritance
  • java.lang.Object
  • com.google.common.collect.RegularImmutableMap.Values.SerializedForm
All Implemented Interfaces
java.io.Serializable
Annotations
@GwtIncompatible
@J2ktIncompatible
@SuppressWarnings:unused

Field Summary

Modifier and TypeField and Description
pack-priv final ImmutableMap<?, V>
private static final long

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv Object
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

mapback to summary
pack-priv final ImmutableMap<?, V> map
serialVersionUIDback to summary
private static final long serialVersionUID
Annotations
@J2ktIncompatible

Constructor Detail

SerializedFormback to summary
pack-priv SerializedForm(ImmutableMap<?, V> map)

Method Detail

readResolveback to summary
pack-priv Object readResolve()