V
- The type of valuesK
- The type of keyspublic interface ComputingMap<K,V> extends ReadOnlyMap<K,V>
K
to type V
. This means that we may
simply add a key to the map and have the associated value be calculated and
added automatically.
This interface may form the basis of a caching system, for example.Modifier and Type | Method and Description |
---|---|
boolean |
clear()
Remove all keys and values from the map.
|
V |
get(K key)
For the given key, this method should return the value which has been
computed.
|
default boolean |
isEmpty() |
java.util.Set<K> |
keySet() |
boolean |
put(K key)
Enters the key into the map such that a value of type
V will at
some point be computed which will be then returned by any subsequent calls
to get(K) . |
default boolean |
putAll(java.util.Collection<? extends K> keys) |
default V |
putGet(K key)
This method simply makes sure the value for the given key has been computed
and added to the map, then returns it.
|
V |
putGet(K key,
java.util.function.Consumer<V> wasPresent,
java.util.function.Consumer<V> wasMissing) |
default boolean |
remove(K key)
Remove the given key and it's associated computed value from the map.
|
default boolean |
removeAll(java.util.Collection<? extends K> keys) |
V |
removeGet(K key)
Remove the given key and it's associated computed value from the map.
|
java.util.Collection<V> |
values() |
size
V get(K key)
get
in interface ReadOnlyMap<K,V>
key
- The key object for which to return the mapped computed valueboolean put(K key)
V
will at
some point be computed which will be then returned by any subsequent calls
to get(K)
.
Generally keys should be immutable, and the computation associated with the
map will be expected to produce identical results each time, so in the case
that the key has already been added to the map most implementations should
just return instantly and do no work. Because of this it also makes little
sense to return the previous value for a key entered more than once.key
- The key object to be mapped to a new valuedefault boolean putAll(java.util.Collection<? extends K> keys)
default V putGet(K key)
key
- The key object to be mapped to a new valueV putGet(K key, java.util.function.Consumer<V> wasPresent, java.util.function.Consumer<V> wasMissing)
java.util.Set<K> keySet()
keySet
in interface ReadOnlyMap<K,V>
java.util.Collection<V> values()
V removeGet(K key)
Use of this method may result in worse performance that
remove(Object)
, as some implementations may cancel value
computation for keys removed by the latter.
key
- The key to remove.default boolean remove(K key)
key
- The key to remove.default boolean removeAll(java.util.Collection<? extends K> keys)
boolean clear()
default boolean isEmpty()
isEmpty
in interface ReadOnlyMap<K,V>