ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ConcurrentMap.java
Revision: 1.17
Committed: Sat Dec 27 19:26:25 2003 UTC (20 years, 5 months ago) by dl
Branch: MAIN
Changes since 1.16: +2 -2 lines
Log Message:
Headers reference Creative Commons

File Contents

# User Rev Content
1 dl 1.2 /*
2     * Written by Doug Lea with assistance from members of JCP JSR-166
3 dl 1.17 * Expert Group and released to the public domain, as explained at
4     * http://creativecommons.org/licenses/publicdomain
5 dl 1.2 */
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.14 * <tt>putIfAbsent</tt>, <tt>remove</tt>, and <tt>replace</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.14 * if ((map.containsKey(key) && map.get(key).equals(value)) {
56 dl 1.7 * 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.14
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 dl 1.6
91 dl 1.15 /**
92     * Replace entry for key only if currently mapped to some value.
93     * Acts as
94     * <pre>
95     * if ((map.containsKey(key)) {
96 dl 1.16 * return map.put(key, value);
97     * } else return null;
98 dl 1.15 * </pre>
99     * except that the action is performed atomically.
100     * @param key key with which the specified value is associated.
101     * @param value value to be associated with the specified key.
102 dl 1.16 * @return previous value associated with specified key, or <tt>null</tt>
103     * if there was no mapping for key. A <tt>null</tt> return can
104     * also indicate that the map previously associated <tt>null</tt>
105     * with the specified key, if the implementation supports
106     * <tt>null</tt> values.
107 dl 1.15 * @throws NullPointerException if this map does not permit <tt>null</tt>
108     * keys or values, and the specified key or value is
109     * <tt>null</tt>.
110     */
111 dl 1.16 V replace(K key, V value);
112 dl 1.15
113 tim 1.1 }