Package com.globalmentor.collections
Class DecoratorReverseMap<K,V>
java.lang.Object
com.globalmentor.collections.MapDecorator<K,V>
com.globalmentor.collections.DecoratorReverseMap<K,V>
- Type Parameters:
K
- The type of map key.V
- The type of map value.The keys and values in this map have a one-to-one relationship. Associating multiple values with a key will likely result in errant functionality.
- All Implemented Interfaces:
ReverseMap<K,
,V> Map<K,
V>
A map that also allows lookup of the map keys keyed to the values by decorating two maps.
- Author:
- Garret Wilson
-
Nested Class Summary
-
Field Summary
Fields inherited from class com.globalmentor.collections.MapDecorator
map
-
Constructor Summary
-
Method Summary
Methods inherited from class com.globalmentor.collections.MapDecorator
compute, computeIfAbsent, computeIfPresent, containsKey, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, putAll, putIfAbsent, remove, replace, replace, replaceAll, size, values
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, containsKey, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, putAll, putIfAbsent, remove, replace, replace, replaceAll, size, values
-
Constructor Details
-
DecoratorReverseMap
Constructs a reverse map by decorating two other maps.- Parameters:
map
- The main map to be decorated.reverseMap
- The map to contain reverse lookup values.- Throws:
NullPointerException
- if the given map and/or reverse map isnull
.
-
-
Method Details
-
getKey
Returns the key that represents the given value.- Specified by:
getKey
in interfaceReverseMap<K,
V> - Parameters:
value
- The value whose associated key is to be returned.- Returns:
- The key to which this map reverse maps the specified value, or
null
if the map contains no reverse mapping for this value. - See Also:
-
removeValue
Description copied from interface:ReverseMap
Removes the mapping for a value from this map if it is present.- Specified by:
removeValue
in interfaceReverseMap<K,
V> - Parameters:
value
- The value whose mapping is to be removed from the map.- Returns:
- The previous key associated with the value, or
null
if there was no mapping for the value.
-
containsValue
- Specified by:
containsValue
in interfaceMap<K,
V> - Overrides:
containsValue
in classMapDecorator<K,
V> - Implementation Specification:
- This version uses an internal reverse map to provide faster lookups than the default linear-time lookup.
-
put
-
remove
-
clear
public void clear()
-