|
33 | 33 | import java.util.NoSuchElementException; |
34 | 34 | import java.util.ResourceBundle; |
35 | 35 | import java.util.Set; |
36 | | -import java.util.concurrent.ConcurrentHashMap; |
37 | | -import java.util.concurrent.ConcurrentMap; |
38 | | -import java.util.concurrent.atomic.AtomicMarkableReference; |
| 36 | +import java.util.HashMap; // SwingJS was Concurrent |
| 37 | +import java.util.Map; // SwingJS was Concurrent |
| 38 | +//import java.util.concurrent.atomic.AtomicMarkableReference; |
39 | 39 |
|
40 | 40 | /** |
41 | 41 | * ParallelListResourceBundle is another variant of ListResourceBundle |
|
46 | 46 | * @author Masayoshi Okutsu |
47 | 47 | */ |
48 | 48 | public abstract class ParallelListResourceBundle extends ResourceBundle { |
49 | | - private volatile ConcurrentMap<String, Object> lookup; |
| 49 | + private volatile Map<String, Object> lookup; |
50 | 50 | private volatile Set<String> keyset; |
51 | | - private final AtomicMarkableReference<Object[][]> parallelContents |
52 | | - = new AtomicMarkableReference<>(null, false); |
53 | | - |
| 51 | + private Object[][] parallelContents; |
| 52 | + private boolean done = false; |
54 | 53 | /** |
55 | 54 | * Sole constructor. (For invocation by subclass constructors, typically |
56 | 55 | * implicit.) |
@@ -87,26 +86,34 @@ ResourceBundle getParent() { |
87 | 86 | */ |
88 | 87 | public void setParallelContents(OpenListResourceBundle rb) { |
89 | 88 | if (rb == null) { |
90 | | - parallelContents.compareAndSet(null, null, false, true); |
| 89 | + compareAndSet(null, null, false, true); |
91 | 90 | } else { |
92 | | - parallelContents.compareAndSet(null, rb.getContents(), false, false); |
| 91 | + compareAndSet(null, rb.getContents(), false, false); |
93 | 92 | } |
94 | 93 | } |
95 | 94 |
|
96 | | - /** |
| 95 | + private void compareAndSet(Object[][] orig, Object[][] val, boolean wasdone, boolean done) { |
| 96 | + if (parallelContents == orig && this.done == wasdone) { |
| 97 | + parallelContents = val; this.done = done; |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + /** |
97 | 102 | * Returns true if any parallel contents have been set or if this bundle is |
98 | 103 | * marked as complete. |
99 | 104 | * |
100 | 105 | * @return true if any parallel contents have been processed |
101 | 106 | */ |
102 | 107 | boolean areParallelContentsComplete() { |
103 | | - // Quick check for `complete' |
104 | | - if (parallelContents.isMarked()) { |
105 | | - return true; |
106 | | - } |
107 | | - boolean[] done = new boolean[1]; |
108 | | - Object[][] data = parallelContents.get(done); |
109 | | - return data != null || done[0]; |
| 108 | + return parallelContents != null; |
| 109 | +// return true; |
| 110 | +// // Quick check for `complete' |
| 111 | +// if (parallelContents.isMarked()) { |
| 112 | +// return true; |
| 113 | +// } |
| 114 | +// boolean[] done = new boolean[1]; |
| 115 | +// Object[][] data = parallelContents.get(done); |
| 116 | +// return data != null || done[0]; |
110 | 117 | } |
111 | 118 |
|
112 | 119 | @Override |
@@ -162,21 +169,21 @@ synchronized void resetKeySet() { |
162 | 169 | * Loads the lookup table if they haven't been loaded already. |
163 | 170 | */ |
164 | 171 | void loadLookupTablesIfNecessary() { |
165 | | - ConcurrentMap<String, Object> map = lookup; |
| 172 | + Map<String, Object> map = lookup; |
166 | 173 | if (map == null) { |
167 | | - map = new ConcurrentHashMap<>(); |
| 174 | + map = new HashMap<>(); |
168 | 175 | for (Object[] item : getContents()) { |
169 | 176 | map.put((String) item[0], item[1]); |
170 | 177 | } |
171 | 178 | } |
172 | 179 |
|
173 | 180 | // If there's any parallel contents data, merge the data into map. |
174 | | - Object[][] data = parallelContents.getReference(); |
| 181 | + Object[][] data = parallelContents; |
175 | 182 | if (data != null) { |
176 | 183 | for (Object[] item : data) { |
177 | 184 | map.putIfAbsent((String) item[0], item[1]); |
178 | 185 | } |
179 | | - parallelContents.set(null, true); |
| 186 | + parallelContents = null; |
180 | 187 | } |
181 | 188 | if (lookup == null) { |
182 | 189 | synchronized (this) { |
|
0 commit comments