Package com.luciad.util.collections
Interface ILcdMultiKeyMap<K,V>
- All Superinterfaces:
Map<K,
V>
- All Known Subinterfaces:
ILcdMultiKeyCache
,ILspGLResourceCache
Interface for a map that uses multiple keys per stored value. The multiple
keys effectively change the map from a traditional key-value mapping to a
tree structure. Each node in this tree structure is an
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<K,V> 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.
- Since:
- 2012.0
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionGets the entries of this branch's branch map.Gets the keys associated with the branches of this map.int
Gets the number of branches.Collection
<? extends ILcdMultiKeyMap<K, V>> Gets the values of this branch's leaf map.void
Clears the entire contents of the multi-key map, not just the map at this level, but also the branches.Returns the entry corresponding to the specified list of keys.Returns the branch that is associated with the given key, ornull
if the branch does not exist.getOrCreateBranch
(K[] aKeys) Creates and returns a new branch for the given key.void
Inserts a entry with the given keys and value.Gets all keys in this map, recursivelyvoid
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.Methods inherited from interface java.util.Map
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
-
Method Details
-
getBranch
Returns the branch that is associated with the given key, ornull
if the branch does not exist.- Parameters:
aKeys
- the key- Returns:
- the branch associated with the given key, can be
null
if a branch does not exist. - See Also:
-
getOrCreateBranch
Creates and returns a new branch for the given key. A new branch (or sub-branch) is only created when necessary.- Parameters:
aKeys
- the key- Returns:
- the branch associated with the given key. This method never returns
null
.
-
get
Returns the entry corresponding to the specified list of keys. If no match is found for the keys, this method returnsnull
.- Parameters:
aKeys
- the list of keys- Returns:
- the resulting value, or
null
if no value is associated with the key sequence
-
put
Inserts a entry with the given keys and value. If a mapping corresponding to the given keys already exists, it is overwritten.- Parameters:
aKeys
- the list of keysaValue
- the value
-
remove
Removes all entries whose list of keys starts with the specified key sequence.- Parameters:
aKeys
- the list of keys
-
removeRecursive
Removes all entries from the map whose list of keys contains the specified object. The object can occur at any location in the key sequence; it does not have to be the first key.- Parameters:
aKey
- the key
-
clearRecursive
void clearRecursive()Clears the entire contents of the multi-key map, not just the map at this level, but also the branches. -
branchSize
int branchSize()Gets the number of branches.- Returns:
- the number of child branches
-
branchKeySet
Gets the keys associated with the branches of this map.- Returns:
- the branches key set
-
recursiveLeafKeySet
Gets all keys in this map, recursively- Returns:
- all the keys in this map
-
branchEntrySet
Gets the entries of this branch's branch map.- Returns:
- the branch entry set
-
branchValues
Collection<? extends ILcdMultiKeyMap<K,V>> branchValues()Gets the values of this branch's leaf map.- Returns:
- the branch value set
-