1 |
dl |
1.2 |
/* |
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 |
jsr166 |
1.5 |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
dl |
1.2 |
*/ |
6 |
dl |
1.1 |
import java.util.*; |
7 |
|
|
import java.util.concurrent.*; |
8 |
|
|
import java.util.concurrent.locks.*; |
9 |
|
|
|
10 |
|
|
|
11 |
|
|
/** |
12 |
|
|
* This is an incomplete implementation of a wrapper class |
13 |
|
|
* that places read-write locks around unsynchronized Maps. |
14 |
|
|
* Exists as a sample input for MapLoops test. |
15 |
|
|
*/ |
16 |
|
|
|
17 |
|
|
public class SMap implements Map { |
18 |
|
|
private final Map m; |
19 |
|
|
public SMap(Map m) { |
20 |
|
|
if (m == null) |
21 |
|
|
throw new NullPointerException(); |
22 |
|
|
this.m = m; |
23 |
|
|
} |
24 |
|
|
|
25 |
jsr166 |
1.3 |
public SMap() { |
26 |
dl |
1.1 |
this(new TreeMap()); // use TreeMap by default |
27 |
|
|
} |
28 |
|
|
|
29 |
|
|
public synchronized int size() { |
30 |
|
|
return m.size(); |
31 |
|
|
} |
32 |
jsr166 |
1.4 |
public synchronized boolean isEmpty() { |
33 |
dl |
1.1 |
return m.isEmpty(); |
34 |
|
|
} |
35 |
|
|
|
36 |
|
|
public synchronized Object get(Object key) { |
37 |
|
|
return m.get(key); |
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
public synchronized boolean containsKey(Object key) { |
41 |
|
|
return m.containsKey(key); |
42 |
|
|
} |
43 |
jsr166 |
1.4 |
public synchronized boolean containsValue(Object value) { |
44 |
dl |
1.1 |
return m.containsValue(value); |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
|
48 |
|
|
public synchronized Set keySet() { // Not implemented |
49 |
|
|
return m.keySet(); |
50 |
|
|
} |
51 |
jsr166 |
1.3 |
|
52 |
dl |
1.1 |
public synchronized Set entrySet() { // Not implemented |
53 |
|
|
return m.entrySet(); |
54 |
|
|
} |
55 |
jsr166 |
1.3 |
|
56 |
dl |
1.1 |
public synchronized Collection values() { // Not implemented |
57 |
|
|
return m.values(); |
58 |
|
|
} |
59 |
jsr166 |
1.3 |
|
60 |
dl |
1.1 |
public synchronized boolean equals(Object o) { |
61 |
|
|
return m.equals(o); |
62 |
|
|
} |
63 |
|
|
public synchronized int hashCode() { |
64 |
|
|
return m.hashCode(); |
65 |
|
|
} |
66 |
|
|
public synchronized String toString() { |
67 |
|
|
return m.toString(); |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
|
|
public synchronized Object put(Object key, Object value) { |
73 |
|
|
return m.put(key, value); |
74 |
|
|
} |
75 |
|
|
public synchronized Object remove(Object key) { |
76 |
|
|
return m.remove(key); |
77 |
|
|
} |
78 |
|
|
public synchronized void putAll(Map map) { |
79 |
|
|
m.putAll(map); |
80 |
|
|
} |
81 |
|
|
public synchronized void clear() { |
82 |
|
|
m.clear(); |
83 |
|
|
} |
84 |
jsr166 |
1.3 |
|
85 |
dl |
1.1 |
} |