ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ConcurrentMap.java
Revision: 1.14
Committed: Fri Nov 28 12:37:00 2003 UTC (20 years, 6 months ago) by dl
Branch: MAIN
Changes since 1.13: +23 -2 lines
Log Message:
Added replace method

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. Use, modify, and
4 * redistribute this code in any way without acknowledgement.
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 * @since 1.5
14 * @author Doug Lea
15 * @param <K> the type of keys maintained by this map
16 * @param <V> the type of mapped values
17 */
18 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 * if (!map.containsKey(key))
25 * return map.put(key, value);
26 * else
27 * return map.get(key);
28 * </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 * @throws NullPointerException if this map does not permit <tt>null</tt>
45 * keys or values, and the specified key or value is
46 * <tt>null</tt>.
47 *
48 **/
49 V putIfAbsent(K key, V value);
50
51 /**
52 * Remove entry for key only if currently mapped to given value.
53 * Acts as
54 * <pre>
55 * if ((map.containsKey(key) && map.get(key).equals(value)) {
56 * map.remove(key);
57 * return true;
58 * } else return false;
59 * </pre>
60 * except that the action is performed atomically.
61 * @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 * @throws NullPointerException if this map does not permit <tt>null</tt>
65 * keys or values, and the specified key or value is
66 * <tt>null</tt>.
67 */
68 boolean remove(Object key, Object value);
69
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
91 }