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

public abstract Class ImmutableMap<K, V>

extends Object
implements Map<K, V>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.util.Map
Known Direct Subclasses
com.google.common.collect.ImmutableMap.IteratorBasedImmutableMap, com.google.common.collect.ImmutableSortedMap, com.google.common.collect.JdkBackedImmutableMap, com.google.common.collect.RegularImmutableMap, com.google.common.collect.ImmutableBiMap
Annotations
@DoNotMock:Use ImmutableMap.of or another implementation
@GwtCompatible
serializable:true
emulated:true
@SuppressWarnings:serial
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkNotNull, .Preconditions.checkState, com.google.common.collect.CollectPreconditions.checkEntryNotNull, .CollectPreconditions.checkNonnegative, java.util.Objects.requireNonNull

A Map whose contents will never change, with many other important properties detailed at ImmutableCollection.

See the Guava User Guide article on immutable collections.

Authors
Jesse Wilson, Kevin Bourrillion
Since
2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ImmutableMap.Builder<K, V>

A builder for creating immutable map instances, especially public static final maps ("constant maps").

pack-priv abstract static class
private class
pack-priv static class
ImmutableMap.SerializedForm<K, V>

Serialized type for all ImmutableMap instances.

Field Summary

Modifier and TypeField and Description
pack-priv static final Map.Entry<?, ?>[]
private transient ImmutableSet<Map.Entry<K, V>>
private transient ImmutableSet<K>
private transient ImmutableSetMultimap<K, V>
private static final long
private transient ImmutableCollection<V>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public ImmutableSetMultimap<K, V>
asMultimap()

Returns a multimap view of the map.

public static <K, V> ImmutableMap.Builder<K, V>
builder()

Returns a new builder.

public static <K, V> ImmutableMap.Builder<K, V>
builderWithExpectedSize(int expectedSize)

Returns a new builder, expecting the specified number of entries to be added.

pack-priv static void
checkNoConflict(boolean safe, String conflictDescription, Object entry1, Object entry2)

public final void
clear()

Implements java.util.Map.clear.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the map unmodified.
public final V
compute(K
key with which the specified value is to be associated
key
,
BiFunction<? super K, ? super @Nullable V, ? extends @Nullable V>
the remapping function to compute a value
remappingFunction
)

Overrides default java.util.Map.compute.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the map unmodified.
public final V
computeIfAbsent(K
key with which the specified value is to be associated
key
,
Function<? super K, ? extends V>
the mapping function to compute a value
mappingFunction
)

Overrides default java.util.Map.computeIfAbsent.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the map unmodified.
public final V
computeIfPresent(K
key with which the specified value is to be associated
key
,
BiFunction<? super K, ? super V, ? extends @Nullable V>
the remapping function to compute a value
remappingFunction
)

Overrides default java.util.Map.computeIfPresent.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the map unmodified.
pack-priv static IllegalArgumentException
conflictException(String conflictDescription, Object entry1, Object entry2)

public boolean
containsKey(Object
key whose presence in this map is to be tested
key
)

Implements java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key.
public boolean
containsValue(Object
value whose presence in this map is to be tested
value
)

Implements java.util.Map.containsValue.

Returns true if this map maps one or more keys to the specified value.
public static <K, V> ImmutableMap<K, V>
copyOf(Map<? extends K, ? extends V>
a Map from which entries are drawn, must be non-null
map
)

Hides java.util.Map.copyOf.

Returns an immutable map containing the same entries as map.
public static <K, V> ImmutableMap<K, V>
copyOf(Iterable<? extends Map.Entry<? extends K, ? extends V>> entries)

Returns an immutable map containing the specified entries.

private static <K extends Enum<K>, V> ImmutableMap<K, ? extends V>
copyOfEnumMap(EnumMap<?, ? extends V> original)

pack-priv abstract ImmutableSet<Map.Entry<K, V>>
pack-priv abstract ImmutableSet<K>
pack-priv abstract ImmutableCollection<V>
pack-priv static <K, V> Map.Entry<K, V>
entryOf(K key, V value)

Verifies that key and value are non-null, and returns a new immutable entry with those values.

public ImmutableSet<Map.Entry<K, V>>
entrySet()

Implements java.util.Map.entrySet.

Returns an immutable set of the mappings in this map.
public boolean
equals(Object
object to be compared for equality with this map
object
)

Overrides java.lang.Object.equals.

Implements java.util.Map.equals.

Compares the specified object with this map for equality.
public abstract V
get(Object
the key whose associated value is to be returned
key
)

Redeclares 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.
public final V
getOrDefault(Object
the key whose associated value is to be returned
key
,
V
the default mapping of the key
defaultValue
)

Overrides default java.util.Map.getOrDefault.

Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Map.hashCode.

Returns the hash code value for this map.
public boolean
isEmpty()

Implements java.util.Map.isEmpty.

Returns true if this map contains no key-value mappings.
pack-priv boolean
pack-priv abstract boolean
pack-priv UnmodifiableIterator<K>
public ImmutableSet<K>
keySet()

Implements java.util.Map.keySet.

Returns an immutable set of the keys in this map, in the same order that they appear in entrySet.
pack-priv Spliterator<K>
public final V
merge(K
key with which the resulting value is to be associated
key
,
V
the non-null value to be merged with the existing value associated with the key or, if no existing value or a null value is associated with the key, to be associated with the key
value
,
BiFunction<? super V, ? super V, ? extends @Nullable V>
the remapping function to recompute a value if present
function
)

Overrides default java.util.Map.merge.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the map unmodified.
public static <K, V> ImmutableMap<K, V>
of()

Hides java.util.Map.of.

Returns the empty map.
public static <K, V> ImmutableMap<K, V>
of(K
the mapping's key
k1
,
V
the mapping's value
v1
)

Hides java.util.Map.of.

Returns an immutable map containing a single entry.
public static <K, V> ImmutableMap<K, V>
of(K
the first mapping's key
k1
,
V
the first mapping's value
v1
,
K
the second mapping's key
k2
,
V
the second mapping's value
v2
)

Hides java.util.Map.of.

Returns an immutable map containing the given entries, in order.
public static <K, V> ImmutableMap<K, V>
of(K
the first mapping's key
k1
,
V
the first mapping's value
v1
,
K
the second mapping's key
k2
,
V
the second mapping's value
v2
,
K
the third mapping's key
k3
,
V
the third mapping's value
v3
)

Hides java.util.Map.of.

Returns an immutable map containing the given entries, in order.
public static <K, V> ImmutableMap<K, V>
of(K
the first mapping's key
k1
,
V
the first mapping's value
v1
,
K
the second mapping's key
k2
,
V
the second mapping's value
v2
,
K
the third mapping's key
k3
,
V
the third mapping's value
v3
,
K
the fourth mapping's key
k4
,
V
the fourth mapping's value
v4
)

Hides java.util.Map.of.

Returns an immutable map containing the given entries, in order.
public static <K, V> ImmutableMap<K, V>
of(K
the first mapping's key
k1
,
V
the first mapping's value
v1
,
K
the second mapping's key
k2
,
V
the second mapping's value
v2
,
K
the third mapping's key
k3
,
V
the third mapping's value
v3
,
K
the fourth mapping's key
k4
,
V
the fourth mapping's value
v4
,
K
the fifth mapping's key
k5
,
V
the fifth mapping's value
v5
)

Hides java.util.Map.of.

Returns an immutable map containing the given entries, in order.
public static <K, V> ImmutableMap<K, V>
of(K
the first mapping's key
k1
,
V
the first mapping's value
v1
,
K
the second mapping's key
k2
,
V
the second mapping's value
v2
,
K
the third mapping's key
k3
,
V
the third mapping's value
v3
,
K
the fourth mapping's key
k4
,
V
the fourth mapping's value
v4
,
K
the fifth mapping's key
k5
,
V
the fifth mapping's value
v5
,
K
the sixth mapping's key
k6
,
V
the sixth mapping's value
v6
)

Hides java.util.Map.of.

Returns an immutable map containing the given entries, in order.
public static <K, V> ImmutableMap<K, V>
of(K
the first mapping's key
k1
,
V
the first mapping's value
v1
,
K
the second mapping's key
k2
,
V
the second mapping's value
v2
,
K
the third mapping's key
k3
,
V
the third mapping's value
v3
,
K
the fourth mapping's key
k4
,
V
the fourth mapping's value
v4
,
K
the fifth mapping's key
k5
,
V
the fifth mapping's value
v5
,
K
the sixth mapping's key
k6
,
V
the sixth mapping's value
v6
,
K
the seventh mapping's key
k7
,
V
the seventh mapping's value
v7
)

Hides java.util.Map.of.

Returns an immutable map containing the given entries, in order.
public static <K, V> ImmutableMap<K, V>
of(K
the first mapping's key
k1
,
V
the first mapping's value
v1
,
K
the second mapping's key
k2
,
V
the second mapping's value
v2
,
K
the third mapping's key
k3
,
V
the third mapping's value
v3
,
K
the fourth mapping's key
k4
,
V
the fourth mapping's value
v4
,
K
the fifth mapping's key
k5
,
V
the fifth mapping's value
v5
,
K
the sixth mapping's key
k6
,
V
the sixth mapping's value
v6
,
K
the seventh mapping's key
k7
,
V
the seventh mapping's value
v7
,
K
the eighth mapping's key
k8
,
V
the eighth mapping's value
v8
)

Hides java.util.Map.of.

Returns an immutable map containing the given entries, in order.
public static <K, V> ImmutableMap<K, V>
of(K
the first mapping's key
k1
,
V
the first mapping's value
v1
,
K
the second mapping's key
k2
,
V
the second mapping's value
v2
,
K
the third mapping's key
k3
,
V
the third mapping's value
v3
,
K
the fourth mapping's key
k4
,
V
the fourth mapping's value
v4
,
K
the fifth mapping's key
k5
,
V
the fifth mapping's value
v5
,
K
the sixth mapping's key
k6
,
V
the sixth mapping's value
v6
,
K
the seventh mapping's key
k7
,
V
the seventh mapping's value
v7
,
K
the eighth mapping's key
k8
,
V
the eighth mapping's value
v8
,
K
the ninth mapping's key
k9
,
V
the ninth mapping's value
v9
)

Hides java.util.Map.of.

Returns an immutable map containing the given entries, in order.
public static <K, V> ImmutableMap<K, V>
of(K
the first mapping's key
k1
,
V
the first mapping's value
v1
,
K
the second mapping's key
k2
,
V
the second mapping's value
v2
,
K
the third mapping's key
k3
,
V
the third mapping's value
v3
,
K
the fourth mapping's key
k4
,
V
the fourth mapping's value
v4
,
K
the fifth mapping's key
k5
,
V
the fifth mapping's value
v5
,
K
the sixth mapping's key
k6
,
V
the sixth mapping's value
v6
,
K
the seventh mapping's key
k7
,
V
the seventh mapping's value
v7
,
K
the eighth mapping's key
k8
,
V
the eighth mapping's value
v8
,
K
the ninth mapping's key
k9
,
V
the ninth mapping's value
v9
,
K
the tenth mapping's key
k10
,
V
the tenth mapping's value
v10
)

Hides java.util.Map.of.

Returns an immutable map containing the given entries, in order.
public static <K, V> ImmutableMap<K, V>
ofEntries(Map.Entry<? extends K, ? extends V>...
Map.Entrys containing the keys and values from which the map is populated
entries
)

Hides java.util.Map.ofEntries.

Returns an immutable map containing the given entries, in order.
public final V
put(K
key with which the specified value is to be associated
k
,
V
value to be associated with the specified key
v
)

Implements java.util.Map.put.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the map unmodified.
public final void
putAll(Map<? extends K, ? extends V>
mappings to be stored in this map
map
)

Implements java.util.Map.putAll.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the map unmodified.
public final V
putIfAbsent(K
key with which the specified value is to be associated
key
,
V
value to be associated with the specified key
value
)

Overrides default java.util.Map.putIfAbsent.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the map unmodified.
private void
public final V
remove(Object
key whose mapping is to be removed from the map
o
)

Implements java.util.Map.remove.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the map unmodified.
public final boolean
remove(Object
key with which the specified value is associated
key
,
Object
value expected to be associated with the specified key
value
)

Overrides default java.util.Map.remove.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the map unmodified.
public final boolean
replace(K
key with which the specified value is associated
key
,
V
value expected to be associated with the specified key
oldValue
,
V
value to be associated with the specified key
newValue
)

Overrides default java.util.Map.replace.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the map unmodified.
public final V
replace(K
key with which the specified value is associated
key
,
V
value to be associated with the specified key
value
)

Overrides default java.util.Map.replace.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the map unmodified.
public final void
replaceAll(BiFunction<? super K, ? super V, ? extends V>
the function to apply to each entry
function
)

Overrides default java.util.Map.replaceAll.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the map unmodified.
public static <T extends @Nullable Object, K, V> Collector<T, ?, ImmutableMap<K, V>>
toImmutableMap(Function<? super T, ? extends K> keyFunction, Function<? super T, ? extends V> valueFunction)

Returns a Collector that accumulates elements into an ImmutableMap whose keys and values are the result of applying the provided mapping functions to the input elements.

public static <T extends @Nullable Object, K, V> Collector<T, ?, ImmutableMap<K, V>>
toImmutableMap(Function<? super T, ? extends K> keyFunction, Function<? super T, ? extends V> valueFunction, BinaryOperator<V> mergeFunction)

Returns a Collector that accumulates elements into an ImmutableMap whose keys and values are the result of applying the provided mapping functions to the input elements.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public ImmutableCollection<V>
values()

Implements java.util.Map.values.

Returns an immutable collection of the values in this map, in the same order that they appear in entrySet.
pack-priv Object
writeReplace()

Returns a serializable form of this object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait