Class ForwardingConcurrentMap<K,​V>

  • All Implemented Interfaces:
    <K,​V>, <K,​V>

    @GwtCompatible
    public abstract class ForwardingConcurrentMap<K,​V>
    extends ForwardingMap<K,​V>
    implements <K,​V>
    A concurrent map which forwards all its method calls to another concurrent map. Subclasses should override one or more methods to modify the behavior of the backing map as desired per the .

    default method warning: This class forwards calls to only some default methods. Specifically, it forwards calls only for methods that existed . For newer methods, like forEach, it inherits their default implementations. When those implementations invoke methods, they invoke methods on the ForwardingConcurrentMap.

    Since:
    2.0
    Author:
    Charles Fry
    • Method Detail

      • delegate

        protected abstract <K,​Vdelegate()
        Description copied from class: ForwardingObject
        Returns the backing delegate instance that methods are forwarded to. Abstract subclasses generally override this method with an abstract method that has a more specific return type, such as ForwardingSet.delegate(). Concrete subclasses override this method to supply the instance being decorated.
        Specified by:
        delegate in class ForwardingMap<K,​V>
      • putIfAbsent

        public V putIfAbsent​(K key,
                             V value)
        Description copied from interface: 
        If the specified key is not already associated with a value, associates it with the given value. This is equivalent to, for this map:
         
         if (!map.containsKey(key))
           return map.put(key, value);
         else
           return map.get(key);
        except that the action is performed atomically.
        Specified by:
         in interface <K,​V>
        Specified by:
         in interface <K,​V>
        Parameters:
        key - key with which the specified value is to be associated
        value - value to be associated with the specified key
        Returns:
        the previous value associated with the specified key, or null if there was no mapping for the key. (A null return can also indicate that the map previously associated null with the key, if the implementation supports null values.)
      • remove

        public boolean  key,
                               value)
        Description copied from interface: 
        Removes the entry for a key only if currently mapped to a given value. This is equivalent to, for this map:
         
         if (map.containsKey(key)
             && Objects.equals(map.get(key), value)) {
           map.remove(key);
           return true;
         } else {
           return false;
         }
        except that the action is performed atomically.
        Specified by:
         in interface <K,​V>
        Specified by:
         in interface <K,​V>
        Parameters:
        key - key with which the specified value is associated
        value - value expected to be associated with the specified key
        Returns:
        true if the value was removed
      • replace

        public V replace​(K key,
                         V value)
        Description copied from interface: 
        Replaces the entry for a key only if currently mapped to some value. This is equivalent to, for this map:
         
         if (map.containsKey(key))
           return map.put(key, value);
         else
           return null;
        except that the action is performed atomically.
        Specified by:
         in interface <K,​V>
        Specified by:
         in interface <K,​V>
        Parameters:
        key - key with which the specified value is associated
        value - value to be associated with the specified key
        Returns:
        the previous value associated with the specified key, or null if there was no mapping for the key. (A null return can also indicate that the map previously associated null with the key, if the implementation supports null values.)
      • replace

        public boolean replace​(K key,
                               V oldValue,
                               V newValue)
        Description copied from interface: 
        Replaces the entry for a key only if currently mapped to a given value. This is equivalent to, for this map:
         
         if (map.containsKey(key)
             && Objects.equals(map.get(key), oldValue)) {
           map.put(key, newValue);
           return true;
         } else {
           return false;
         }
        except that the action is performed atomically.
        Specified by:
         in interface <K,​V>
        Specified by:
         in interface <K,​V>
        Parameters:
        key - key with which the specified value is associated
        oldValue - value expected to be associated with the specified key
        newValue - value to be associated with the specified key
        Returns:
        true if the value was replaced