- Type Parameters:
K- the type of map keys. The map is invariant on its key type, as it can accept key as a parameter (of containsKey for example) and return it in keys set.V- the type of map values. The map is covariant on its value type.
- All Known Subinterfaces:
PersistentMap<K,V>
A generic immutable collection that holds pairs of objects (keys and values) and supports efficiently retrieving the value corresponding to each key. Map keys are unique; the map holds only one value for each key. Methods in this interface support only read-only access to the immutable map.
Modification operations are supported through the PersistentMap interface.
Implementors of this interface take responsibility to be immutable. Once constructed they must contain the same elements in the same order.
-
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsKey(K key) Returnstrueif the map contains the specifiedkey.booleancontainsValue(V value) Returnstrueif the map maps one or more keys to the specifiedvalue.entries()Returns a read-only Set of all key/value pairs in this map.static <K extends @Nullable Object, V extends @Nullable Object>
ImmutableMap<K, V> Returns an immutable map containing all entries from the specified map.static <K extends @Nullable Object, V extends @Nullable Object>
ImmutableMap<K, V> from(ImmutableMap<K, V> map) Returns an immutable map containing all entries from the specified map.Returns the value corresponding to the givenkey, ornullif such a key is not present in the map.default booleanisEmpty()Returnstrueif the map is empty (contains no elements),falseotherwise.keys()Returns a read-only Set of all keys in this map.intsize()Returns the number of key/value pairs in the map.values()Returns a read-only Collection of all values in this map.
-
Method Details
-
from
static <K extends @Nullable Object, V extends @Nullable Object> ImmutableMap<K,V> from(ImmutableMap<K, V> map) Returns an immutable map containing all entries from the specified map.
If the specified map is already an immutable map, returns it as is.
Entries of the returned map are iterated in the same order as in the specified map.
-
from
static <K extends @Nullable Object, V extends @Nullable Object> ImmutableMap<K,V> from(Map<K, V> map) Returns an immutable map containing all entries from the specified map.
If the specified map is already an immutable map, returns it as is.
Entries of the returned map are iterated in the same order as in the specified map.
-
size
int size()Returns the number of key/value pairs in the map.
If a map contains more than
Int.MAX_VALUEelements, the value of this property is unspecified. For implementations allowing to have more thanInt.MAX_VALUEelements, it is recommended to explicitly document behavior of this property. -
isEmpty
default boolean isEmpty()Returnstrueif the map is empty (contains no elements),falseotherwise. -
containsKey
Returnstrueif the map contains the specifiedkey. -
containsValue
Returnstrueif the map maps one or more keys to the specifiedvalue. -
get
Returns the value corresponding to the given
key, ornullif such a key is not present in the map.Note that for maps supporting
nullvalues, the returnednullvalue associated with thekeyis indistinguishable from the missingkey, so containsKey should be used to check if the map actually contains thekey. -
keys
ImmutableSet<K> keys()Returns a read-only Set of all keys in this map. -
values
ImmutableCollection<V> values()Returns a read-only Collection of all values in this map. Note that this collection may contain duplicate values. -
entries
ImmutableSet<Map.Entry<K,V>> entries()Returns a read-only Set of all key/value pairs in this map.
-