Interface PMap<K,​V>

  • All Known Implementing Classes:
    HamtPMap

    public interface PMap<K,​V>
    A minimal interface for null-hostile, persistent immutable maps.
    • Method Detail

      • isEmpty

        boolean isEmpty()
        Returns whether this map is empty.
      • values

        java.lang.Iterable<V> values()
        Returns an iterable for the values in this map.
      • keys

        java.lang.Iterable<K> keys()
        Returns an iterable for the keys in this map.
      • get

        @Nullable
        V get​(K key)
        Retrieves the given key from the map, or returns null if it is not present.
      • plus

        PMap<K,​V> plus​(K key,
                             V value)
        Returns a new map with the given key-value pair added. If the value is already present, then this same map will be returned.
      • minus

        PMap<K,​V> minus​(K key)
        Returns a new map with the given key removed. If the key was not present in the first place, then this same map will be returned.
      • reconcile

        PMap<K,​V> reconcile​(PMap<K,​V> that,
                                  PMap.Reconciler<K,​V> joiner)
        Performs a reconcile operation to merge this and that.

        joiner is called for each pair of entries, one from each map, which share the same key and whose values are not Object.equals(java.lang.Object). This includes entries that are absent from one of the maps, for which null is passed as the absent value.

        The return of calling joiner will appear in the merged map at the key of the original entry pair. The return may not be null. If the values in a pair of entries are Object.equals(java.lang.Object), that value will be used directly in the result without calling joiner.

        The first value passed to joiner comes from this, and the second value comes from that. There are no guarantees on the source of key. Note that that map must be the same implementation.

      • equivalent

        boolean equivalent​(PMap<K,​V> that,
                           java.util.function.BiPredicate<V,​V> equivalence)
        Checks equality recursively based on the given equivalence. Short-circuits as soon as a 'false' result is found, or if a key in one map is missing from the other. The equivalence will only be called on two non-null values. Note that that map must be the same implementation. Note that the equivalence MUST be reflective (i.e. equivalence.test(x, x) == true).