Top Description Constructors Methods
com.google.common.collect

public abstract Class ForwardingConcurrentMap<K, V>

extends ForwardingMap<K, V>
implements ConcurrentMap<K, V>
Class Inheritance
All Implemented Interfaces
java.util.concurrent.ConcurrentMap, java.util.Map
Known Direct Subclasses
com.google.common.collect.MapMakerInternalMap.AbstractSerializationProxy
Annotations
@GwtCompatible
@ElementTypesAreNonnullByDefault
Imports
com.google.common.annotations.GwtCompatible, com.google.errorprone.annotations.CanIgnoreReturnValue, java.util.concurrent.ConcurrentMap, javax.annotation.CheckForNull

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 decorator pattern.

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

Author
Charles Fry
Since
2.0

Constructor Summary

AccessConstructor and Description
protected
ForwardingConcurrentMap()

Constructor for use by subclasses.

Method Summary

Modifier and TypeMethod and Description
protected abstract ConcurrentMap<K, V>
delegate()

Implements abstract com.google.common.collect.ForwardingMap.delegate.

Returns the backing delegate instance that methods are forwarded to.
public V
putIfAbsent(K
key with which the specified value is to be associated
key
,
V
value to be associated with the specified key
value
)

Overrides default java.util.Map.putIfAbsent.

Implements java.util.concurrent.ConcurrentMap.putIfAbsent.

If the specified key is not already associated with a value, associates it with the given value.
public boolean
remove(Object
key with which the specified value is associated
key
,
Object
value expected to be associated with the specified key
value
)

Overrides default java.util.Map.remove.

Implements java.util.concurrent.ConcurrentMap.remove.

Removes the entry for a key only if currently mapped to a given value.
public V
replace(K
key with which the specified value is associated
key
,
V
value to be associated with the specified key
value
)

Overrides default java.util.Map.replace.

Implements java.util.concurrent.ConcurrentMap.replace.

Replaces the entry for a key only if currently mapped to some value.
public boolean
replace(K
key with which the specified value is associated
key
,
V
value expected to be associated with the specified key
oldValue
,
V
value to be associated with the specified key
newValue
)

Overrides default java.util.Map.replace.

Implements java.util.concurrent.ConcurrentMap.replace.

Replaces the entry for a key only if currently mapped to a given value.
Inherited from com.google.common.collect.ForwardingMap:
clearcontainsKeycontainsValueentrySetequalsgethashCodeisEmptykeySetputputAllremovesizestandardClearstandardContainsKeystandardContainsValuestandardEqualsstandardHashCodestandardIsEmptystandardPutAllstandardRemovestandardToStringvalues

Constructor Detail

ForwardingConcurrentMapback to summary
protected ForwardingConcurrentMap()

Constructor for use by subclasses.

Method Detail

delegateback to summary
protected abstract ConcurrentMap<K, V> delegate()

Implements abstract com.google.common.collect.ForwardingMap.delegate.

Doc from com.google.common.collect.ForwardingObject.delegate.

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.

Annotations
@Override
putIfAbsentback to summary
public V putIfAbsent(K key, V value)

Overrides default java.util.Map.putIfAbsent.

Implements java.util.concurrent.ConcurrentMap.putIfAbsent.

Doc from java.util.concurrent.ConcurrentMap.putIfAbsent.

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.
Parameters
key:K

key with which the specified value is to be associated

value:V

value to be associated with the specified key

Returns:V

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.)

Annotations
@CanIgnoreReturnValue
@Override
@CheckForNull
removeback to summary
public boolean remove(Object key, Object value)

Overrides default java.util.Map.remove.

Implements java.util.concurrent.ConcurrentMap.remove.

Doc from java.util.concurrent.ConcurrentMap.remove.

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.
Parameters
key:Object

key with which the specified value is associated

value:Object

value expected to be associated with the specified key

Returns:boolean

true if the value was removed

Annotations
@CanIgnoreReturnValue
@Override
replaceback to summary
public V replace(K key, V value)

Overrides default java.util.Map.replace.

Implements java.util.concurrent.ConcurrentMap.replace.

Doc from java.util.concurrent.ConcurrentMap.replace.

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.
Parameters
key:K

key with which the specified value is associated

value:V

value to be associated with the specified key

Returns:V

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.)

Annotations
@CanIgnoreReturnValue
@Override
@CheckForNull
replaceback to summary
public boolean replace(K key, V oldValue, V newValue)

Overrides default java.util.Map.replace.

Implements java.util.concurrent.ConcurrentMap.replace.

Doc from java.util.concurrent.ConcurrentMap.replace.

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.
Parameters
key:K

key with which the specified value is associated

oldValue:V

value expected to be associated with the specified key

newValue:V

value to be associated with the specified key

Returns:boolean

true if the value was replaced

Annotations
@CanIgnoreReturnValue
@Override