1 |
/* |
2 |
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
* Expert Group and released to the public domain. Use, modify, and |
4 |
* redistribute this code in any way without acknowledgement. |
5 |
*/ |
6 |
|
7 |
package java.util.concurrent; |
8 |
import java.util.Map; |
9 |
|
10 |
/** |
11 |
* A {@link java.util.Map} providing an additional atomic |
12 |
* <tt>putIfAbsent</tt> method. |
13 |
**/ |
14 |
public interface ConcurrentMap<K, V> extends Map<K, V> { |
15 |
/** |
16 |
* If the specified key is not already associated |
17 |
* with a value, associate it with the given value. |
18 |
* This is equivalent to |
19 |
* <pre> |
20 |
* if (!map.containsKey(key)) map.put(key, value); |
21 |
* return get(key); |
22 |
* </pre> |
23 |
* Except that the action is performed atomically. |
24 |
* @param key key with which the specified value is to be associated. |
25 |
* @param value value to be associated with the specified key. |
26 |
* @return previous value associated with specified key, or <tt>null</tt> |
27 |
* if there was no mapping for key. A <tt>null</tt> return can |
28 |
* also indicate that the map previously associated <tt>null</tt> |
29 |
* with the specified key, if the implementation supports |
30 |
* <tt>null</tt> values. |
31 |
* |
32 |
* @throws UnsupportedOperationException if the <tt>put</tt> operation is |
33 |
* not supported by this map. |
34 |
* @throws ClassCastException if the class of the specified key or value |
35 |
* prevents it from being stored in this map. |
36 |
* @throws IllegalArgumentException if some aspect of this key or value |
37 |
* prevents it from being stored in this map. |
38 |
* @throws NullPointerException this map does not permit <tt>null</tt> |
39 |
* keys or values, and the specified key or value is |
40 |
* <tt>null</tt>. |
41 |
* |
42 |
**/ |
43 |
public V putIfAbsent(K key, V value); |
44 |
} |