ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ConcurrentMap.java
Revision: 1.21
Committed: Tue Apr 26 01:43:01 2005 UTC (19 years, 1 month ago) by jsr166
Branch: MAIN
Changes since 1.20: +40 -42 lines
Log Message:
doc 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 *
36 * @param key key with which the specified value is to be associated.
37 * @param value value to be associated with the specified key.
38 * @return previous value associated with specified key, or <tt>null</tt>
39 * if there was no mapping for key. A <tt>null</tt> return can
40 * also indicate that the map previously associated <tt>null</tt>
41 * with the specified key, if the implementation supports
42 * <tt>null</tt> values.
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 <tt>null</tt>.
51 *
52 */
53 V putIfAbsent(K key, V value);
54
55 /**
56 * Removes the entry for a key only if currently mapped to a given value.
57 * This is equivalent to
58 * <pre>
59 * if (map.containsKey(key) && map.get(key).equals(value)) {
60 * map.remove(key);
61 * return true;
62 * } else return false;
63 * </pre>
64 * except that the action is performed atomically.
65 *
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 <tt>null</tt>.
73 */
74 boolean remove(Object key, Object value);
75
76 /**
77 * Replaces the entry for a key only if currently mapped to a given value.
78 * This is equivalent to
79 * <pre>
80 * if (map.containsKey(key) && map.get(key).equals(oldValue)) {
81 * map.put(key, newValue);
82 * return true;
83 * } else return false;
84 * </pre>
85 * except that the action is performed atomically.
86 *
87 * @param key key with which the specified value is associated.
88 * @param oldValue value expected to be associated with the specified key.
89 * @param newValue value to be associated with the specified key.
90 * @return true if the value was replaced
91 * @throws UnsupportedOperationException if the <tt>put</tt> operation is
92 * not supported by this map.
93 * @throws NullPointerException if this map does not permit <tt>null</tt>
94 * keys or values, and the specified key or value is <tt>null</tt>.
95 */
96 boolean replace(K key, V oldValue, V newValue);
97
98 /**
99 * Replaces the entry for a key only if currently mapped to some value.
100 * This is equivalent to
101 * <pre>
102 * if (map.containsKey(key)) {
103 * return map.put(key, value);
104 * } else return null;
105 * </pre>
106 * except that the action is performed atomically.
107 *
108 * @param key key with which the specified value is associated.
109 * @param value value to be associated with the specified key.
110 * @return previous value associated with specified key, or <tt>null</tt>
111 * if there was no mapping for key. A <tt>null</tt> return can
112 * also indicate that the map previously associated <tt>null</tt>
113 * with the specified key, if the implementation supports
114 * <tt>null</tt> values.
115 * @throws UnsupportedOperationException if the <tt>put</tt> operation is
116 * not supported by this map.
117 * @throws NullPointerException if this map does not permit <tt>null</tt>
118 * keys or values, and the specified key or value is <tt>null</tt>.
119 */
120 V replace(K key, V value);
121
122 }