ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ConcurrentMap.java
Revision: 1.20
Committed: Thu Jun 24 23:55:02 2004 UTC (19 years, 11 months ago) by dl
Branch: MAIN
Changes since 1.19: +6 -0 lines
Log Message:
Documentation wording fixes

File Contents

# Content
1 /*
2 * Written by Doug Lea with assistance from members of JCP JSR-166
3 * Expert Group and released to the public domain, as explained at
4 * http://creativecommons.org/licenses/publicdomain
5 */
6
7 package java.util.concurrent;
8 import java.util.Map;
9
10 /**
11 * A {@link java.util.Map} providing additional atomic
12 * <tt>putIfAbsent</tt>, <tt>remove</tt>, and <tt>replace</tt> methods.
13 *
14 * <p>This interface is a member of the
15 * <a href="{@docRoot}/../guide/collections/index.html">
16 * Java Collections Framework</a>.
17 *
18 * @since 1.5
19 * @author Doug Lea
20 * @param <K> the type of keys maintained by this map
21 * @param <V> the type of mapped values
22 */
23 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 * if (!map.containsKey(key))
30 * return map.put(key, value);
31 * else
32 * return map.get(key);
33 * </pre>
34 * Except that the action is performed atomically.
35 * @param key key with which the specified value is to be associated.
36 * @param value value to be associated with the specified key.
37 * @return previous value associated with specified key, or <tt>null</tt>
38 * if there was no mapping for key. A <tt>null</tt> return can
39 * also indicate that the map previously associated <tt>null</tt>
40 * with the specified key, if the implementation supports
41 * <tt>null</tt> values.
42 *
43 * @throws UnsupportedOperationException if the <tt>put</tt> operation is
44 * not supported by this map.
45 * @throws ClassCastException if the class of the specified key or value
46 * prevents it from being stored in this map.
47 * @throws IllegalArgumentException if some aspect of this key or value
48 * prevents it from being stored in this map.
49 * @throws NullPointerException if this map does not permit <tt>null</tt>
50 * keys or values, and the specified key or value is
51 * <tt>null</tt>.
52 *
53 */
54 V putIfAbsent(K key, V value);
55
56 /**
57 * Remove entry for key only if currently mapped to given value.
58 * Acts as
59 * <pre>
60 * if ((map.containsKey(key) && map.get(key).equals(value)) {
61 * map.remove(key);
62 * return true;
63 * } else return false;
64 * </pre>
65 * except that the action is performed atomically.
66 * @param key key with which the specified value is associated.
67 * @param value value associated with the specified key.
68 * @return true if the value was removed, false otherwise
69 * @throws UnsupportedOperationException if the <tt>remove</tt> operation is
70 * not supported by this map.
71 * @throws NullPointerException if this map does not permit <tt>null</tt>
72 * keys or values, and the specified key or value is
73 * <tt>null</tt>.
74 */
75 boolean remove(Object key, Object value);
76
77
78 /**
79 * Replace entry for key only if currently mapped to given value.
80 * Acts as
81 * <pre>
82 * if ((map.containsKey(key) && map.get(key).equals(oldValue)) {
83 * map.put(key, newValue);
84 * return true;
85 * } else return false;
86 * </pre>
87 * except that the action is performed atomically.
88 * @param key key with which the specified value is associated.
89 * @param oldValue value expected to be associated with the specified key.
90 * @param newValue value to be associated with the specified key.
91 * @return true if the value was replaced
92 * @throws UnsupportedOperationException if the <tt>put</tt> operation is
93 * not supported by this map.
94 * @throws NullPointerException if this map does not permit <tt>null</tt>
95 * keys or values, and the specified key or value is
96 * <tt>null</tt>.
97 */
98 boolean replace(K key, V oldValue, V newValue);
99
100 /**
101 * Replace entry for key only if currently mapped to some value.
102 * Acts as
103 * <pre>
104 * if ((map.containsKey(key)) {
105 * return map.put(key, value);
106 * } else return null;
107 * </pre>
108 * except that the action is performed atomically.
109 * @param key key with which the specified value is associated.
110 * @param value value to be associated with the specified key.
111 * @return previous value associated with specified key, or <tt>null</tt>
112 * if there was no mapping for key. A <tt>null</tt> return can
113 * also indicate that the map previously associated <tt>null</tt>
114 * with the specified key, if the implementation supports
115 * <tt>null</tt> values.
116 * @throws UnsupportedOperationException if the <tt>put</tt> operation is
117 * not supported by this map.
118 * @throws NullPointerException if this map does not permit <tt>null</tt>
119 * keys or values, and the specified key or value is
120 * <tt>null</tt>.
121 */
122 V replace(K key, V value);
123
124 }