ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/loops/SCollection.java
Revision: 1.5
Committed: Thu Jan 15 18:34:19 2015 UTC (9 years, 3 months ago) by jsr166
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +0 -1 lines
Log Message:
delete extraneous blank lines

File Contents

# Content
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/publicdomain/zero/1.0/
5 */
6 import java.util.*;
7 import java.util.concurrent.*;
8 import java.util.concurrent.locks.*;
9
10 /**
11 * This is an incomplete implementation of a wrapper class
12 * that places read-write locks around unsynchronized Collections.
13 * Exists as a sample input for CollectionLoops test.
14 */
15 public final class SCollection<E> implements Collection<E> {
16 private final Collection c;
17 private final ReentrantLock l = new ReentrantLock();
18
19 public SCollection(Collection<E> c) {
20 if (c == null)
21 throw new NullPointerException();
22 this.c = c;
23 }
24
25 public SCollection() {
26 this(new ArrayList<E>());
27 }
28
29 public final int size() {
30 l.lock();
31 try { return c.size(); }
32 finally { l.unlock(); }
33 }
34
35 public final boolean isEmpty() {
36 l.lock();
37 try { return c.isEmpty(); }
38 finally { l.unlock(); }
39 }
40
41 public final boolean contains(Object o) {
42 l.lock();
43 try { return c.contains(o); }
44 finally { l.unlock(); }
45 }
46
47 public final boolean equals(Object o) {
48 l.lock();
49 try { return c.equals(o); }
50 finally { l.unlock(); }
51 }
52
53 public final int hashCode() {
54 l.lock();
55 try { return c.hashCode(); }
56 finally { l.unlock(); }
57 }
58
59 public final String toString() {
60 l.lock();
61 try { return c.toString(); }
62 finally { l.unlock(); }
63 }
64
65 public final Iterator<E> iterator() {
66 l.lock();
67 try { return c.iterator(); }
68 finally { l.unlock(); }
69 }
70
71 public final Object[] toArray() {
72 l.lock();
73 try { return c.toArray(); }
74 finally { l.unlock(); }
75 }
76
77 public final <T> T[] toArray(T[] a) {
78 l.lock();
79 try { return (T[])c.toArray(a); }
80 finally { l.unlock(); }
81 }
82
83 public final boolean add(E e) {
84 l.lock();
85 try { return c.add(e); }
86 finally { l.unlock(); }
87 }
88
89 public final boolean remove(Object o) {
90 l.lock();
91 try { return c.remove(o); }
92 finally { l.unlock(); }
93 }
94
95 public final boolean containsAll(Collection<?> coll) {
96 l.lock();
97 try { return c.containsAll(coll); }
98 finally { l.unlock(); }
99 }
100
101 public final boolean addAll(Collection<? extends E> coll) {
102 l.lock();
103 try { return c.addAll(coll); }
104 finally { l.unlock(); }
105 }
106
107 public final boolean removeAll(Collection<?> coll) {
108 l.lock();
109 try { return c.removeAll(coll); }
110 finally { l.unlock(); }
111 }
112
113 public final boolean retainAll(Collection<?> coll) {
114 l.lock();
115 try { return c.retainAll(coll); }
116 finally { l.unlock(); }
117 }
118
119 public final void clear() {
120 l.lock();
121 try { c.clear(); }
122 finally { l.unlock(); }
123 }
124
125 }