public interface KeyMap<V> extends java.util.Map<Key,V>
Map
implementation for handling keys.
The difference between this map and a regular Map
is that this map handles checks for
global keys as well as individual ones.
For example, if this map has "STONE" as a key inside it, the Map.get(Object)
method will return the value
of that key when "STONE" is provided, as well as any other key with a different sub-key ("STONE:0", for example).
However, if this set has "STONE:0" as a key, as well as the global key inside it, the Map.get(Object)
method
will return the value of the exact same key and not its global key (Therefore, the value of "STONE:0" will be
returned if "STONE:0" is provided, and the value of "STONE" will be provided if "STONE:1" is provided)
Modifier and Type | Method and Description |
---|---|
java.util.Map<Key,V> |
asMap()
Return a regular
HashMap with the keys and values of this map. |
static <V> KeyMap<V> |
createConcurrentKeyMap()
Create a new empty
KeyMap instance based on ConcurrentHashMap . |
static <V> KeyMap<V> |
createConcurrentKeyMap(java.util.Map<Key,V> map)
Create a new
KeyMap instance from the given map based on ConcurrentHashMap . |
static <V> KeyMap<V> |
createKeyMap()
Create a new empty
KeyMap instance based on HashMap . |
static <V> KeyMap<V> |
createKeyMap(java.util.Map<Key,V> map)
Create a new
KeyMap instance from the given map based on HashMap . |
static <V> KeyMap<V> |
createKeyMap(java.util.function.Supplier<java.util.Map<java.lang.String,V>> mapCreator)
Create a new empty
KeyMap instance. |
static <K,V> java.util.stream.Collector<K,?,KeyMap<V>> |
getCollector(java.util.function.Function<? super K,? extends Key> keyMapper,
java.util.function.Function<? super K,? extends V> valueMapper)
Create a collector for
KeyMap based on HashMap that can be used in streams |
static <K,V> java.util.stream.Collector<K,?,KeyMap<V>> |
getCollector(java.util.function.Function<? super K,? extends Key> keyMapper,
java.util.function.Function<? super K,? extends V> valueMapper,
java.util.function.Supplier<java.util.Map<java.lang.String,V>> mapCreator)
Create a collector for
KeyMap that can be used in streams. |
Key |
getKey(Key original)
Get the key that is similar to the provided key.
|
Key |
getKey(Key original,
Key def)
Get the key that is similar to the provided key.
|
V |
getRaw(Key key,
V def)
Get a value from the key without checking for global keys or other similar keys.
|
boolean |
removeIf(java.util.function.Predicate<Key> predicate)
See
Collection.removeIf(Predicate) |
static <V> KeyMap<V> createKeyMap(java.util.function.Supplier<java.util.Map<java.lang.String,V>> mapCreator)
KeyMap
instance.mapCreator
- The map creator for the inner-map of the new KeyMap
static <V> KeyMap<V> createKeyMap()
KeyMap
instance based on HashMap
.static <V> KeyMap<V> createKeyMap(java.util.Map<Key,V> map)
KeyMap
instance from the given map based on HashMap
.
If the provided map is also a KeyMap
, the exact same instance of that map is returned.
Otherwise, the returned KeyMap
is a copy of that map.map
- The map to create KeySet
from.static <V> KeyMap<V> createConcurrentKeyMap()
KeyMap
instance based on ConcurrentHashMap
.static <V> KeyMap<V> createConcurrentKeyMap(java.util.Map<Key,V> map)
KeyMap
instance from the given map based on ConcurrentHashMap
.
If the provided map is also a KeyMap
, the exact same instance of that map is returned.
Otherwise, the returned KeyMap
is a copy of that map.map
- The map to create KeySet
from.static <K,V> java.util.stream.Collector<K,?,KeyMap<V>> getCollector(java.util.function.Function<? super K,? extends Key> keyMapper, java.util.function.Function<? super K,? extends V> valueMapper, java.util.function.Supplier<java.util.Map<java.lang.String,V>> mapCreator)
KeyMap
that can be used in streams.keyMapper
- The key mapper to apply.valueMapper
- The values mapper to apply.mapCreator
- The map creator for the inner-map of the new KeyMap
static <K,V> java.util.stream.Collector<K,?,KeyMap<V>> getCollector(java.util.function.Function<? super K,? extends Key> keyMapper, java.util.function.Function<? super K,? extends V> valueMapper)
KeyMap
based on HashMap
that can be used in streamskeyMapper
- The key mapper to apply.valueMapper
- The values mapper to apply.@Nullable Key getKey(Key original)
original
- The original key.Key getKey(Key original, @Nullable Key def)
original
- The original key.def
- Default key to be returned if is not in the map.V getRaw(Key key, V def)
Map
key
- The key to checkdef
- The default value to return.boolean removeIf(java.util.function.Predicate<Key> predicate)
Collection.removeIf(Predicate)