Package com.google.common.collect
Class ForwardingConcurrentMap<K,V>
- java.lang.Object
-
- com.google.common.collect.ForwardingObject
-
- com.google.common.collect.ForwardingMap<K,V>
-
- com.google.common.collect.ForwardingConcurrentMap<K,V>
-
- All Implemented Interfaces:
ConcurrentMap<K,V>,Map<K,V>
@GwtCompatible public abstract class ForwardingConcurrentMap<K,V> extends ForwardingMap<K,V> implements ConcurrentMap<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 decorator pattern.defaultmethod warning: This class forwards calls to only somedefaultmethods. Specifically, it forwards calls only for methods that existed beforedefaultmethods were introduced. For newer methods, likeforEach, it inherits their default implementations. When those implementations invoke methods, they invoke methods on theForwardingConcurrentMap.- Since:
- 2.0
- Author:
- Charles Fry
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.common.collect.ForwardingMap
ForwardingMap.StandardEntrySet, ForwardingMap.StandardKeySet, ForwardingMap.StandardValues
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedForwardingConcurrentMap()Constructor for use by subclasses.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract ConcurrentMap<K,V>delegate()Returns the backing delegate instance that methods are forwarded to.VputIfAbsent(K key, V value)If the specified key is not already associated with a value, associates it with the given value.booleanremove(Object key, Object value)Removes the entry for a key only if currently mapped to a given value.Vreplace(K key, V value)Replaces the entry for a key only if currently mapped to some value.booleanreplace(K key, V oldValue, V newValue)Replaces the entry for a key only if currently mapped to a given value.-
Methods inherited from class com.google.common.collect.ForwardingMap
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, standardClear, standardContainsKey, standardContainsValue, standardEquals, standardHashCode, standardIsEmpty, standardPutAll, standardRemove, standardToString, values
-
Methods inherited from class com.google.common.collect.ForwardingObject
toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.concurrent.ConcurrentMap
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, replaceAll
-
-
-
-
Constructor Detail
-
ForwardingConcurrentMap
protected ForwardingConcurrentMap()
Constructor for use by subclasses.
-
-
Method Detail
-
delegate
protected abstract ConcurrentMap<K,V> delegate()
Description copied from class:ForwardingObjectReturns 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 asForwardingSet.delegate(). Concrete subclasses override this method to supply the instance being decorated.- Specified by:
delegatein classForwardingMap<K,V>
-
putIfAbsent
@CanIgnoreReturnValue @CheckForNull public V putIfAbsent(K key, V value)
Description copied from interface:java.util.concurrent.ConcurrentMapIf the specified key is not already associated with a value, associates it with the given value. This is equivalent to, for thismap:
except that the action is performed atomically.if (!map.containsKey(key)) return map.put(key, value); else return map.get(key);- Specified by:
putIfAbsentin interfaceConcurrentMap<K,V>- Specified by:
putIfAbsentin interfaceMap<K,V>- Parameters:
key- key with which the specified value is to be associatedvalue- value to be associated with the specified key- Returns:
- the previous value associated with the specified key, or
nullif there was no mapping for the key. (Anullreturn can also indicate that the map previously associatednullwith the key, if the implementation supports null values.)
-
remove
@CanIgnoreReturnValue public boolean remove(@CheckForNull Object key, @CheckForNull Object value)
Description copied from interface:java.util.concurrent.ConcurrentMapRemoves the entry for a key only if currently mapped to a given value. This is equivalent to, for thismap:
except that the action is performed atomically.if (map.containsKey(key) && Objects.equals(map.get(key), value)) { map.remove(key); return true; } else { return false; }
-
replace
@CanIgnoreReturnValue @CheckForNull public V replace(K key, V value)
Description copied from interface:java.util.concurrent.ConcurrentMapReplaces the entry for a key only if currently mapped to some value. This is equivalent to, for thismap:
except that the action is performed atomically.if (map.containsKey(key)) return map.put(key, value); else return null;- Specified by:
replacein interfaceConcurrentMap<K,V>- Specified by:
replacein interfaceMap<K,V>- Parameters:
key- key with which the specified value is associatedvalue- value to be associated with the specified key- Returns:
- the previous value associated with the specified key, or
nullif there was no mapping for the key. (Anullreturn can also indicate that the map previously associatednullwith the key, if the implementation supports null values.)
-
replace
@CanIgnoreReturnValue public boolean replace(K key, V oldValue, V newValue)
Description copied from interface:java.util.concurrent.ConcurrentMapReplaces the entry for a key only if currently mapped to a given value. This is equivalent to, for thismap:
except that the action is performed atomically.if (map.containsKey(key) && Objects.equals(map.get(key), oldValue)) { map.put(key, newValue); return true; } else { return false; }- Specified by:
replacein interfaceConcurrentMap<K,V>- Specified by:
replacein interfaceMap<K,V>- Parameters:
key- key with which the specified value is associatedoldValue- value expected to be associated with the specified keynewValue- value to be associated with the specified key- Returns:
trueif the value was replaced
-
-