Libraryless. Click here for Pure Java version (4775L/27K).
1 | static persistable class SynchronizedList<E> |
2 | extends SynchronizedCollection<E> |
3 | implements List<E> { |
4 | /*final*/ List<E> list; |
5 | |
6 | SynchronizedList(List<E> list) { |
7 | super(list); |
8 | this.list = list; |
9 | } |
10 | SynchronizedList(List<E> list, Object mutex) { |
11 | super(list, mutex); |
12 | this.list = list; |
13 | } |
14 | |
15 | public boolean equals(Object o) { |
16 | if (this == o) |
17 | return true; |
18 | synchronized (mutex) {return list.equals(o);} |
19 | } |
20 | public int hashCode() { |
21 | synchronized (mutex) {return list.hashCode();} |
22 | } |
23 | |
24 | public E get(int index) { |
25 | synchronized (mutex) {return list.get(index);} |
26 | } |
27 | public E set(int index, E element) { |
28 | synchronized (mutex) {return list.set(index, element);} |
29 | } |
30 | public void add(int index, E element) { |
31 | synchronized (mutex) {list.add(index, element);} |
32 | } |
33 | public E remove(int index) { |
34 | synchronized (mutex) {return list.remove(index);} |
35 | } |
36 | |
37 | public int indexOf(Object o) { |
38 | synchronized (mutex) {return list.indexOf(o);} |
39 | } |
40 | public int lastIndexOf(Object o) { |
41 | synchronized (mutex) {return list.lastIndexOf(o);} |
42 | } |
43 | |
44 | public boolean addAll(int index, Collection<? extends E> c) { |
45 | synchronized (mutex) {return list.addAll(index, c);} |
46 | } |
47 | |
48 | public ListIterator<E> listIterator() { |
49 | return list.listIterator(); // Must be manually synched by user |
50 | } |
51 | |
52 | public ListIterator<E> listIterator(int index) { |
53 | return list.listIterator(index); // Must be manually synched by user |
54 | } |
55 | |
56 | public List<E> subList(int fromIndex, int toIndex) { |
57 | synchronized (mutex) { |
58 | return new SynchronizedList<>(list.subList(fromIndex, toIndex), |
59 | mutex); |
60 | } |
61 | } |
62 | |
63 | @Override |
64 | public void replaceAll(java.util.function.UnaryOperator<E> operator) { |
65 | synchronized (mutex) {list.replaceAll(operator);} |
66 | } |
67 | @Override |
68 | public void sort(Comparator<? super E> c) { |
69 | synchronized (mutex) {list.sort(c);} |
70 | } |
71 | |
72 | /** |
73 | * SynchronizedRandomAccessList instances are serialized as |
74 | * SynchronizedList instances to allow them to be deserialized |
75 | * in pre-1.4 JREs (which do not have SynchronizedRandomAccessList). |
76 | * This method inverts the transformation. As a beneficial |
77 | * side-effect, it also grafts the RandomAccess marker onto |
78 | * SynchronizedList instances that were serialized in pre-1.4 JREs. |
79 | * |
80 | * Note: Unfortunately, SynchronizedRandomAccessList instances |
81 | * serialized in 1.4.1 and deserialized in 1.4 will become |
82 | * SynchronizedList instances, as this method was missing in 1.4. |
83 | */ |
84 | @java.io.Serial |
85 | private Object readResolve() { |
86 | return (list instanceof RandomAccess |
87 | ? new SynchronizedRandomAccessList<>(list) |
88 | : this); |
89 | } |
90 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1031171 |
Snippet name: | SynchronizedList [copied from JDK] |
Eternal ID of this version: | #1031171/3 |
Text MD5: | 8067a7cbde7998388a2d77a7f2d44c0e |
Transpilation MD5: | 19a2e942523233897dca14ec53fa7f20 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-01-08 21:14:06 |
Source code size: | 2982 bytes / 90 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 274 / 493 |
Version history: | 2 change(s) |
Referenced in: | [show references] |