1 | sclass SynchronizedCollection<A> implements Collection<A> { |
2 | Collection<A> c; // Backing Collection |
3 | Object mutex; // Object on which to synchronize |
4 | |
5 | *() {} // for persistence |
6 | *(Collection<A> c) { |
7 | this.c = Objects.requireNonNull(c); |
8 | mutex = this; |
9 | } |
10 | |
11 | *(Collection<A> c, Object mutex) { |
12 | this.c = Objects.requireNonNull(c); |
13 | this.mutex = Objects.requireNonNull(mutex); |
14 | } |
15 | |
16 | public int size() { |
17 | synchronized (mutex) {return c.size();} |
18 | } |
19 | public boolean isEmpty() { |
20 | synchronized (mutex) {return c.isEmpty();} |
21 | } |
22 | public boolean contains(Object o) { |
23 | synchronized (mutex) {return c.contains(o);} |
24 | } |
25 | public Object[] toArray() { |
26 | synchronized (mutex) {return c.toArray();} |
27 | } |
28 | public <T> T[] toArray(T[] a) { |
29 | synchronized (mutex) {return c.toArray(a);} |
30 | } |
31 | |
32 | public Iterator<A> iterator() { |
33 | return c.iterator(); // Must be manually synched by user! |
34 | } |
35 | |
36 | public boolean add(A A) { |
37 | synchronized (mutex) {return c.add(A);} |
38 | } |
39 | public boolean remove(Object o) { |
40 | synchronized (mutex) {return c.remove(o);} |
41 | } |
42 | |
43 | public boolean containsAll(Collection<?> coll) { |
44 | synchronized (mutex) {return c.containsAll(coll);} |
45 | } |
46 | public boolean addAll(Collection<? extends A> coll) { |
47 | synchronized (mutex) {return c.addAll(coll);} |
48 | } |
49 | public boolean removeAll(Collection<?> coll) { |
50 | synchronized (mutex) {return c.removeAll(coll);} |
51 | } |
52 | public boolean retainAll(Collection<?> coll) { |
53 | synchronized (mutex) {return c.retainAll(coll);} |
54 | } |
55 | public void clear() { |
56 | synchronized (mutex) {c.clear();} |
57 | } |
58 | public String toString() { |
59 | synchronized (mutex) {return c.toString();} |
60 | } |
61 | |
62 | /*public void forEach(Consumer<? super A> consumer) { |
63 | synchronized (mutex) {c.forEach(consumer);} |
64 | }*/ |
65 | |
66 | /*public boolean removeIf(Predicate<? super A> filter) { |
67 | synchronized (mutex) {return c.removeIf(filter);} |
68 | }*/ |
69 | @Override |
70 | public Spliterator<A> spliterator() { |
71 | return c.spliterator(); // Must be manually synched by user! |
72 | } |
73 | |
74 | /*public Stream<A> stream() { |
75 | return c.stream(); // Must be manually synched by user! |
76 | }*/ |
77 | |
78 | /*public Stream<A> parallelStream() { |
79 | return c.parallelStream(); // Must be manually synched by user! |
80 | }*/ |
81 | } |
Began life as a copy of #1009403
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1031169 |
Snippet name: | SynchronizedCollection [not copied from JDK] |
Eternal ID of this version: | #1031169/1 |
Text MD5: | 89286b89521102e4a53beeae44076beb |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-05-16 17:43:24 |
Source code size: | 2354 bytes / 81 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 170 / 224 |
Referenced in: | [show references] |