Package com.globalmentor.collections
Class DecoratorReadWriteLockReverseMap<K,V>
- java.lang.Object
-
- com.globalmentor.collections.ReadWriteLockDecorator
-
- com.globalmentor.collections.DecoratorReadWriteLockMap<K,V>
-
- com.globalmentor.collections.DecoratorReadWriteLockReverseMap<K,V>
-
- Type Parameters:
K
- The type of key used in the map.V
- The type of value stored in the map.
- All Implemented Interfaces:
ReadWriteLockMap<K,V>
,ReadWriteLockReverseMap<K,V>
,ReverseMap<K,V>
,java.util.concurrent.locks.ReadWriteLock
,java.util.Map<K,V>
public class DecoratorReadWriteLockReverseMap<K,V> extends DecoratorReadWriteLockMap<K,V> implements ReadWriteLockReverseMap<K,V>
A thread-safe map decorator that allows many readers but only one writer to access a map at a time, and that also allows lookup of the map keys keyed to the values by decorating two maps. For operations that iterate over live map data, a read or write lock should be acquired before the call to acquire the data and held until the data is consumed.- Author:
- Garret Wilson
-
-
Field Summary
-
Fields inherited from class com.globalmentor.collections.DecoratorReadWriteLockMap
map
-
-
Constructor Summary
Constructors Constructor Description DecoratorReadWriteLockReverseMap(java.util.Map<K,V> map, java.util.Map<V,K> reverseMap)
Map constructor with a default reentrant read/write lock.DecoratorReadWriteLockReverseMap(java.util.Map<K,V> map, java.util.Map<V,K> reverseMap, java.util.concurrent.locks.ReadWriteLock lock)
Map and read/write lock constructor.
-
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.DecoratorReadWriteLockMap
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 com.globalmentor.collections.ReadWriteLockDecorator
readLock, writeLock
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Constructor Detail
-
DecoratorReadWriteLockReverseMap
public DecoratorReadWriteLockReverseMap(java.util.Map<K,V> map, java.util.Map<V,K> reverseMap)
Map constructor with a default reentrant read/write lock.- Parameters:
map
- The map this map should decorate.reverseMap
- The map to contain reverse lookup values.- Throws:
java.lang.NullPointerException
- if the provided map and/or reverse map isnull
.
-
DecoratorReadWriteLockReverseMap
public DecoratorReadWriteLockReverseMap(java.util.Map<K,V> map, java.util.Map<V,K> reverseMap, java.util.concurrent.locks.ReadWriteLock lock)
Map and read/write lock constructor.- Parameters:
map
- The map this map should decorate.reverseMap
- The map to contain reverse lookup values.lock
- The lock for controlling access to the map.- Throws:
java.lang.NullPointerException
- if the provided map, reverse map, and/or lock isnull
.
-
-
Method Detail
-
getKey
public K getKey(V value)
Description copied from interface:ReverseMap
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:
Map.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 classDecoratorReadWriteLockMap<K,V>
-
remove
public V remove(java.lang.Object key)
-
-