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>
A
VivifyingMap
is a map with two additional methods:
getVivify(K)
is likeget
, but it never returns null; instead, it stores an empty value and returns that.prune()
removes empty values
-
Nested Class Summary
-
Field Summary
Fields inherited from class org.checkerframework.afu.scenelib.util.coll.WrapperMap
back
-
Constructor Summary
ConstructorsConstructorDescriptionVivifyingMap
(Map<K, V> back) Constructs a newVivifyingMap
backed by the given map. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract V
createValueFor
(K k) Returns a new, "empty" value to which the keyk
can be mapped; subclasses must implement.Likeget()
, this returns the value to which the specified key is mapped.protected abstract boolean
isEmptyValue
(V v) Returns true if the given value is "empty" -- that is, it is the same as whatgetVivify(K)
would create.void
prune()
Prunes this map by deleting entries with empty values.Methods inherited from class org.checkerframework.afu.scenelib.util.coll.WrapperMap
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, toString, values
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
VivifyingMap
Constructs a newVivifyingMap
backed by the given map. All reads and writes to thisVivifyingMap
go through to the backing map. However, since theVivifyingMap
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
Likeget()
, 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
Returns a new, "empty" value to which the keyk
can be mapped; subclasses must implement. -
prune
public void prune()Prunes this map by deleting entries with empty values. -
isEmptyValue
Returns true if the given value is "empty" -- that is, it is the same as whatgetVivify(K)
would create.This method does not recursively prune its argument, and it does not need to.
-