Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/test/java/util/concurrent/locks/ReentrantReadWriteLock/RWMap.java
+++ new/test/java/util/concurrent/locks/ReentrantReadWriteLock/RWMap.java
1 1 /*
2 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3 3 *
4 4 * This code is free software; you can redistribute it and/or modify it
5 5 * under the terms of the GNU General Public License version 2 only, as
6 6 * published by the Free Software Foundation.
7 7 *
8 8 * This code is distributed in the hope that it will be useful, but WITHOUT
9 9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 11 * version 2 for more details (a copy is included in the LICENSE file that
12 12 * accompanied this code).
13 13 *
14 14 * You should have received a copy of the GNU General Public License version
15 15 * 2 along with this work; if not, write to the Free Software Foundation,
16 16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17 17 *
18 18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19 19 * or visit www.oracle.com if you need additional information or have any
20 20 * questions.
21 21 */
22 22
23 23 /*
24 24 * This file is available under and governed by the GNU General Public
25 25 * License version 2 only, as published by the Free Software Foundation.
26 26 * However, the following notice accompanied the original version of this
27 27 * file:
28 28 *
29 29 * Written by Doug Lea with assistance from members of JCP JSR-166
30 30 * Expert Group and released to the public domain, as explained at
31 31 * http://creativecommons.org/licenses/publicdomain
32 32 */
33 33
34 34 import java.util.*;
35 35 import java.util.concurrent.*;
36 36 import java.util.concurrent.locks.*;
37 37
38 38
39 39 /**
40 40 * This is an incomplete implementation of a wrapper class
41 41 * that places read-write locks around unsynchronized Maps.
42 42 * Exists as a sample input for MapLoops test.
43 43 */
44 44
45 45 public class RWMap implements Map {
46 46 private final Map m;
47 47 private final ReentrantReadWriteLock rwl = new ReentrantReadWriteLock();
48 48
49 49 public RWMap(Map m) {
↓ open down ↓ |
49 lines elided |
↑ open up ↑ |
50 50 if (m == null)
51 51 throw new NullPointerException();
52 52 this.m = m;
53 53 }
54 54
55 55 public RWMap() {
56 56 this(new TreeMap()); // use TreeMap by default
57 57 }
58 58
59 59 public int size() {
60 - rwl.readLock().lock(); try {return m.size();} finally { rwl.readLock().unlock(); }
60 + rwl.readLock().lock();
61 + try { return m.size(); }
62 + finally { rwl.readLock().unlock(); }
61 63 }
62 - public boolean isEmpty(){
63 - rwl.readLock().lock(); try {return m.isEmpty();} finally { rwl.readLock().unlock(); }
64 +
65 + public boolean isEmpty() {
66 + rwl.readLock().lock();
67 + try { return m.isEmpty(); }
68 + finally { rwl.readLock().unlock(); }
64 69 }
65 70
66 71 public Object get(Object key) {
67 - rwl.readLock().lock(); try {return m.get(key);} finally { rwl.readLock().unlock(); }
72 + rwl.readLock().lock();
73 + try { return m.get(key); }
74 + finally { rwl.readLock().unlock(); }
68 75 }
69 76
70 77 public boolean containsKey(Object key) {
71 - rwl.readLock().lock(); try {return m.containsKey(key);} finally { rwl.readLock().unlock(); }
78 + rwl.readLock().lock();
79 + try { return m.containsKey(key); }
80 + finally { rwl.readLock().unlock(); }
72 81 }
73 - public boolean containsValue(Object value){
74 - rwl.readLock().lock(); try {return m.containsValue(value);} finally { rwl.readLock().unlock(); }
82 +
83 + public boolean containsValue(Object value) {
84 + rwl.readLock().lock();
85 + try { return m.containsValue(value); }
86 + finally { rwl.readLock().unlock(); }
75 87 }
76 88
77 89
78 90 public Set keySet() { // Not implemented
79 91 return null;
80 92 }
81 93
82 94 public Set entrySet() { // Not implemented
83 95 return null;
84 96 }
85 97
86 98 public Collection values() { // Not implemented
87 99 return null;
88 100 }
89 101
90 102 public boolean equals(Object o) {
91 - rwl.readLock().lock(); try {return m.equals(o);} finally { rwl.readLock().unlock(); }
103 + rwl.readLock().lock();
104 + try { return m.equals(o); }
105 + finally { rwl.readLock().unlock(); }
92 106 }
107 +
93 108 public int hashCode() {
94 - rwl.readLock().lock(); try {return m.hashCode();} finally { rwl.readLock().unlock(); }
109 + rwl.readLock().lock();
110 + try { return m.hashCode(); }
111 + finally { rwl.readLock().unlock(); }
95 112 }
113 +
96 114 public String toString() {
97 - rwl.readLock().lock(); try {return m.toString();} finally { rwl.readLock().unlock(); }
115 + rwl.readLock().lock();
116 + try { return m.toString(); }
117 + finally { rwl.readLock().unlock(); }
98 118 }
99 119
100 -
101 -
102 120 public Object put(Object key, Object value) {
103 - rwl.writeLock().lock(); try {return m.put(key, value);} finally { rwl.writeLock().unlock(); }
121 + rwl.writeLock().lock();
122 + try { return m.put(key, value); }
123 + finally { rwl.writeLock().unlock(); }
104 124 }
125 +
105 126 public Object remove(Object key) {
106 - rwl.writeLock().lock(); try {return m.remove(key);} finally { rwl.writeLock().unlock(); }
127 + rwl.writeLock().lock();
128 + try { return m.remove(key); }
129 + finally { rwl.writeLock().unlock(); }
107 130 }
131 +
108 132 public void putAll(Map map) {
109 - rwl.writeLock().lock(); try {m.putAll(map);} finally { rwl.writeLock().unlock(); }
133 + rwl.writeLock().lock();
134 + try { m.putAll(map); }
135 + finally { rwl.writeLock().unlock(); }
110 136 }
137 +
111 138 public void clear() {
112 - rwl.writeLock().lock(); try {m.clear();} finally { rwl.writeLock().unlock(); }
139 + rwl.writeLock().lock();
140 + try { m.clear(); }
141 + finally { rwl.writeLock().unlock(); }
113 142 }
114 143
115 144 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX