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 |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
import java.util.*; |
7 |
|
import java.util.concurrent.*; |
8 |
|
import java.util.concurrent.locks.*; |
9 |
|
|
10 |
– |
|
10 |
|
/** |
11 |
|
* This is an incomplete implementation of a wrapper class |
12 |
|
* that places read-write locks around unsynchronized Maps. |
13 |
|
* Exists as a sample input for MapLoops test. |
14 |
|
*/ |
16 |
– |
|
15 |
|
public class SMap implements Map { |
16 |
|
private final Map m; |
17 |
|
public SMap(Map m) { |
20 |
|
this.m = m; |
21 |
|
} |
22 |
|
|
23 |
< |
public SMap() { |
23 |
> |
public SMap() { |
24 |
|
this(new TreeMap()); // use TreeMap by default |
25 |
|
} |
26 |
|
|
27 |
|
public synchronized int size() { |
28 |
|
return m.size(); |
29 |
|
} |
30 |
< |
public synchronized boolean isEmpty(){ |
30 |
> |
public synchronized boolean isEmpty() { |
31 |
|
return m.isEmpty(); |
32 |
|
} |
33 |
|
|
38 |
|
public synchronized boolean containsKey(Object key) { |
39 |
|
return m.containsKey(key); |
40 |
|
} |
41 |
< |
public synchronized boolean containsValue(Object value){ |
41 |
> |
public synchronized boolean containsValue(Object value) { |
42 |
|
return m.containsValue(value); |
43 |
|
} |
44 |
|
|
47 |
– |
|
45 |
|
public synchronized Set keySet() { // Not implemented |
46 |
|
return m.keySet(); |
47 |
|
} |
48 |
< |
|
48 |
> |
|
49 |
|
public synchronized Set entrySet() { // Not implemented |
50 |
|
return m.entrySet(); |
51 |
|
} |
52 |
< |
|
52 |
> |
|
53 |
|
public synchronized Collection values() { // Not implemented |
54 |
|
return m.values(); |
55 |
|
} |
56 |
< |
|
56 |
> |
|
57 |
|
public synchronized boolean equals(Object o) { |
58 |
|
return m.equals(o); |
59 |
|
} |
64 |
|
return m.toString(); |
65 |
|
} |
66 |
|
|
70 |
– |
|
71 |
– |
|
67 |
|
public synchronized Object put(Object key, Object value) { |
68 |
|
return m.put(key, value); |
69 |
|
} |
76 |
|
public synchronized void clear() { |
77 |
|
m.clear(); |
78 |
|
} |
79 |
< |
|
79 |
> |
|
80 |
|
} |