Class VivifyingMap<K,V>

java.lang.Object
org.checkerframework.afu.scenelib.util.coll.WrapperMap<K,V>
org.checkerframework.afu.scenelib.util.coll.VivifyingMap<K,V>
All Implemented Interfaces:
Map<K,V>

public abstract class VivifyingMap<K,V> extends WrapperMap<K,V>
A VivifyingMap is a map with two additional methods:
  • getVivify(K) is like get, but it never returns null; instead, it stores an empty value and returns that.
  • prune() removes empty values
  • Constructor Details

    • VivifyingMap

      public VivifyingMap(Map<K,V> back)
      Constructs a new VivifyingMap backed by the given map. All reads and writes to this VivifyingMap go through to the backing map. However, since the VivifyingMap generally provides a superset of the functionality of the backing map, it is rarely useful to access the backing map directly; the parameter is given mainly so you can provide a new map of your favorite class (HashMap, LinkedHashMap, etc.).
  • Method Details

    • getVivify

      public V getVivify(K k)
      Like get(), this returns the value to which the specified key is mapped. However, this never returns null. If the key is not currently mapped to a value, this method stores a new empty value, then returns that.
    • createValueFor

      protected abstract V createValueFor(K k)
      Returns a new, "empty" value to which the key k can be mapped; subclasses must implement.
    • prune

      public void prune()
      Prunes this map by deleting entries with empty values.
    • isEmptyValue

      protected abstract boolean isEmptyValue(V v)
      Returns true if the given value is "empty" -- that is, it is the same as what getVivify(K) would create.

      This method does not recursively prune its argument, and it does not need to.