Interface PMap<K,V>

Type Parameters:
K - the type of keys maintained by this map
V - the type of mapped values

public interface PMap<K,V>
Persistent (functional) Map.
Author:
Evgeny Mandrikov
  • Method Summary

    Modifier and Type
    Method
    Description
     
    void
    forEach(BiConsumer<K,V> action)
    Performs the given action for each entry in this map until all entries have been processed or the action throws an exception.
    get(K key)
     
    boolean
     
     
    static <K, V> PMap<K,V>
    of()
    Returns a persistent map containing zero mappings.
    static <K, V> PMap<K,V>
    of(K k1, V v1)
    Returns a persistent map containing a single mapping.
    static <K, V> PMap<K,V>
    of(K k1, V v1, K k2, V v2)
    Returns a persistent map containing two mappings.
    static <K, V> PMap<K,V>
    of(K k1, V v1, K k2, V v2, K k3, V v3)
    Returns a persistent map containing three mappings.
    static <K, V> PMap<K,V>
    of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4)
    Returns a persistent map containing four mappings.
    static <K, V> PMap<K,V>
    of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5)
    Returns a persistent map containing five mappings.
    static <K, V> PMap<K,V>
    of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6)
    Returns a persistent map containing six mappings.
    static <K, V> PMap<K,V>
    of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7)
    Returns a persistent map containing seven mappings.
    static <K, V> PMap<K,V>
    of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8)
    Returns a persistent map containing eight mappings.
    static <K, V> PMap<K,V>
    of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9)
    Returns a persistent map containing nine mappings.
    static <K, V> PMap<K,V>
    of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9, K k10, V v10)
    Returns a persistent map containing ten mappings.
    put(K key, V value)
     
    remove(K key)
     
    The string representation consists of a list of key-value mappings in the ascending order of hash codes of keys.
  • Method Details

    • put

      PMap<K,V> put(K key, V value)
      Returns:
      new map with added key-value pair, or this if map already contains given key-value pair
    • remove

      PMap<K,V> remove(K key)
      Returns:
      new map with removed key, or this if map does not contain given key
    • get

      @Nullable V get(K key)
      Returns:
      value associated with given key, or null if not found
    • forEach

      void forEach(BiConsumer<K,V> action)
      Performs the given action for each entry in this map until all entries have been processed or the action throws an exception.
    • isEmpty

      boolean isEmpty()
      Returns:
      true if this map contains no elements
    • toString

      String toString()
      The string representation consists of a list of key-value mappings in the ascending order of hash codes of keys. If two keys have same hash code, then their relative order is arbitrary, but stable.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this map
    • entries

      Iterable<Map.Entry<K,V>> entries()
    • keySet

      PSet<K> keySet()
      Returns:
      a set view of the keys contained in the map.
    • of

      static <K, V> PMap<K,V> of()
      Returns a persistent map containing zero mappings.
      Type Parameters:
      K - the PMap's key type
      V - the PMap's value type
      Returns:
      an empty PMap
    • of

      static <K, V> PMap<K,V> of(K k1, V v1)
      Returns a persistent map containing a single mapping.
      Type Parameters:
      K - the PMap's key type
      V - the PMap's value type
      Parameters:
      k1 - the mapping's key
      v1 - the mapping's value
      Returns:
      a PMap containing the specified mapping
    • of

      static <K, V> PMap<K,V> of(K k1, V v1, K k2, V v2)
      Returns a persistent map containing two mappings.
      Type Parameters:
      K - the PMap's key type
      V - the PMap's value type
      Parameters:
      k1 - the first mapping's key
      v1 - the first mapping's value
      k2 - the second mapping's key
      v2 - the second mapping's value
      Returns:
      a PMap containing the specified mappings
    • of

      static <K, V> PMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3)
      Returns a persistent map containing three mappings.
      Type Parameters:
      K - the PMap's key type
      V - the PMap's value type
      Parameters:
      k1 - the first mapping's key
      v1 - the first mapping's value
      k2 - the second mapping's key
      v2 - the second mapping's value
      k3 - the third mapping's key
      v3 - the third mapping's value
      Returns:
      a PMap containing the specified mappings
    • of

      static <K, V> PMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4)
      Returns a persistent map containing four mappings.
      Type Parameters:
      K - the PMap's key type
      V - the PMap's value type
      Parameters:
      k1 - the first mapping's key
      v1 - the first mapping's value
      k2 - the second mapping's key
      v2 - the second mapping's value
      k3 - the third mapping's key
      v3 - the third mapping's value
      k4 - the fourth mapping's key
      v4 - the fourth mapping's value
      Returns:
      a PMap containing the specified mappings
    • of

      static <K, V> PMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5)
      Returns a persistent map containing five mappings.
      Type Parameters:
      K - the PMap's key type
      V - the PMap's value type
      Parameters:
      k1 - the first mapping's key
      v1 - the first mapping's value
      k2 - the second mapping's key
      v2 - the second mapping's value
      k3 - the third mapping's key
      v3 - the third mapping's value
      k4 - the fourth mapping's key
      v4 - the fourth mapping's value
      k5 - the fifth mapping's key
      v5 - the fifth mapping's value
      Returns:
      a PMap containing the specified mappings
    • of

      static <K, V> PMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6)
      Returns a persistent map containing six mappings.
      Type Parameters:
      K - the PMap's key type
      V - the PMap's value type
      Parameters:
      k1 - the first mapping's key
      v1 - the first mapping's value
      k2 - the second mapping's key
      v2 - the second mapping's value
      k3 - the third mapping's key
      v3 - the third mapping's value
      k4 - the fourth mapping's key
      v4 - the fourth mapping's value
      k5 - the fifth mapping's key
      v5 - the fifth mapping's value
      k6 - the sixth mapping's key
      v6 - the sixth mapping's value
      Returns:
      a PMap containing the specified mappings
    • of

      static <K, V> PMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7)
      Returns a persistent map containing seven mappings.
      Type Parameters:
      K - the PMap's key type
      V - the PMap's value type
      Parameters:
      k1 - the first mapping's key
      v1 - the first mapping's value
      k2 - the second mapping's key
      v2 - the second mapping's value
      k3 - the third mapping's key
      v3 - the third mapping's value
      k4 - the fourth mapping's key
      v4 - the fourth mapping's value
      k5 - the fifth mapping's key
      v5 - the fifth mapping's value
      k6 - the sixth mapping's key
      v6 - the sixth mapping's value
      k7 - the seventh mapping's key
      v7 - the seventh mapping's value
      Returns:
      a PMap containing the specified mappings
    • of

      static <K, V> PMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8)
      Returns a persistent map containing eight mappings.
      Type Parameters:
      K - the PMap's key type
      V - the PMap's value type
      Parameters:
      k1 - the first mapping's key
      v1 - the first mapping's value
      k2 - the second mapping's key
      v2 - the second mapping's value
      k3 - the third mapping's key
      v3 - the third mapping's value
      k4 - the fourth mapping's key
      v4 - the fourth mapping's value
      k5 - the fifth mapping's key
      v5 - the fifth mapping's value
      k6 - the sixth mapping's key
      v6 - the sixth mapping's value
      k7 - the seventh mapping's key
      v7 - the seventh mapping's value
      k8 - the eighth mapping's key
      v8 - the eighth mapping's value
      Returns:
      a PMap containing the specified mappings
    • of

      static <K, V> PMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9)
      Returns a persistent map containing nine mappings.
      Type Parameters:
      K - the PMap's key type
      V - the PMap's value type
      Parameters:
      k1 - the first mapping's key
      v1 - the first mapping's value
      k2 - the second mapping's key
      v2 - the second mapping's value
      k3 - the third mapping's key
      v3 - the third mapping's value
      k4 - the fourth mapping's key
      v4 - the fourth mapping's value
      k5 - the fifth mapping's key
      v5 - the fifth mapping's value
      k6 - the sixth mapping's key
      v6 - the sixth mapping's value
      k7 - the seventh mapping's key
      v7 - the seventh mapping's value
      k8 - the eighth mapping's key
      v8 - the eighth mapping's value
      k9 - the ninth mapping's key
      v9 - the ninth mapping's value
      Returns:
      a PMap containing the specified mappings
    • of

      static <K, V> PMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9, K k10, V v10)
      Returns a persistent map containing ten mappings.
      Type Parameters:
      K - the PMap's key type
      V - the PMap's value type
      Parameters:
      k1 - the first mapping's key
      v1 - the first mapping's value
      k2 - the second mapping's key
      v2 - the second mapping's value
      k3 - the third mapping's key
      v3 - the third mapping's value
      k4 - the fourth mapping's key
      v4 - the fourth mapping's value
      k5 - the fifth mapping's key
      v5 - the fifth mapping's value
      k6 - the sixth mapping's key
      v6 - the sixth mapping's value
      k7 - the seventh mapping's key
      v7 - the seventh mapping's value
      k8 - the eighth mapping's key
      v8 - the eighth mapping's value
      k9 - the ninth mapping's key
      v9 - the ninth mapping's value
      k10 - the tenth mapping's key
      v10 - the tenth mapping's value
      Returns:
      a PMap containing the specified mappings