Interface ImmutableMap<K,V>

Type Parameters:
K - the key type
V - the value type
All Superinterfaces:
Iterable<Map.Entry<K,V>>, ReadOnlyMap<K,V>
All Known Subinterfaces:
ImmutableNavigableMap<K,V>, ImmutableSequencedMap<K,V>, ImmutableSortedMap<K,V>
All Known Implementing Classes:
ChampMap, ChampVectorMap, ImmutableMapFacade, RedBlackMap

public interface ImmutableMap<K,V> extends ReadOnlyMap<K,V>
An interface to an immutable map; the implementation guarantees that the state of the map does not change.

An interface to an immutable map provides methods for creating a new immutable map with new, updated or deleted entries, without changing the original immutable map.

  • Method Details

    • clear

      ImmutableMap<K,V> clear()
      Returns a copy of this map that is empty.
      Returns:
      this set instance if it is already empty, or a different set instance that is empty.
    • put

      ImmutableMap<K,V> put(K key, @Nullable V value)
      Returns a copy of this map that contains all entries of this map with the specified entry added or updated.
      Parameters:
      key - the key of the entry
      value - the value of the entry
      Returns:
      this map instance if it already contains the same entry, or a different map instance with the entry added or updated
    • putAll

      default ImmutableMap<K,V> putAll(Map<? extends K,? extends V> m)
      Returns a copy of this map that contains all entries of this map with entries from the specified map added or updated.
      Parameters:
      m - another map
      Returns:
      this map instance if it already contains the same entries, or a different map instance with the entries added or updated
    • putAll

      default ImmutableMap<K,V> putAll(Iterable<? extends Map.Entry<? extends K,? extends V>> c)
      Returns a copy of this map that contains all entries of this map with entries from the specified map added or updated.
      Parameters:
      c - another map
      Returns:
      this map instance if it already contains the same entries, or a different map instance with the entries added or updated
    • putKeyValues

      default ImmutableMap<K,V> putKeyValues(Object... kv)
      Returns a copy of this map that contains all entries of this map with entries from the specified map added or updated.
      Parameters:
      kv - a list of alternating keys and values
      Returns:
      this map instance if it already contains the same entries, or a different map instance with the entries added or updated
    • remove

      ImmutableMap<K,V> remove(K key)
      Returns a copy of this map that contains all entries of this map with the specified entry removed.
      Parameters:
      key - the key of the entry
      Returns:
      this map instance if it already does not contain the entry, or a different map instance with the entry removed
    • removeAll

      default ImmutableMap<K,V> removeAll(Iterable<? extends K> c)
      Returns a copy of this map that contains all entries of this map except the entries of the specified collection.
      Parameters:
      c - a collection with keys of entries to be removed from this map
      Returns:
      this map instance if it already does not contain the entries, or a different map instance with the entries removed
    • retainAll

      default ImmutableMap<K,V> retainAll(Iterable<? extends K> c)
      Returns a copy of this map that contains only entries that are in this map and in the specified collection.
      Parameters:
      c - a collection with keys of entries to be retained in this map
      Returns:
      this map instance if it has not changed, or a different map instance with entries removed
    • retainAll

      default ImmutableMap<K,V> retainAll(ReadOnlyCollection<? extends K> c)
      Returns a copy of this map that contains only entries that are in this map and in the specified collection.
      Parameters:
      c - a collection with keys of entries to be retained in this map
      Returns:
      this map instance if it has not changed, or a different map instance with entries removed
    • toMutable

      Map<K,V> toMutable()
      Returns a mutable copy of this map.
      Returns:
      a mutable copy.
    • maxSize

      int maxSize()
      Returns the maximal number of entries that this map type can hold
      Returns:
      the maximal size