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

Type Parameters:
K - the type of map keys. The map is invariant on its key type.
V - the type of map values. The persistent map is covariant on its value type.
All Superinterfaces:
ImmutableMap<K,V>

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

A generic persistent 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.

Modification operations return new instances of the persistent map with the modification applied.

  • Method Details

    • of

      static <K extends @Nullable Object, V extends @Nullable Object> PersistentMap<K,V> of()
      Returns an empty persistent map.
    • of

      @SafeVarargs static <K extends @Nullable Object, V extends @Nullable Object> PersistentMap<K,V> of(Map.Entry<? extends K, ? extends V>... entries)

      Returns a new persistent map with the specified contents, given as a list of pairs where the first component is the key and the second is the value.

      If multiple pairs have the same key, the resulting map will contain the value from the last of those pairs.

      Entries of the map are iterated in the order they were specified.

    • hashOf

      static <K extends @Nullable Object, V extends @Nullable Object> PersistentMap<K,V> hashOf()
      Returns an empty persistent map.
    • hashOf

      @SafeVarargs static <K extends @Nullable Object, V extends @Nullable Object> PersistentMap<K,V> hashOf(Map.Entry<? extends K, ? extends V>... entries)

      Returns a new persistent map with the specified contents, given as a list of pairs where the first component is the key and the second is the value.

      If multiple pairs have the same key, the resulting map will contain the value from the last of those pairs.

      Order of the entries in the returned map is unspecified.

    • from

      static <K extends @Nullable Object, V extends @Nullable Object> PersistentMap<K,V> from(ImmutableMap<K,V> map)

      Returns a persistent map containing all entries from the specified map.

      If the specified map is already a persistent map, returns it as is. If the specified map is a persistent map builder, calls build on it and returns the result.

      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> PersistentMap<K,V> from(Map<K,V> map)

      Returns a persistent map containing all entries from the specified map.

      If the specified map is already a persistent map, returns it as is. If the specified map is a persistent map builder, calls build on it and returns the result.

      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> PersistentMap<K,V> from(Iterable<? extends Map.Entry<? extends K, ? extends V>> entries)

      Returns a persistent map containing all entries from the specified entry sequence.

      Entries of the returned map are iterated in the same order as in the specified entry sequence.

    • from

      static <K extends @Nullable Object, V extends @Nullable Object> PersistentMap<K,V> from(Map.Entry<? extends K, ? extends V>[] entries)

      Returns a persistent map containing all entries from the specified array.

      Entries of the returned map are iterated in the same order as in the specified array.

    • from

      static <K extends @Nullable Object, V extends @Nullable Object> PersistentMap<K,V> from(Stream<? extends Map.Entry<? extends K, ? extends V>> entries)

      Returns a persistent map containing all entries from the specified sequence.

      Entries of the returned map are iterated in the same order as in the specified sequence.

    • hashFrom

      static <K extends @Nullable Object, V extends @Nullable Object> PersistentMap<K,V> hashFrom(Map<K,V> map)

      Returns a persistent map containing all entries from the specified map.

      If the specified map is already a persistent hash map, returns it as is. If the specified map is a persistent hash map builder, calls build on it and returns the result.

      Order of the entries in the returned map is unspecified.

    • hashFrom

      static <K extends @Nullable Object, V extends @Nullable Object> PersistentMap<K,V> hashFrom(Iterable<? extends Map.Entry<? extends K, ? extends V>> entries)

      Returns a persistent map containing all entries from the specified entry sequence.

      Order of the entries in the returned map is unspecified.

    • hashFrom

      static <K extends @Nullable Object, V extends @Nullable Object> PersistentMap<K,V> hashFrom(Map.Entry<? extends K, ? extends V>[] entries)

      Returns a persistent map containing all entries from the specified array.

      Order of the entries in the returned map is unspecified.

    • hashFrom

      static <K extends @Nullable Object, V extends @Nullable Object> PersistentMap<K,V> hashFrom(Stream<? extends Map.Entry<? extends K, ? extends V>> entries)

      Returns a persistent map containing all entries from the specified sequence.

      Order of the entries in the returned map is unspecified.

    • put

      PersistentMap<K,V> put(K key, V value)

      Returns the result of associating the specified value with the specified key in this map.

      If this map already contains a mapping for the key, the old value is replaced by the specified value.

      Returns:
      a new persistent map with the specified value associated with the specified key; or this instance if no modifications were made in the result of this operation.
    • remove

      PersistentMap<K,V> remove(K key)
      Returns the result of removing the specified key and its corresponding value from this map.
      Returns:
      a new persistent map with the specified key and its corresponding value removed; or this instance if it contains no mapping for the key.
    • remove

      PersistentMap<K,V> remove(K key, V value)
      Returns the result of removing the entry that maps the specified key to the specified value.
      Returns:
      a new persistent map with the entry for the specified key and value removed; or this instance if it contains no entry with the specified key and value.
    • putAll

      PersistentMap<K,V> putAll(Map<? extends K, ? extends V> map)

      Returns the result of merging the specified m map with this map.

      The effect of this call is equivalent to that of calling put(k, v) once for each mapping from key k to value v in the specified map.

      Returns:
      a new persistent map with keys and values from the specified map m associated; or this instance if no modifications were made in the result of this operation.
    • clear

      PersistentMap<K,V> clear()
      Returns an empty persistent map.
    • builder

      Returns a new builder with the same contents as this map.

      The builder can be used to efficiently perform multiple modification operations.

    • mutate

      default PersistentMap<K,V> mutate(Consumer<? super Map<K,V>> mutator)
    • putAll

      default PersistentMap<K,V> putAll(Iterable<? extends Map.Entry<? extends K, ? extends V>> pairs)
      Returns the result of replacing or adding entries to this map from the specified key-value pairs.
      Returns:
      a new persistent map with entries from the specified key-value pairs added; or this instance if no modifications were made in the result of this operation.
    • putAll

      default PersistentMap<K,V> putAll(Map.Entry<? extends K, ? extends V>[] pairs)
      Returns the result of replacing or adding entries to this map from the specified key-value pairs.
      Returns:
      a new persistent map with entries from the specified key-value pairs added; or this instance if no modifications were made in the result of this operation.
    • putAll

      default PersistentMap<K,V> putAll(Stream<? extends Map.Entry<? extends K, ? extends V>> pairs)
      Returns the result of replacing or adding entries to this map from the specified key-value pairs.
      Returns:
      a new persistent map with entries from the specified key-value pairs added; or this instance if no modifications were made in the result of this operation.
    • removeAll

      default PersistentMap<K,V> removeAll(Iterable<? extends K> keys)
      Returns the result of removing the specified keys and their corresponding values from this map.
      Returns:
      a new persistent map with the specified keys and their corresponding values removed; or this instance if no modifications were made in the result of this operation.
    • removeAll

      default PersistentMap<K,V> removeAll(K[] keys)
      Returns the result of removing the specified keys and their corresponding values from this map.
      Returns:
      a new persistent map with the specified keys and their corresponding values removed; or this instance if no modifications were made in the result of this operation.
    • removeAll

      default PersistentMap<K,V> removeAll(Stream<? extends K> keys)
      Returns the result of removing the specified keys and their corresponding values from this map.
      Returns:
      a new persistent map with the specified keys and their corresponding values removed; or this instance if no modifications were made in the result of this operation.