1 |
dl |
1.2 |
/* |
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 |
tim |
1.1 |
package java.util.concurrent; |
8 |
|
|
import java.util.Map; |
9 |
|
|
|
10 |
|
|
/** |
11 |
dl |
1.11 |
* A {@link java.util.Map} providing additional atomic |
12 |
dl |
1.6 |
* <tt>putIfAbsent</tt> and <tt>remove</tt> methods. |
13 |
dl |
1.4 |
* @since 1.5 |
14 |
|
|
* @author Doug Lea |
15 |
dl |
1.13 |
* @param <K> the type of keys maintained by this map |
16 |
|
|
* @param <V> the type of mapped values |
17 |
dl |
1.4 |
*/ |
18 |
tim |
1.1 |
public interface ConcurrentMap<K, V> extends Map<K, V> { |
19 |
|
|
/** |
20 |
|
|
* If the specified key is not already associated |
21 |
|
|
* with a value, associate it with the given value. |
22 |
|
|
* This is equivalent to |
23 |
|
|
* <pre> |
24 |
dl |
1.5 |
* if (!map.containsKey(key)) |
25 |
|
|
* return map.put(key, value); |
26 |
|
|
* else |
27 |
|
|
* return map.get(key); |
28 |
tim |
1.1 |
* </pre> |
29 |
|
|
* Except that the action is performed atomically. |
30 |
|
|
* @param key key with which the specified value is to be associated. |
31 |
|
|
* @param value value to be associated with the specified key. |
32 |
|
|
* @return previous value associated with specified key, or <tt>null</tt> |
33 |
|
|
* if there was no mapping for key. A <tt>null</tt> return can |
34 |
|
|
* also indicate that the map previously associated <tt>null</tt> |
35 |
|
|
* with the specified key, if the implementation supports |
36 |
|
|
* <tt>null</tt> values. |
37 |
|
|
* |
38 |
|
|
* @throws UnsupportedOperationException if the <tt>put</tt> operation is |
39 |
|
|
* not supported by this map. |
40 |
|
|
* @throws ClassCastException if the class of the specified key or value |
41 |
|
|
* prevents it from being stored in this map. |
42 |
|
|
* @throws IllegalArgumentException if some aspect of this key or value |
43 |
|
|
* prevents it from being stored in this map. |
44 |
dholmes |
1.9 |
* @throws NullPointerException if this map does not permit <tt>null</tt> |
45 |
tim |
1.1 |
* keys or values, and the specified key or value is |
46 |
|
|
* <tt>null</tt>. |
47 |
|
|
* |
48 |
|
|
**/ |
49 |
dl |
1.4 |
V putIfAbsent(K key, V value); |
50 |
dl |
1.6 |
|
51 |
|
|
/** |
52 |
|
|
* Remove entry for key only if currently mapped to given value. |
53 |
|
|
* Acts as |
54 |
|
|
* <pre> |
55 |
dl |
1.7 |
* if (map.get(key).equals(value)) { |
56 |
|
|
* map.remove(key); |
57 |
|
|
* return true; |
58 |
tim |
1.10 |
* } else return false; |
59 |
dl |
1.6 |
* </pre> |
60 |
|
|
* except that the action is performed atomically. |
61 |
dl |
1.7 |
* @param key key with which the specified value is associated. |
62 |
|
|
* @param value value associated with the specified key. |
63 |
|
|
* @return true if the value was removed |
64 |
dholmes |
1.9 |
* @throws NullPointerException if this map does not permit <tt>null</tt> |
65 |
dl |
1.8 |
* keys or values, and the specified key or value is |
66 |
|
|
* <tt>null</tt>. |
67 |
dl |
1.6 |
*/ |
68 |
dl |
1.7 |
boolean remove(Object key, Object value); |
69 |
dl |
1.6 |
|
70 |
tim |
1.1 |
} |