Package com.google.javascript.rhino
Interface PMap<K,V>
-
- All Known Implementing Classes:
HamtPMap
public interface PMap<K,V>
A minimal interface for null-hostile, persistent immutable maps.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
PMap.Reconciler<K,V>
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
equivalent(PMap<K,V> that, java.util.function.BiPredicate<V,V> equivalence)
Checks equality recursively based on the given equivalence.@Nullable V
get(K key)
Retrieves the given key from the map, or returns null if it is not present.boolean
isEmpty()
Returns whether this map is empty.java.lang.Iterable<K>
keys()
Returns an iterable for the keys in this map.PMap<K,V>
minus(K key)
Returns a new map with the given key removed.PMap<K,V>
plus(K key, V value)
Returns a new map with the given key-value pair added.PMap<K,V>
reconcile(PMap<K,V> that, PMap.Reconciler<K,V> joiner)
Performs a reconcile operation to mergethis
andthat
.java.lang.Iterable<V>
values()
Returns an iterable for the values in this map.
-
-
-
Method Detail
-
isEmpty
@CheckReturnValue boolean isEmpty()
Returns whether this map is empty.
-
values
@CheckReturnValue java.lang.Iterable<V> values()
Returns an iterable for the values in this map.
-
keys
@CheckReturnValue 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
@CheckReturnValue 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
@CheckReturnValue 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
@CheckReturnValue PMap<K,V> reconcile(PMap<K,V> that, PMap.Reconciler<K,V> joiner)
Performs a reconcile operation to mergethis
andthat
.joiner
is called for each pair of entries, one from each map, which share the same key and whose values are notObject.equals(java.lang.Object)
. This includes entries that are absent from one of the maps, for whichnull
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 areObject.equals(java.lang.Object)
, that value will be used directly in the result without callingjoiner
.The first value passed to
joiner
comes fromthis
, and the second value comes fromthat
. There are no guarantees on the source ofkey
. Note thatthat
map must be the same implementation.
-
equivalent
@CheckReturnValue 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 thatthat
map must be the same implementation. Note that the equivalence MUST be reflective (i.e. equivalence.test(x, x) == true).
-
-