ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ConcurrentMap.java
Revision: 1.25
Committed: Wed May 18 00:40:58 2005 UTC (19 years ago) by jsr166
Branch: MAIN
Changes since 1.24: +22 -13 lines
Log Message:
doc fixes

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