Package com.tangosol.util
Class SetMap<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
com.tangosol.util.SetMap<K,V>
- All Implemented Interfaces:
Map<K,
V>
A Map implementation based on a known
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.
- Since:
- 12.2.1.4.0
- Author:
- hr 2016.09.29
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,
V>, AbstractMap.SimpleImmutableEntry<K, V> -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
boolean
containsKey
(Object key) protected V
ensureValue
(Object oKey) Return a value for the specified key.entrySet()
Return an external map allowing type safe access.Return the internal map allowing any object to be stored.boolean
isEmpty()
keySet()
void
int
size()
Methods inherited from class java.util.AbstractMap
clone, containsValue, equals, hashCode, toString, values
Methods inherited from class java.lang.Object
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
-
Field Details
-
Constructor Details
-
SetMap
Construct a SetMap.- Parameters:
setKeys
- a set of keys to base this Map on
-
SetMap
Construct a SetMap.- Parameters:
setKeys
- a set of keys to base this Map onfunctionValue
- aFunction
to derive the value for a given key
-
SetMap
Construct a SetMap.- Parameters:
setKeys
- a set of keys to base this Map onfunctionValue
- aFunction
to derive the value for a given keysupplierMap
- the Map to use to hold keys and values
-
-
Method Details
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
- Specified by:
containsKey
in interfaceMap<K,
V> - Overrides:
containsKey
in classAbstractMap<K,
V>
-
get
-
put
-
remove
-
putAll
-
clear
public void clear() -
keySet
-
entrySet
-
getInternalMap
Return the internal map allowing any object to be stored.- Returns:
- the internal map
-
getExternalMap
Return an external map allowing type safe access.- Returns:
- an external map
-
ensureValue
Return a value for the specified key.- Parameters:
oKey
- the key to load a value for- Returns:
- a value for the specified key
-