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