public interface ILcdMultiKeyMap<K,V> extends Map<K,V>
ILspMultiKeyMap
itself. As an example of why this is useful, it is common for painters to
cache computed data which depends on the painter, on a domain object and on
the view's current world reference. This interface supports this scenario by
allowing all three of these objects to be used as the key for the stored value.
A more traditional single-key/single-value mapping could support this
as well by using an array or composite of objects as the key. However, exposing
the tree-like nature of the data structure allows for more efficient
implementations. For example, to add multiple values to the same branch it is better
to first retrieve the branch using the getBranch(Object[])
method
and from then on work with the resulting branch. The below code snippets are
equivalent, but the first is more efficient.
Variant 1:
ILcdMultiKeyMap map;
K key1, key2, key3, key4;
V value1, value2;
K[] keys = {key1, key2};
ILcdMultiKeyMap branch = map.getOrCreateBranch(keys);
branch.put(key3, value1 );
branch.put(key4, value2 );
Variant 2:
ILcdMultiKeyMap map;
K key1, key2, key3, key4;
V value1, value2;
K[] keys1 = {key1, key2, key3};
K[] keys2 = {key1, key2, key4};
map.put(keys1, value1);
map.put(keys2, value2);
The Map
interface methods operate on the current node.
Modifier and Type | Method and Description |
---|---|
Set<? extends Map.Entry<K,? extends ILcdMultiKeyMap<K,V>>> |
branchEntrySet()
Gets the entries of this branch's branch map.
|
Set<K> |
branchKeySet()
Gets the keys associated with the branches of this map.
|
int |
branchSize()
Gets the number of branches.
|
Collection<? extends ILcdMultiKeyMap<K,V>> |
branchValues()
Gets the values of this branch's leaf map.
|
void |
clearRecursive()
Clears the entire contents of the multi-key map,
not just the map at this level, but also the branches.
|
V |
get(K[] aKeys)
Returns the entry corresponding to the specified list of keys.
|
ILcdMultiKeyMap<K,V> |
getBranch(K[] aKeys)
Returns the branch that is associated with the given key, or
null
if the branch does not exist. |
ILcdMultiKeyMap<K,V> |
getOrCreateBranch(K[] aKeys)
Creates and returns a new branch for the given key.
|
void |
put(K[] aKeys,
V aValue)
Inserts a entry with the given keys and value.
|
Iterable<K[]> |
recursiveLeafKeySet()
Gets all keys in this map, recursively
|
void |
remove(K[] aKeys)
Removes all entries whose list of keys starts with the specified key
sequence.
|
void |
removeRecursive(K aKey)
Removes all entries from the map whose list of keys contains the
specified object.
|
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
ILcdMultiKeyMap<K,V> getBranch(K[] aKeys)
null
if the branch does not exist.aKeys
- the keynull
if
a branch does not exist.getOrCreateBranch(Object[])
ILcdMultiKeyMap<K,V> getOrCreateBranch(K[] aKeys)
aKeys
- the keynull
.V get(K[] aKeys)
null
.aKeys
- the list of keysnull
if no value is associated with the key sequencevoid put(K[] aKeys, V aValue)
aKeys
- the list of keysaValue
- the valuevoid remove(K[] aKeys)
aKeys
- the list of keysvoid removeRecursive(K aKey)
aKey
- the keyvoid clearRecursive()
int branchSize()
Set<K> branchKeySet()
Iterable<K[]> recursiveLeafKeySet()
Set<? extends Map.Entry<K,? extends ILcdMultiKeyMap<K,V>>> branchEntrySet()
Collection<? extends ILcdMultiKeyMap<K,V>> branchValues()