public class SetMap<K,V> extends AbstractMap<K,V>
set
of keys and a Function
that when given a key can derive the value. Once a value has been
derived for a key the function will not be called again for the same key.
This map can be mutated outside of the original set of keys or within the set of keys. The latter will result in the function not being called for the respective keys.
This implementation is the inverse to a MapSet
which can trivially
distill a Map of keys and values to a Set of keys. With the use of a Function
this implementation allows a Set of keys to be converted lazily to a Map of
keys and values.
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Modifier and Type | Field and Description |
---|---|
protected Function<K,V> |
f_functionValue
A function to load a value for a provided key.
|
protected Map<K,Object> |
f_map
The underlying map.
|
Constructor and Description |
---|
SetMap(Set<K> setKeys,
Function<K,V> functionValue)
Construct a SetMap.
|
SetMap(Set<K> setKeys,
Function<K,V> functionValue,
Supplier<Map<K,V>> supplierMap)
Construct a SetMap.
|
Modifier and Type | Method and Description |
---|---|
void |
clear() |
boolean |
containsKey(Object key) |
protected V |
ensureValue(Object oKey)
Return a value for the specified key.
|
Set<Map.Entry<K,V>> |
entrySet() |
V |
get(Object key) |
protected Map<K,V> |
getExternalMap()
Return an external map allowing type safe access.
|
protected Map<K,Object> |
getInternalMap()
Return the internal map allowing any object to be stored.
|
boolean |
isEmpty() |
Set<K> |
keySet() |
V |
put(K key,
V value) |
void |
putAll(Map<? extends K,? extends V> map) |
V |
remove(Object key) |
int |
size() |
clone, containsValue, equals, hashCode, toString, values
finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
public SetMap(Set<K> setKeys, Function<K,V> functionValue)
setKeys
- a set of keys to base this Map onfunctionValue
- a Function
to derive the value for a given
keypublic int size()
public boolean isEmpty()
public boolean containsKey(Object key)
containsKey
in interface Map<K,V>
containsKey
in class AbstractMap<K,V>
public void clear()
protected Map<K,Object> getInternalMap()
protected Map<K,V> getExternalMap()