9 |
|
|
10 |
|
/** |
11 |
|
* A {@link java.util.Map} providing additional atomic |
12 |
< |
* <tt>putIfAbsent</tt> and <tt>remove</tt> methods. |
12 |
> |
* <tt>putIfAbsent</tt>, <tt>remove</tt>, and <tt>replace</tt> methods. |
13 |
|
* @since 1.5 |
14 |
|
* @author Doug Lea |
15 |
|
* @param <K> the type of keys maintained by this map |
52 |
|
* Remove entry for key only if currently mapped to given value. |
53 |
|
* Acts as |
54 |
|
* <pre> |
55 |
< |
* if (map.get(key).equals(value)) { |
55 |
> |
* if ((map.containsKey(key) && map.get(key).equals(value)) { |
56 |
|
* map.remove(key); |
57 |
|
* return true; |
58 |
|
* } else return false; |
67 |
|
*/ |
68 |
|
boolean remove(Object key, Object value); |
69 |
|
|
70 |
+ |
|
71 |
+ |
/** |
72 |
+ |
* Replace entry for key only if currently mapped to given value. |
73 |
+ |
* Acts as |
74 |
+ |
* <pre> |
75 |
+ |
* if ((map.containsKey(key) && map.get(key).equals(oldValue)) { |
76 |
+ |
* map.put(key, newValue); |
77 |
+ |
* return true; |
78 |
+ |
* } else return false; |
79 |
+ |
* </pre> |
80 |
+ |
* except that the action is performed atomically. |
81 |
+ |
* @param key key with which the specified value is associated. |
82 |
+ |
* @param oldValue value expected to be associated with the specified key. |
83 |
+ |
* @param newValue value to be associated with the specified key. |
84 |
+ |
* @return true if the value was replaced |
85 |
+ |
* @throws NullPointerException if this map does not permit <tt>null</tt> |
86 |
+ |
* keys or values, and the specified key or value is |
87 |
+ |
* <tt>null</tt>. |
88 |
+ |
*/ |
89 |
+ |
boolean replace(K key, V oldValue, V newValue); |
90 |
+ |
|
91 |
|
} |