ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/loops/RWMap.java
Revision: 1.3
Committed: Sun Aug 7 19:25:55 2005 UTC (18 years, 9 months ago) by dl
Branch: MAIN
Changes since 1.2: +1 -0 lines
Log Message:
Add exchanger performance tests; update others

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