Class MultiKeyMap<K,V> 
- Type Parameters:
- K- the type of the keys in this map
- V- the type of the values in this map
- All Implemented Interfaces:
- Serializable,- Cloneable,- Map<MultiKey<? extends K>,,- V> - Get<MultiKey<? extends K>,,- V> - IterableGet<MultiKey<? extends K>,,- V> - IterableMap<MultiKey<? extends K>,,- V> - Put<MultiKey<? extends K>,- V> 
Map implementation that uses multiple keys to map the value.
 
 This class is the most efficient way to uses multiple keys to map to a value.
 The best way to use this class is via the additional map-style methods.
 These provide get, containsKey, put and
 remove for individual keys which operate without extra object creation.
 
 The additional methods are the main interface of this map.
 As such, you will not normally hold this map in a variable of type Map.
 
 The normal map methods take in and return a MultiKey.
 If you try to use put() with any other object type a
 ClassCastException is thrown. If you try to use null as
 the key in put() a NullPointerException is thrown.
 
 This map is implemented as a decorator of a AbstractHashedMap which
 enables extra behavior to be added easily.
 
- MultiKeyMap.decorate(new LinkedMap())creates an ordered map.
- MultiKeyMap.decorate(new LRUMap())creates an least recently used map.
- MultiKeyMap.decorate(new ReferenceMap())creates a garbage collector sensitive map.
 Note that IdentityMap and ReferenceIdentityMap are unsuitable
 for use as the key comparison would work on the whole MultiKey, not the elements within.
 
As an example, consider a least recently used cache that uses a String airline code and a Locale to lookup the airline's name:
 private MultiKeyMap cache = MultiKeyMap.multiKeyMap(new LRUMap(50));
 public String getAirlineName(String code, String locale) {
   String name = (String) cache.get(code, locale);
   if (name == null) {
     name = getAirlineNameFromDB(code, locale);
     cache.put(code, locale, name);
   }
   return name;
 }
 
 Note that MultiKeyMap is not synchronized and is not thread-safe. If you wish to use this map from multiple threads concurrently, you must use appropriate synchronization. This class may throw exceptions when accessed by concurrent threads without synchronization.
- Since:
- 3.1
- See Also:
- 
Nested Class Summary
- 
Constructor SummaryConstructorsModifierConstructorDescriptionConstructs a new MultiKeyMap that decorates aHashedMap.protectedMultiKeyMap(AbstractHashedMap<MultiKey<? extends K>, V> map) Constructor that decorates the specified map and is called frommultiKeyMap(AbstractHashedMap).
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidCheck to ensure that input keys are valid MultiKey objects.clone()Clones the map without cloning the keys or values.booleancontainsKey(Object key1, Object key2) Checks whether the map contains the specified multi-key.booleancontainsKey(Object key1, Object key2, Object key3) Checks whether the map contains the specified multi-key.booleancontainsKey(Object key1, Object key2, Object key3, Object key4) Checks whether the map contains the specified multi-key.booleanChecks whether the map contains the specified multi-key.protected AbstractHashedMap<MultiKey<? extends K>, V> Gets the map being decorated.Gets the value mapped to the specified multi-key.Gets the value mapped to the specified multi-key.Gets the value mapped to the specified multi-key.Gets the value mapped to the specified multi-key.protected intGets the hash code for the specified multi-key.protected intGets the hash code for the specified multi-key.protected intGets the hash code for the specified multi-key.protected intGets the hash code for the specified multi-key.protected booleanisEqualKey(AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry, Object key1, Object key2) Is the key equal to the combined key.protected booleanisEqualKey(AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry, Object key1, Object key2, Object key3) Is the key equal to the combined key.protected booleanisEqualKey(AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry, Object key1, Object key2, Object key3, Object key4) Is the key equal to the combined key.protected booleanisEqualKey(AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry, Object key1, Object key2, Object key3, Object key4, Object key5) Is the key equal to the combined key.MapIterator<MultiKey<? extends K>, V> Obtains aMapIteratorover the map.static <K,V> MultiKeyMap <K, V> multiKeyMap(AbstractHashedMap<MultiKey<? extends K>, V> map) Decorates the specified map to add the MultiKeyMap API and fast query.Associates the specified value with the specified keys in this map.Associates the specified value with the specified keys in this map.Associates the specified value with the specified keys in this map.Associates the specified value with the specified keys in this map.Puts the key and value into the map, where the key must be a non-null MultiKey object.voidCopies all of the keys and values from the specified map to this map.booleanRemoves all mappings where the first key is that specified.booleanRemoves all mappings where the first two keys are those specified.booleanRemoves all mappings where the first three keys are those specified.booleanRemoves all mappings where the first four keys are those specified.removeMultiKey(Object key1, Object key2) Removes the specified multi-key from this map.removeMultiKey(Object key1, Object key2, Object key3) Removes the specified multi-key from this map.removeMultiKey(Object key1, Object key2, Object key3, Object key4) Removes the specified multi-key from this map.Removes the specified multi-key from this map.Methods inherited from class org.apache.commons.collections4.map.AbstractMapDecoratorclear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, remove, size, toString, valuesMethods inherited from class java.lang.Objectfinalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Mapcompute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
- 
Constructor Details- 
MultiKeyMappublic MultiKeyMap()Constructs a new MultiKeyMap that decorates aHashedMap.
- 
MultiKeyMapConstructor that decorates the specified map and is called frommultiKeyMap(AbstractHashedMap). The map must not be null and should be empty or only contain valid keys. This constructor performs no validation.- Parameters:
- map- the map to decorate
 
 
- 
- 
Method Details- 
multiKeyMapDecorates the specified map to add the MultiKeyMap API and fast query. The map must not be null and must be empty.- Type Parameters:
- K- the key type
- V- the value type
- Parameters:
- map- the map to decorate, not null
- Returns:
- a new multi key map
- Throws:
- NullPointerException- if map is null
- IllegalArgumentException- if the map is not empty
- Since:
- 4.0
 
- 
checkKey
- 
clone
- 
containsKeyChecks whether the map contains the specified multi-key.- Parameters:
- key1- the first key
- key2- the second key
- Returns:
- true if the map contains the key
 
- 
containsKeyChecks whether the map contains the specified multi-key.- Parameters:
- key1- the first key
- key2- the second key
- key3- the third key
- Returns:
- true if the map contains the key
 
- 
containsKeyChecks whether the map contains the specified multi-key.- Parameters:
- key1- the first key
- key2- the second key
- key3- the third key
- key4- the fourth key
- Returns:
- true if the map contains the key
 
- 
containsKeyChecks whether the map contains the specified multi-key.- Parameters:
- key1- the first key
- key2- the second key
- key3- the third key
- key4- the fourth key
- key5- the fifth key
- Returns:
- true if the map contains the key
 
- 
decoratedGets the map being decorated.- Overrides:
- decoratedin class- AbstractMapDecorator<MultiKey<? extends K>,- V> 
- Returns:
- the decorated map
 
- 
get
- 
get
- 
get
- 
get
- 
hash
- 
hash
- 
hash
- 
hash
- 
isEqualKeyprotected boolean isEqualKey(AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry, Object key1, Object key2) Is the key equal to the combined key.- Parameters:
- entry- the entry to compare to
- key1- the first key
- key2- the second key
- Returns:
- true if the key matches
 
- 
isEqualKeyprotected boolean isEqualKey(AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry, Object key1, Object key2, Object key3) Is the key equal to the combined key.- Parameters:
- entry- the entry to compare to
- key1- the first key
- key2- the second key
- key3- the third key
- Returns:
- true if the key matches
 
- 
isEqualKeyprotected boolean isEqualKey(AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry, Object key1, Object key2, Object key3, Object key4) Is the key equal to the combined key.- Parameters:
- entry- the entry to compare to
- key1- the first key
- key2- the second key
- key3- the third key
- key4- the fourth key
- Returns:
- true if the key matches
 
- 
isEqualKeyprotected boolean isEqualKey(AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry, Object key1, Object key2, Object key3, Object key4, Object key5) Is the key equal to the combined key.- Parameters:
- entry- the entry to compare to
- key1- the first key
- key2- the second key
- key3- the third key
- key4- the fourth key
- key5- the fifth key
- Returns:
- true if the key matches
 
- 
mapIteratorDescription copied from class:AbstractIterableMapObtains aMapIteratorover the map.A map iterator is an efficient way of iterating over maps. There is no need to access the entry set or use Map Entry objects. IterableMap<String,Integer> map = new HashedMap<String,Integer>(); MapIterator<String,Integer> it = map.mapIterator(); while (it.hasNext()) { String key = it.next(); Integer value = it.getValue(); it.setValue(value + 1); }- Specified by:
- mapIteratorin interface- IterableGet<K,- V> 
- Overrides:
- mapIteratorin class- AbstractIterableMap<MultiKey<? extends K>,- V> 
- Returns:
- a map iterator
 
- 
putAssociates the specified value with the specified keys in this map.- Parameters:
- key1- the first key
- key2- the second key
- key3- the third key
- key4- the fourth key
- key5- the fifth key
- value- the value to store
- Returns:
- the value previously mapped to this combined key, null if none
 
- 
putAssociates the specified value with the specified keys in this map.- Parameters:
- key1- the first key
- key2- the second key
- key3- the third key
- key4- the fourth key
- value- the value to store
- Returns:
- the value previously mapped to this combined key, null if none
 
- 
put
- 
put
- 
putPuts the key and value into the map, where the key must be a non-null MultiKey object.- Specified by:
- putin interface- Map<K,- V> 
- Specified by:
- putin interface- Put<K,- V> 
- Overrides:
- putin class- AbstractMapDecorator<MultiKey<? extends K>,- V> 
- Parameters:
- key- the non-null MultiKey object
- value- the value to store
- Returns:
- the previous value for the key
- Throws:
- NullPointerException- if the key is null
- ClassCastException- if the key is not a MultiKey
- See Also:
 
- 
putAllCopies all of the keys and values from the specified map to this map. Each key must be non-null and a MultiKey object.- Specified by:
- putAllin interface- Map<K,- V> 
- Specified by:
- putAllin interface- Put<K,- V> 
- Overrides:
- putAllin class- AbstractMapDecorator<MultiKey<? extends K>,- V> 
- Parameters:
- mapToCopy- to this map
- Throws:
- NullPointerException- if the mapToCopy or any key within is null
- ClassCastException- if any key in mapToCopy is not a MultiKey
- See Also:
 
- 
removeAll
- 
removeAllRemoves all mappings where the first two keys are those specified.This method removes all the mappings where the MultiKeyhas two or more keys, and the first two match those specified.- Parameters:
- key1- the first key
- key2- the second key
- Returns:
- true if any elements were removed
 
- 
removeAllRemoves all mappings where the first three keys are those specified.This method removes all the mappings where the MultiKeyhas three or more keys, and the first three match those specified.- Parameters:
- key1- the first key
- key2- the second key
- key3- the third key
- Returns:
- true if any elements were removed
 
- 
removeAllRemoves all mappings where the first four keys are those specified.This method removes all the mappings where the MultiKeyhas four or more keys, and the first four match those specified.- Parameters:
- key1- the first key
- key2- the second key
- key3- the third key
- key4- the fourth key
- Returns:
- true if any elements were removed
 
- 
removeMultiKeyRemoves the specified multi-key from this map.- Parameters:
- key1- the first key
- key2- the second key
- Returns:
- the value mapped to the removed key, null if key not in map
- Since:
- 4.0 (previous name: remove(Object, Object))
 
- 
removeMultiKeyRemoves the specified multi-key from this map.- Parameters:
- key1- the first key
- key2- the second key
- key3- the third key
- Returns:
- the value mapped to the removed key, null if key not in map
- Since:
- 4.0 (previous name: remove(Object, Object, Object))
 
- 
removeMultiKeyRemoves the specified multi-key from this map.- Parameters:
- key1- the first key
- key2- the second key
- key3- the third key
- key4- the fourth key
- Returns:
- the value mapped to the removed key, null if key not in map
- Since:
- 4.0 (previous name: remove(Object, Object, Object, Object))
 
- 
removeMultiKeyRemoves the specified multi-key from this map.- Parameters:
- key1- the first key
- key2- the second key
- key3- the third key
- key4- the fourth key
- key5- the fifth key
- Returns:
- the value mapped to the removed key, null if key not in map
- Since:
- 4.0 (previous name: remove(Object, Object, Object, Object, Object))
 
 
-