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:
Map<Key,Value>
public final class CrudMap<Key,Value> extends AbstractMap<Key,Value>
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.- Since:
- 8.2.0
- Author:
- XIMA MEDIA GmbH
-
-
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 given data adapter.static <T> Set<T>
newSet(Class<T> keyType, CrudMapAdapter<T,Unit> dataAdapter)
Creates a new set that delegates to the given data adapter.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>
-
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 given data adapter.- Parameters:
dataAdapter
- Data adapter for reading and writing data.keyType
- Type of the map keys.
-
newSet
public static <T> Set<T> newSet(Class<T> keyType, CrudMapAdapter<T,Unit> dataAdapter)
Creates a new set that delegates to the given data adapter.- Parameters:
dataAdapter
- Data adapter for reading and writing data.keyType
- Type of the map keys.- See Also:
CrudMapAdapter.SetLike
-
-