Interface ImmutableMap<K extends @Nullable Object, V extends @Nullable Object>

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>

public interface ImmutableMap<K extends @Nullable Object, V extends @Nullable Object>

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 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_VALUE elements, the value of this property is unspecified. For implementations allowing to have more than Int.MAX_VALUE elements, it is recommended to explicitly document behavior of this property.

    • isEmpty

      default boolean isEmpty()
      Returns true if the map is empty (contains no elements), false otherwise.
    • containsKey

      boolean containsKey(K key)
      Returns true if the map contains the specified key.
    • containsValue

      boolean containsValue(V value)
      Returns true if the map maps one or more keys to the specified value.
    • get

      @Nullable V get(K key)

      Returns the value corresponding to the given key, or null if such a key is not present in the map.

      Note that for maps supporting null values, the returned null value associated with the key is indistinguishable from the missing key, so containsKey should be used to check if the map actually contains the key.

    • keys

      ImmutableSet<K> keys()
      Returns a read-only Set of all keys in this map.
    • 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.