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>
public class SetMap<K,V> extends AbstractMap<K,V>
A Map implementation based on a knownset
of keys and aFunction
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 extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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()
-
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
-
-
-
-
Constructor Detail
-
SetMap
public SetMap(Set<K> setKeys)
Construct a SetMap.- Parameters:
setKeys
- a set of keys to base this Map on
-
SetMap
public SetMap(Set<K> setKeys, Function<K,V> functionValue)
Construct a SetMap.- Parameters:
setKeys
- a set of keys to base this Map onfunctionValue
- aFunction
to derive the value for a given key
-
-
Method Detail
-
size
public int size()
-
isEmpty
public boolean isEmpty()
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey
in interfaceMap<K,V>
- Overrides:
containsKey
in classAbstractMap<K,V>
-
clear
public void clear()
-
getInternalMap
protected Map<K,Object> getInternalMap()
Return the internal map allowing any object to be stored.- Returns:
- the internal map
-
getExternalMap
protected Map<K,V> getExternalMap()
Return an external map allowing type safe access.- Returns:
- an external map
-
-