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>
,java.util.Map<K,V>
public class DecoratorReverseMap<K,V> extends MapDecorator<K,V> implements ReverseMap<K,V>
A map that also allows lookup of the map keys keyed to the values by decorating two maps.- Author:
- Garret Wilson
-
-
Field Summary
-
Fields inherited from class com.globalmentor.collections.MapDecorator
map
-
-
Constructor Summary
Constructors Constructor Description DecoratorReverseMap(java.util.Map<K,V> map, java.util.Map<V,K> reverseMap)
Constructs a reverse map by decorating two other maps.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
boolean
containsValue(java.lang.Object value)
K
getKey(V value)
Returns the key that represents the given value.V
put(K key, V value)
V
remove(java.lang.Object key)
K
removeValue(V value)
Removes the mapping for a value from this map if it is present.-
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
-
-
-
-
Constructor Detail
-
DecoratorReverseMap
public DecoratorReverseMap(java.util.Map<K,V> map, java.util.Map<V,K> reverseMap)
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:
java.lang.NullPointerException
- if the given map and/or reverse map isnull
.
-
-
Method Detail
-
getKey
public K getKey(V value)
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:
containsValue(Object)
-
removeValue
public K removeValue(V value)
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
public boolean containsValue(java.lang.Object value)
- Specified by:
containsValue
in interfacejava.util.Map<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.
-
remove
public V remove(java.lang.Object key)
-
-