Class 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
    • 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 is null.
      • 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 is null.
    • 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 interface ReverseMap<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 interface ReverseMap<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.