Replaces the entry for a key only if currently mapped to a given value.
This is equivalent to, for this {@code map}:
<pre> {@code
if (map.containsKey(key)
&& Objects.equals(map.get(key), oldValue)) {
map.put(key, newValue);
return true;
} else {
return false;
}}</pre>
except that the action is performed atomically.
@implNote This implementation intentionally re-abstracts the
inappropriate default provided in {@code Map}.
@param key key with which the specified value is associated
@param oldValue value expected to be associated with the specified key
@param newValue value to be associated with the specified key
@return {@code true} if the value was replaced
@throws UnsupportedOperationException if the {@code put} operation
is not supported by this map
@throws ClassCastException if the class of a specified key or value
prevents it from being stored in this map
@throws NullPointerException if a specified key or value is null,
and this map does not permit null keys or values
@throws IllegalArgumentException if some property of a specified key
or value prevents it from being stored in this map
Replaces the entry for a key only if currently mapped to a given value. This is equivalent to, for this {@code map}: <pre> {@code if (map.containsKey(key) && Objects.equals(map.get(key), oldValue)) { map.put(key, newValue); return true; } else { return false; }}</pre>
except that the action is performed atomically.
@implNote This implementation intentionally re-abstracts the inappropriate default provided in {@code Map}.
@param key key with which the specified value is associated @param oldValue value expected to be associated with the specified key @param newValue value to be associated with the specified key @return {@code true} if the value was replaced @throws UnsupportedOperationException if the {@code put} operation is not supported by this map @throws ClassCastException if the class of a specified key or value prevents it from being stored in this map @throws NullPointerException if a specified key or value is null, and this map does not permit null keys or values @throws IllegalArgumentException if some property of a specified key or value prevents it from being stored in this map