ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/loops/RLMap.java
Revision: 1.3
Committed: Thu Oct 29 23:09:08 2009 UTC (14 years, 6 months ago) by jsr166
Branch: MAIN
Changes since 1.2: +6 -6 lines
Log Message:
whitespace

File Contents

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