Package de.xima.fc.common.collection
Class CrudMap<Key,Value>
- java.lang.Object
-
- java.util.AbstractMap<Key,Value>
-
- de.xima.fc.common.collection.CrudMap<Key,Value>
-
- Type Parameters:
Key
- Type of the map keys.Value
- Type of the map values.
- All Implemented Interfaces:
Serializable
,Map<Key,Value>
public final class CrudMap<Key,Value> extends AbstractMap<Key,Value> implements Serializable
CRUD = create, read, update, and deleteA map that delegates to a
CrudMapAdapter
with aget(key)
,set(key, value)
, anddelete
method. This lets you implement a map in terms of simple get, set, delete operations (instead of having to implement an entry set when usingAbstractMap
).This is especially useful when you do not have a simple map, but need to compute the keys or values in some fashion.
You can also use this to implement a view of an existing map with mapped or filtered keys and values: Keys for which
get
returnsnull
are excluded from the map.The map is serializable if the data adapter is serializable.
- Since:
- 8.2.0
- Author:
- XIMA MEDIA GmbH
- See Also:
- Serialized Form
-
-
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 Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
containsKey(Object key)
Set<Map.Entry<Key,Value>>
entrySet()
Value
get(Object key)
Value
getOrDefault(Object key, Value defaultValue)
boolean
isEmpty()
static <K,V>
Map<K,V>newMap(Class<K> keyType, CrudMapAdapter<K,V> dataAdapter)
Creates a new map that delegates to the givendata adapter
for getting data from the map, setting data to the map, and deleting data from the map.static <T> Set<T>
newSet(Class<T> keyType, CrudMapAdapter<T,Unit> dataAdapter)
Creates a new set that delegates to the givendata adapter
for getting elements from the set, adding deleting elements to the set, and deleting elements from the set.Value
put(Key key, Value value)
Value
remove(Object key)
int
size()
-
Methods inherited from class java.util.AbstractMap
clear, clone, containsValue, equals, hashCode, keySet, putAll, 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, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Method Detail
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey
in interfaceMap<Key,Value>
- Overrides:
containsKey
in classAbstractMap<Key,Value>
-
getOrDefault
public Value getOrDefault(Object key, Value defaultValue)
- Specified by:
getOrDefault
in interfaceMap<Key,Value>
-
isEmpty
public boolean isEmpty()
-
size
public int size()
-
newMap
public static <K,V> Map<K,V> newMap(Class<K> keyType, CrudMapAdapter<K,V> dataAdapter)
Creates a new map that delegates to the givendata adapter
for getting data from the map, setting data to the map, and deleting data from the map.- Type Parameters:
K
- Type of the map keys.V
- Type of the map values.- Parameters:
dataAdapter
- Data adapter for reading and writing data.keyType
- Type of the map keys.- Returns:
- The new map.
-
newSet
public static <T> Set<T> newSet(Class<T> keyType, CrudMapAdapter<T,Unit> dataAdapter)
Creates a new set that delegates to the givendata adapter
for getting elements from the set, adding deleting elements to the set, and deleting elements from the set.- Type Parameters:
T
- Type of the set elements.- Parameters:
dataAdapter
- Data adapter for reading and writing data.keyType
- Type of the set elements.- Returns:
- The new set.
- See Also:
CrudMapAdapter.SetLike
-
-