Interface ILcdMultiKeyMap<K,V>

All Superinterfaces:
Map<K,V>
All Known Subinterfaces:
ILcdMultiKeyCache, ILspGLResourceCache

public interface ILcdMultiKeyMap<K,V> extends Map<K,V>
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
  • Method Details Link icon

    • getBranch Link icon

      ILcdMultiKeyMap<K,V> getBranch(K[] aKeys)
      Returns the branch that is associated with the given key, or null 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 Link icon

      ILcdMultiKeyMap<K,V> getOrCreateBranch(K[] aKeys)
      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 Link icon

      V get(K[] aKeys)
      Returns the entry corresponding to the specified list of keys. If no match is found for the keys, this method returns null.
      Parameters:
      aKeys - the list of keys
      Returns:
      the resulting value, or null if no value is associated with the key sequence
    • put Link icon

      void put(K[] aKeys, V aValue)
      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 keys
      aValue - the value
    • remove Link icon

      void remove(K[] aKeys)
      Removes all entries whose list of keys starts with the specified key sequence.
      Parameters:
      aKeys - the list of keys
    • removeRecursive Link icon

      void removeRecursive(K aKey)
      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 Link icon

      void clearRecursive()
      Clears the entire contents of the multi-key map, not just the map at this level, but also the branches.
    • branchSize Link icon

      int branchSize()
      Gets the number of branches.
      Returns:
      the number of child branches
    • branchKeySet Link icon

      Set<K> branchKeySet()
      Gets the keys associated with the branches of this map.
      Returns:
      the branches key set
    • recursiveLeafKeySet Link icon

      Iterable<K[]> recursiveLeafKeySet()
      Gets all keys in this map, recursively
      Returns:
      all the keys in this map
    • branchEntrySet Link icon

      Set<? extends Map.Entry<K,? extends ILcdMultiKeyMap<K,V>>> branchEntrySet()
      Gets the entries of this branch's branch map.
      Returns:
      the branch entry set
    • branchValues Link icon

      Collection<? extends ILcdMultiKeyMap<K,V>> branchValues()
      Gets the values of this branch's leaf map.
      Returns:
      the branch value set