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> ReadWriteLock
,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
-
Nested Class Summary
-
Field Summary
Fields inherited from class com.globalmentor.collections.DecoratorReadWriteLockMap
map
-
Constructor Summary
ConstructorDescriptionMap constructor with a default reentrant read/write lock.DecoratorReadWriteLockReverseMap
(Map<K, V> map, Map<V, K> reverseMap, ReadWriteLock lock) Map and read/write lock constructor. -
Method Summary
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
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
Methods inherited from interface java.util.concurrent.locks.ReadWriteLock
readLock, writeLock
-
Constructor Details
-
DecoratorReadWriteLockReverseMap
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:
NullPointerException
- if the provided map and/or reverse map isnull
.
-
DecoratorReadWriteLockReverseMap
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:
NullPointerException
- if the provided map, reverse map, and/or lock isnull
.
-
-
Method Details
-
getKey
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:
-
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 classDecoratorReadWriteLockMap<K,
V>
-
put
-
remove
-
clear
public void clear()
-