ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ConcurrentMap.java
Revision: 1.33
Committed: Wed Apr 20 19:08:20 2011 UTC (13 years, 1 month ago) by dl
Branch: MAIN
Changes since 1.32: +2 -2 lines
Log Message:
Use relative URLs in last change

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 jsr166 1.31 * http://creativecommons.org/publicdomain/zero/1.0/
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.19 *
14 jsr166 1.29 * <p>Memory consistency effects: As with other concurrent
15     * collections, actions in a thread prior to placing an object into a
16     * {@code ConcurrentMap} as a key or value
17     * <a href="package-summary.html#MemoryVisibility"><i>happen-before</i></a>
18     * actions subsequent to the access or removal of that object from
19     * the {@code ConcurrentMap} in another thread.
20     *
21 dl 1.19 * <p>This interface is a member of the
22 jsr166 1.30 * <a href="{@docRoot}/../technotes/guides/collections/index.html">
23 dl 1.19 * Java Collections Framework</a>.
24 jsr166 1.21 *
25 dl 1.4 * @since 1.5
26     * @author Doug Lea
27 dl 1.13 * @param <K> the type of keys maintained by this map
28 jsr166 1.21 * @param <V> the type of mapped values
29 dl 1.4 */
30 tim 1.1 public interface ConcurrentMap<K, V> extends Map<K, V> {
31     /**
32     * If the specified key is not already associated
33     * with a value, associate it with the given value.
34     * This is equivalent to
35     * <pre>
36 jsr166 1.21 * if (!map.containsKey(key))
37     * return map.put(key, value);
38 dl 1.5 * else
39 jsr166 1.23 * return map.get(key);</pre>
40 jsr166 1.21 * except that the action is performed atomically.
41     *
42 jsr166 1.24 * @param key key with which the specified value is to be associated
43     * @param value value to be associated with the specified key
44 jsr166 1.25 * @return the previous value associated with the specified key, or
45     * <tt>null</tt> if there was no mapping for the key.
46 jsr166 1.24 * (A <tt>null</tt> return can also indicate that the map
47 jsr166 1.25 * previously associated <tt>null</tt> with the key,
48     * if the implementation supports null values.)
49 jsr166 1.22 * @throws UnsupportedOperationException if the <tt>put</tt> operation
50 jsr166 1.24 * is not supported by this map
51 tim 1.1 * @throws ClassCastException if the class of the specified key or value
52 jsr166 1.24 * prevents it from being stored in this map
53     * @throws NullPointerException if the specified key or value is null,
54     * and this map does not permit null keys or values
55     * @throws IllegalArgumentException if some property of the specified key
56     * or value prevents it from being stored in this map
57 tim 1.1 *
58 dl 1.18 */
59 dl 1.4 V putIfAbsent(K key, V value);
60 dl 1.6
61     /**
62 jsr166 1.21 * Removes the entry for a key only if currently mapped to a given value.
63     * This is equivalent to
64     * <pre>
65 jsr166 1.24 * if (map.containsKey(key) &amp;&amp; map.get(key).equals(value)) {
66 jsr166 1.21 * map.remove(key);
67     * return true;
68 jsr166 1.23 * } else return false;</pre>
69 dl 1.6 * except that the action is performed atomically.
70 jsr166 1.21 *
71 jsr166 1.24 * @param key key with which the specified value is associated
72 jsr166 1.25 * @param value value expected to be associated with the specified key
73     * @return <tt>true</tt> if the value was removed
74 jsr166 1.22 * @throws UnsupportedOperationException if the <tt>remove</tt> operation
75 jsr166 1.24 * is not supported by this map
76 jsr166 1.25 * @throws ClassCastException if the key or value is of an inappropriate
77 dl 1.32 * is incompatible with this deque
78 dl 1.33 * (<a href="../Collection.html#optional-restrictions">optional</a>)
79 jsr166 1.24 * @throws NullPointerException if the specified key or value is null,
80 dl 1.32 * and this map does not permit null keys or values
81 dl 1.33 * (<a href="../Collection.html#optional-restrictions">optional</a>)
82 dl 1.6 */
83 dl 1.7 boolean remove(Object key, Object value);
84 dl 1.14
85     /**
86 jsr166 1.21 * Replaces the entry for a key only if currently mapped to a given value.
87     * This is equivalent to
88     * <pre>
89 jsr166 1.24 * if (map.containsKey(key) &amp;&amp; map.get(key).equals(oldValue)) {
90 jsr166 1.21 * map.put(key, newValue);
91     * return true;
92 jsr166 1.23 * } else return false;</pre>
93 dl 1.14 * except that the action is performed atomically.
94 jsr166 1.21 *
95 jsr166 1.24 * @param key key with which the specified value is associated
96     * @param oldValue value expected to be associated with the specified key
97     * @param newValue value to be associated with the specified key
98 jsr166 1.25 * @return <tt>true</tt> if the value was replaced
99 jsr166 1.22 * @throws UnsupportedOperationException if the <tt>put</tt> operation
100 jsr166 1.24 * is not supported by this map
101 jsr166 1.25 * @throws ClassCastException if the class of a specified key or value
102     * prevents it from being stored in this map
103 jsr166 1.24 * @throws NullPointerException if a specified key or value is null,
104     * and this map does not permit null keys or values
105 jsr166 1.25 * @throws IllegalArgumentException if some property of a specified key
106     * or value prevents it from being stored in this map
107 dl 1.14 */
108     boolean replace(K key, V oldValue, V newValue);
109 dl 1.6
110 dl 1.15 /**
111 jsr166 1.21 * Replaces the entry for a key only if currently mapped to some value.
112     * This is equivalent to
113     * <pre>
114     * if (map.containsKey(key)) {
115     * return map.put(key, value);
116 jsr166 1.23 * } else return null;</pre>
117 dl 1.15 * except that the action is performed atomically.
118 jsr166 1.21 *
119 jsr166 1.24 * @param key key with which the specified value is associated
120     * @param value value to be associated with the specified key
121 jsr166 1.25 * @return the previous value associated with the specified key, or
122     * <tt>null</tt> if there was no mapping for the key.
123 jsr166 1.24 * (A <tt>null</tt> return can also indicate that the map
124 jsr166 1.25 * previously associated <tt>null</tt> with the key,
125     * if the implementation supports null values.)
126 jsr166 1.22 * @throws UnsupportedOperationException if the <tt>put</tt> operation
127 jsr166 1.24 * is not supported by this map
128 jsr166 1.25 * @throws ClassCastException if the class of the specified key or value
129     * prevents it from being stored in this map
130 jsr166 1.24 * @throws NullPointerException if the specified key or value is null,
131     * and this map does not permit null keys or values
132 jsr166 1.25 * @throws IllegalArgumentException if some property of the specified key
133     * or value prevents it from being stored in this map
134 dl 1.15 */
135 dl 1.16 V replace(K key, V value);
136 tim 1.1 }