ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/loops/RLMap.java
Revision: 1.6
Committed: Sun Oct 21 06:40:21 2012 UTC (11 years, 6 months ago) by jsr166
Branch: MAIN
Changes since 1.5: +0 -2 lines
Log Message:
no blank line between javadoc and corresponding code

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 jsr166 1.5 * http://creativecommons.org/publicdomain/zero/1.0/
5 dl 1.2 */
6    
7 dl 1.1 import java.util.*;
8     import java.util.concurrent.*;
9     import java.util.concurrent.locks.*;
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     public class RLMap implements Map {
17     private final Map m;
18     private final ReentrantLock rl = new ReentrantLock();
19 jsr166 1.3
20 dl 1.1 public RLMap(Map m) {
21     if (m == null)
22     throw new NullPointerException();
23     this.m = m;
24     }
25    
26 jsr166 1.3 public RLMap() {
27 dl 1.1 this(new TreeMap()); // use TreeMap by default
28     }
29    
30     public int size() {
31     rl.lock(); try {return m.size();} finally { rl.unlock(); }
32     }
33 jsr166 1.4 public boolean isEmpty() {
34 dl 1.1 rl.lock(); try {return m.isEmpty();} finally { rl.unlock(); }
35     }
36    
37     public Object get(Object key) {
38     rl.lock(); try {return m.get(key);} finally { rl.unlock(); }
39     }
40    
41     public boolean containsKey(Object key) {
42     rl.lock(); try {return m.containsKey(key);} finally { rl.unlock(); }
43     }
44 jsr166 1.4 public boolean containsValue(Object value) {
45 dl 1.1 rl.lock(); try {return m.containsValue(value);} finally { rl.unlock(); }
46     }
47    
48    
49     public Set keySet() { // Not implemented
50     return m.keySet();
51     }
52 jsr166 1.3
53 dl 1.1 public Set entrySet() { // Not implemented
54     return m.entrySet();
55     }
56 jsr166 1.3
57 dl 1.1 public Collection values() { // Not implemented
58     return m.values();
59     }
60 jsr166 1.3
61 dl 1.1 public boolean equals(Object o) {
62     rl.lock(); try {return m.equals(o);} finally { rl.unlock(); }
63     }
64     public int hashCode() {
65     rl.lock(); try {return m.hashCode();} finally { rl.unlock(); }
66     }
67     public String toString() {
68     rl.lock(); try {return m.toString();} finally { rl.unlock(); }
69     }
70    
71    
72    
73     public Object put(Object key, Object value) {
74     rl.lock(); try {return m.put(key, value);} finally { rl.unlock(); }
75     }
76     public Object remove(Object key) {
77     rl.lock(); try {return m.remove(key);} finally { rl.unlock(); }
78     }
79     public void putAll(Map map) {
80     rl.lock(); try {m.putAll(map);} finally { rl.unlock(); }
81     }
82     public void clear() {
83     rl.lock(); try {m.clear();} finally { rl.unlock(); }
84     }
85 jsr166 1.3
86 dl 1.1 }