Class MultiKeyMap
- java.lang.Object
-
- org.apache.commons.collections.map.MultiKeyMap
-
- All Implemented Interfaces:
java.io.Serializable,java.util.Map,IterableMap
@Deprecated(since="2021-04-30") public class MultiKeyMap extends java.lang.Object implements IterableMap, java.io.Serializable
Deprecated.Commons Collections 3 is in maintenance mode. Commons Collections 4 should be used instead.AMapimplementation 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,putandremovefor 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 useput()with any other object type aClassCastExceptionis thrown. If you try to usenullas the key input()aNullPointerExceptionis thrown.This map is implemented as a decorator of a
AbstractHashedMapwhich enables extra behaviour 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.
IdentityMapandReferenceIdentityMapare 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.decorate(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:
- Commons Collections 3.1
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description MultiKeyMap()Deprecated.Constructs a new MultiKeyMap that decorates aHashedMap.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclear()Deprecated.java.lang.Objectclone()Deprecated.Clones the map without cloning the keys or values.booleancontainsKey(java.lang.Object key)Deprecated.booleancontainsKey(java.lang.Object key1, java.lang.Object key2)Deprecated.Checks whether the map contains the specified multi-key.booleancontainsKey(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3)Deprecated.Checks whether the map contains the specified multi-key.booleancontainsKey(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3, java.lang.Object key4)Deprecated.Checks whether the map contains the specified multi-key.booleancontainsKey(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3, java.lang.Object key4, java.lang.Object key5)Deprecated.Checks whether the map contains the specified multi-key.booleancontainsValue(java.lang.Object value)Deprecated.static MultiKeyMapdecorate(AbstractHashedMap map)Deprecated.Decorates the specified map to add the MultiKeyMap API and fast query.java.util.SetentrySet()Deprecated.booleanequals(java.lang.Object obj)Deprecated.java.lang.Objectget(java.lang.Object key)Deprecated.java.lang.Objectget(java.lang.Object key1, java.lang.Object key2)Deprecated.Gets the value mapped to the specified multi-key.java.lang.Objectget(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3)Deprecated.Gets the value mapped to the specified multi-key.java.lang.Objectget(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3, java.lang.Object key4)Deprecated.Gets the value mapped to the specified multi-key.java.lang.Objectget(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3, java.lang.Object key4, java.lang.Object key5)Deprecated.Gets the value mapped to the specified multi-key.inthashCode()Deprecated.booleanisEmpty()Deprecated.java.util.SetkeySet()Deprecated.MapIteratormapIterator()Deprecated.Obtains aMapIteratorover the map.java.lang.Objectput(java.lang.Object key, java.lang.Object value)Deprecated.Puts the key and value into the map, where the key must be a non-null MultiKey object.java.lang.Objectput(java.lang.Object key1, java.lang.Object key2, java.lang.Object value)Deprecated.Stores the value against the specified multi-key.java.lang.Objectput(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3, java.lang.Object value)Deprecated.Stores the value against the specified multi-key.java.lang.Objectput(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3, java.lang.Object key4, java.lang.Object value)Deprecated.Stores the value against the specified multi-key.java.lang.Objectput(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3, java.lang.Object key4, java.lang.Object key5, java.lang.Object value)Deprecated.Stores the value against the specified multi-key.voidputAll(java.util.Map mapToCopy)Deprecated.Copies all of the keys and values from the specified map to this map.java.lang.Objectremove(java.lang.Object key)Deprecated.java.lang.Objectremove(java.lang.Object key1, java.lang.Object key2)Deprecated.Removes the specified multi-key from this map.java.lang.Objectremove(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3)Deprecated.Removes the specified multi-key from this map.java.lang.Objectremove(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3, java.lang.Object key4)Deprecated.Removes the specified multi-key from this map.java.lang.Objectremove(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3, java.lang.Object key4, java.lang.Object key5)Deprecated.Removes the specified multi-key from this map.booleanremoveAll(java.lang.Object key1)Deprecated.Removes all mappings where the first key is that specified.booleanremoveAll(java.lang.Object key1, java.lang.Object key2)Deprecated.Removes all mappings where the first two keys are those specified.booleanremoveAll(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3)Deprecated.Removes all mappings where the first three keys are those specified.booleanremoveAll(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3, java.lang.Object key4)Deprecated.Removes all mappings where the first four keys are those specified.intsize()Deprecated.java.lang.StringtoString()Deprecated.java.util.Collectionvalues()Deprecated.
-
-
-
Method Detail
-
decorate
public static MultiKeyMap decorate(AbstractHashedMap map)
Deprecated.Decorates the specified map to add the MultiKeyMap API and fast query. The map must not be null and must be empty.- Parameters:
map- the map to decorate, not null- Throws:
java.lang.IllegalArgumentException- if the map is null or not empty
-
get
public java.lang.Object get(java.lang.Object key1, java.lang.Object key2)Deprecated.Gets the value mapped to the specified multi-key.- Parameters:
key1- the first keykey2- the second key- Returns:
- the mapped value, null if no match
-
containsKey
public boolean containsKey(java.lang.Object key1, java.lang.Object key2)Deprecated.Checks whether the map contains the specified multi-key.- Parameters:
key1- the first keykey2- the second key- Returns:
- true if the map contains the key
-
put
public java.lang.Object put(java.lang.Object key1, java.lang.Object key2, java.lang.Object value)Deprecated.Stores the value against the specified multi-key.- Parameters:
key1- the first keykey2- the second keyvalue- the value to store- Returns:
- the value previously mapped to this combined key, null if none
-
remove
public java.lang.Object remove(java.lang.Object key1, java.lang.Object key2)Deprecated.Removes the specified multi-key from this map.- Specified by:
removein interfacejava.util.Map- Parameters:
key1- the first keykey2- the second key- Returns:
- the value mapped to the removed key, null if key not in map
-
get
public java.lang.Object get(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3)Deprecated.Gets the value mapped to the specified multi-key.- Parameters:
key1- the first keykey2- the second keykey3- the third key- Returns:
- the mapped value, null if no match
-
containsKey
public boolean containsKey(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3)Deprecated.Checks whether the map contains the specified multi-key.- Parameters:
key1- the first keykey2- the second keykey3- the third key- Returns:
- true if the map contains the key
-
put
public java.lang.Object put(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3, java.lang.Object value)Deprecated.Stores the value against the specified multi-key.- Parameters:
key1- the first keykey2- the second keykey3- the third keyvalue- the value to store- Returns:
- the value previously mapped to this combined key, null if none
-
remove
public java.lang.Object remove(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3)Deprecated.Removes the specified multi-key from this map.- Parameters:
key1- the first keykey2- the second keykey3- the third key- Returns:
- the value mapped to the removed key, null if key not in map
-
get
public java.lang.Object get(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3, java.lang.Object key4)Deprecated.Gets the value mapped to the specified multi-key.- Parameters:
key1- the first keykey2- the second keykey3- the third keykey4- the fourth key- Returns:
- the mapped value, null if no match
-
containsKey
public boolean containsKey(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3, java.lang.Object key4)Deprecated.Checks whether the map contains the specified multi-key.- Parameters:
key1- the first keykey2- the second keykey3- the third keykey4- the fourth key- Returns:
- true if the map contains the key
-
put
public java.lang.Object put(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3, java.lang.Object key4, java.lang.Object value)Deprecated.Stores the value against the specified multi-key.- Parameters:
key1- the first keykey2- the second keykey3- the third keykey4- the fourth keyvalue- the value to store- Returns:
- the value previously mapped to this combined key, null if none
-
remove
public java.lang.Object remove(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3, java.lang.Object key4)Deprecated.Removes the specified multi-key from this map.- Parameters:
key1- the first keykey2- the second keykey3- the third keykey4- the fourth key- Returns:
- the value mapped to the removed key, null if key not in map
-
get
public java.lang.Object get(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3, java.lang.Object key4, java.lang.Object key5)Deprecated.Gets the value mapped to the specified multi-key.- Parameters:
key1- the first keykey2- the second keykey3- the third keykey4- the fourth keykey5- the fifth key- Returns:
- the mapped value, null if no match
-
containsKey
public boolean containsKey(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3, java.lang.Object key4, java.lang.Object key5)Deprecated.Checks whether the map contains the specified multi-key.- Parameters:
key1- the first keykey2- the second keykey3- the third keykey4- the fourth keykey5- the fifth key- Returns:
- true if the map contains the key
-
put
public java.lang.Object put(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3, java.lang.Object key4, java.lang.Object key5, java.lang.Object value)Deprecated.Stores the value against the specified multi-key.- Parameters:
key1- the first keykey2- the second keykey3- the third keykey4- the fourth keykey5- the fifth keyvalue- the value to store- Returns:
- the value previously mapped to this combined key, null if none
-
remove
public java.lang.Object remove(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3, java.lang.Object key4, java.lang.Object key5)Deprecated.Removes the specified multi-key from this map.- Parameters:
key1- the first keykey2- the second keykey3- the third keykey4- the fourth keykey5- the fifth key- Returns:
- the value mapped to the removed key, null if key not in map
-
removeAll
public boolean removeAll(java.lang.Object key1)
Deprecated.Removes all mappings where the first key is that specified.This method removes all the mappings where the
MultiKeyhas one or more keys, and the first matches that specified.- Parameters:
key1- the first key- Returns:
- true if any elements were removed
-
removeAll
public boolean removeAll(java.lang.Object key1, java.lang.Object key2)Deprecated.Removes 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 keykey2- the second key- Returns:
- true if any elements were removed
-
removeAll
public boolean removeAll(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3)Deprecated.Removes 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 keykey2- the second keykey3- the third key- Returns:
- true if any elements were removed
-
removeAll
public boolean removeAll(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3, java.lang.Object key4)Deprecated.Removes 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 keykey2- the second keykey3- the third keykey4- the fourth key- Returns:
- true if any elements were removed
-
clone
public java.lang.Object clone()
Deprecated.Clones the map without cloning the keys or values.- Returns:
- a shallow clone
-
put
public java.lang.Object put(java.lang.Object key, java.lang.Object value)Deprecated.Puts the key and value into the map, where the key must be a non-null MultiKey object.- Specified by:
putin interfacejava.util.Map- Parameters:
key- the non-null MultiKey objectvalue- the value to store- Returns:
- the previous value for the key
- Throws:
java.lang.NullPointerException- if the key is nulljava.lang.ClassCastException- if the key is not a MultiKey
-
putAll
public void putAll(java.util.Map mapToCopy)
Deprecated.Copies 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 interfacejava.util.Map- Parameters:
mapToCopy- to this map- Throws:
java.lang.NullPointerException- if the mapToCopy or any key within is nulljava.lang.ClassCastException- if any key in mapToCopy is not a MultiKey
-
mapIterator
public MapIterator mapIterator()
Deprecated.Description copied from interface:IterableMapObtains aMapIteratorover the map.A map iterator is an efficient way of iterating over maps. There is no need to access the entry set or cast to Map Entry objects.
IterableMap map = new HashedMap(); MapIterator it = map.mapIterator(); while (it.hasNext()) { Object key = it.next(); Object value = it.getValue(); it.setValue("newValue"); }- Specified by:
mapIteratorin interfaceIterableMap- Returns:
- a map iterator
-
size
public int size()
Deprecated.- Specified by:
sizein interfacejava.util.Map
-
isEmpty
public boolean isEmpty()
Deprecated.- Specified by:
isEmptyin interfacejava.util.Map
-
containsKey
public boolean containsKey(java.lang.Object key)
Deprecated.- Specified by:
containsKeyin interfacejava.util.Map
-
containsValue
public boolean containsValue(java.lang.Object value)
Deprecated.- Specified by:
containsValuein interfacejava.util.Map
-
get
public java.lang.Object get(java.lang.Object key)
Deprecated.- Specified by:
getin interfacejava.util.Map
-
remove
public java.lang.Object remove(java.lang.Object key)
Deprecated.- Specified by:
removein interfacejava.util.Map
-
clear
public void clear()
Deprecated.- Specified by:
clearin interfacejava.util.Map
-
keySet
public java.util.Set keySet()
Deprecated.- Specified by:
keySetin interfacejava.util.Map
-
values
public java.util.Collection values()
Deprecated.- Specified by:
valuesin interfacejava.util.Map
-
entrySet
public java.util.Set entrySet()
Deprecated.- Specified by:
entrySetin interfacejava.util.Map
-
equals
public boolean equals(java.lang.Object obj)
Deprecated.- Specified by:
equalsin interfacejava.util.Map- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
Deprecated.- Specified by:
hashCodein interfacejava.util.Map- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
Deprecated.- Overrides:
toStringin classjava.lang.Object
-
-