|
Lines 60-66
Link Here
|
| 60 |
|
60 |
|
| 61 |
protected void firstListenerAdded() { |
61 |
protected void firstListenerAdded() { |
| 62 |
if (!isDisposed()) { |
62 |
if (!isDisposed()) { |
| 63 |
cachedList = property.getList(source); |
63 |
cachedList = getList(); |
| 64 |
|
64 |
|
| 65 |
if (listener == null) { |
65 |
if (listener == null) { |
| 66 |
listener = property |
66 |
listener = property |
|
Lines 72-79
Link Here
|
| 72 |
getRealm().exec(new Runnable() { |
72 |
getRealm().exec(new Runnable() { |
| 73 |
public void run() { |
73 |
public void run() { |
| 74 |
List oldList = cachedList; |
74 |
List oldList = cachedList; |
| 75 |
List newList = cachedList = property |
75 |
List newList = cachedList = getList(); |
| 76 |
.getList(source); |
|
|
| 77 |
ListDiff diff = event.diff; |
76 |
ListDiff diff = event.diff; |
| 78 |
if (diff == null) { |
77 |
if (diff == null) { |
| 79 |
diff = Diffs.computeListDiff( |
78 |
diff = Diffs.computeListDiff( |
|
Lines 108-187
Link Here
|
| 108 |
|
107 |
|
| 109 |
// Queries |
108 |
// Queries |
| 110 |
|
109 |
|
|
|
110 |
private List getList() { |
| 111 |
return property.getList(source); |
| 112 |
} |
| 113 |
|
| 111 |
protected int doGetSize() { |
114 |
protected int doGetSize() { |
| 112 |
return property.size(source); |
115 |
return getList().size(); |
| 113 |
} |
116 |
} |
| 114 |
|
117 |
|
| 115 |
public boolean contains(Object o) { |
118 |
public boolean contains(Object o) { |
| 116 |
getterCalled(); |
119 |
getterCalled(); |
| 117 |
return property.contains(source, o); |
120 |
return getList().contains(o); |
| 118 |
} |
121 |
} |
| 119 |
|
122 |
|
| 120 |
public boolean containsAll(Collection c) { |
123 |
public boolean containsAll(Collection c) { |
| 121 |
getterCalled(); |
124 |
getterCalled(); |
| 122 |
return property.containsAll(source, c); |
125 |
return getList().containsAll(c); |
| 123 |
} |
126 |
} |
| 124 |
|
127 |
|
| 125 |
public Object get(int index) { |
128 |
public Object get(int index) { |
| 126 |
getterCalled(); |
129 |
getterCalled(); |
| 127 |
return property.get(source, index); |
130 |
return getList().get(index); |
| 128 |
} |
131 |
} |
| 129 |
|
132 |
|
| 130 |
public int indexOf(Object o) { |
133 |
public int indexOf(Object o) { |
| 131 |
getterCalled(); |
134 |
getterCalled(); |
| 132 |
return property.indexOf(source, o); |
135 |
return getList().indexOf(o); |
| 133 |
} |
136 |
} |
| 134 |
|
137 |
|
| 135 |
public boolean isEmpty() { |
138 |
public boolean isEmpty() { |
| 136 |
getterCalled(); |
139 |
getterCalled(); |
| 137 |
return property.isEmpty(source); |
140 |
return getList().isEmpty(); |
| 138 |
} |
141 |
} |
| 139 |
|
142 |
|
| 140 |
public int lastIndexOf(Object o) { |
143 |
public int lastIndexOf(Object o) { |
| 141 |
getterCalled(); |
144 |
getterCalled(); |
| 142 |
return property.lastIndexOf(source, o); |
145 |
return getList().lastIndexOf(o); |
| 143 |
} |
146 |
} |
| 144 |
|
147 |
|
| 145 |
public Object[] toArray() { |
148 |
public Object[] toArray() { |
| 146 |
getterCalled(); |
149 |
getterCalled(); |
| 147 |
return property.toArray(source); |
150 |
return getList().toArray(); |
| 148 |
} |
151 |
} |
| 149 |
|
152 |
|
| 150 |
public Object[] toArray(Object[] a) { |
153 |
public Object[] toArray(Object[] a) { |
| 151 |
getterCalled(); |
154 |
getterCalled(); |
| 152 |
return property.toArray(source, a); |
155 |
return getList().toArray(a); |
| 153 |
} |
156 |
} |
| 154 |
|
157 |
|
| 155 |
// Single change operations |
158 |
// Single change operations |
| 156 |
|
159 |
|
| 157 |
public boolean add(Object o) { |
160 |
public boolean add(Object o) { |
| 158 |
checkRealm(); |
161 |
checkRealm(); |
| 159 |
add(property.size(source), o); |
162 |
add(getList().size(), o); |
| 160 |
return true; |
163 |
return true; |
| 161 |
} |
164 |
} |
| 162 |
|
165 |
|
| 163 |
public void add(int index, Object o) { |
166 |
public void add(int index, Object o) { |
| 164 |
checkRealm(); |
167 |
checkRealm(); |
| 165 |
boolean wasUpdating = updating; |
168 |
boolean wasUpdating = updating; |
|
|
169 |
boolean changed; |
| 166 |
updating = true; |
170 |
updating = true; |
|
|
171 |
List list = new ArrayList(getList()); |
| 172 |
list.add(index, o); |
| 173 |
ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry(index, |
| 174 |
true, o)); |
| 167 |
try { |
175 |
try { |
| 168 |
property.add(source, index, o); |
176 |
changed = property.setList(source, list, diff); |
| 169 |
modCount++; |
177 |
modCount++; |
| 170 |
} finally { |
178 |
} finally { |
| 171 |
updating = wasUpdating; |
179 |
updating = wasUpdating; |
| 172 |
} |
180 |
} |
| 173 |
|
181 |
|
| 174 |
cachedList = property.getList(source); |
182 |
if (changed) { |
| 175 |
fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(index, |
183 |
cachedList = getList(); |
| 176 |
true, o))); |
184 |
fireListChange(diff); |
|
|
185 |
} |
| 177 |
} |
186 |
} |
| 178 |
|
187 |
|
| 179 |
public Iterator iterator() { |
188 |
public Iterator iterator() { |
| 180 |
getterCalled(); |
189 |
getterCalled(); |
| 181 |
return new Iterator() { |
190 |
return new Iterator() { |
| 182 |
int expectedModCount = modCount; |
191 |
int expectedModCount = modCount; |
| 183 |
ListIterator delegate = new ArrayList(property.getList(source)) |
192 |
List list = new ArrayList(getList()); |
| 184 |
.listIterator(); |
193 |
ListIterator iterator = list.listIterator(); |
| 185 |
|
194 |
|
| 186 |
Object lastElement = null; |
195 |
Object lastElement = null; |
| 187 |
int lastIndex = -1; |
196 |
int lastIndex = -1; |
|
Lines 189-202
Link Here
|
| 189 |
public boolean hasNext() { |
198 |
public boolean hasNext() { |
| 190 |
getterCalled(); |
199 |
getterCalled(); |
| 191 |
checkForComodification(); |
200 |
checkForComodification(); |
| 192 |
return delegate.hasNext(); |
201 |
return iterator.hasNext(); |
| 193 |
} |
202 |
} |
| 194 |
|
203 |
|
| 195 |
public Object next() { |
204 |
public Object next() { |
| 196 |
getterCalled(); |
205 |
getterCalled(); |
| 197 |
checkForComodification(); |
206 |
checkForComodification(); |
| 198 |
Object next = lastElement = delegate.next(); |
207 |
Object next = lastElement = iterator.next(); |
| 199 |
lastIndex = delegate.previousIndex(); |
208 |
lastIndex = iterator.previousIndex(); |
| 200 |
return next; |
209 |
return next; |
| 201 |
} |
210 |
} |
| 202 |
|
211 |
|
|
Lines 206-230
Link Here
|
| 206 |
if (lastIndex == -1) |
215 |
if (lastIndex == -1) |
| 207 |
throw new IllegalStateException(); |
216 |
throw new IllegalStateException(); |
| 208 |
|
217 |
|
| 209 |
delegate.remove(); // stay in sync |
218 |
iterator.remove(); // stay in sync |
|
|
219 |
ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( |
| 220 |
lastIndex, false, lastElement)); |
| 210 |
|
221 |
|
| 211 |
boolean wasUpdating = updating; |
222 |
boolean wasUpdating = updating; |
|
|
223 |
boolean changed; |
| 212 |
updating = true; |
224 |
updating = true; |
| 213 |
try { |
225 |
try { |
| 214 |
property.remove(source, lastIndex); |
226 |
changed = property.setList(source, list, diff); |
| 215 |
modCount++; |
227 |
modCount++; |
| 216 |
} finally { |
228 |
} finally { |
| 217 |
updating = wasUpdating; |
229 |
updating = wasUpdating; |
| 218 |
} |
230 |
} |
| 219 |
|
231 |
|
| 220 |
cachedList = property.getList(source); |
232 |
if (changed) { |
| 221 |
fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( |
233 |
cachedList = getList(); |
| 222 |
lastIndex, false, lastElement))); |
234 |
fireListChange(diff); |
| 223 |
|
235 |
|
| 224 |
lastElement = null; |
236 |
lastElement = null; |
| 225 |
lastIndex = -1; |
237 |
lastIndex = -1; |
| 226 |
|
238 |
|
| 227 |
expectedModCount = modCount; |
239 |
expectedModCount = modCount; |
|
|
240 |
} |
| 228 |
} |
241 |
} |
| 229 |
|
242 |
|
| 230 |
private void checkForComodification() { |
243 |
private void checkForComodification() { |
|
Lines 237-264
Link Here
|
| 237 |
public Object move(int oldIndex, int newIndex) { |
250 |
public Object move(int oldIndex, int newIndex) { |
| 238 |
checkRealm(); |
251 |
checkRealm(); |
| 239 |
|
252 |
|
| 240 |
int size = property.size(source); |
253 |
List list = getList(); |
|
|
254 |
int size = list.size(); |
| 241 |
if (oldIndex < 0 || oldIndex >= size || newIndex < 0 |
255 |
if (oldIndex < 0 || oldIndex >= size || newIndex < 0 |
| 242 |
|| newIndex >= size) |
256 |
|| newIndex >= size) |
| 243 |
throw new IndexOutOfBoundsException(); |
257 |
throw new IndexOutOfBoundsException(); |
|
|
258 |
|
| 244 |
if (oldIndex == newIndex) |
259 |
if (oldIndex == newIndex) |
| 245 |
return property.get(source, oldIndex); |
260 |
return list.get(oldIndex); |
| 246 |
|
261 |
|
| 247 |
Object element; |
262 |
list = new ArrayList(list); |
|
|
263 |
Object element = list.remove(oldIndex); |
| 264 |
list.add(newIndex, element); |
| 265 |
|
| 266 |
ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( |
| 267 |
oldIndex, false, element), Diffs.createListDiffEntry(newIndex, |
| 268 |
true, element)); |
| 248 |
|
269 |
|
| 249 |
boolean wasUpdating = updating; |
270 |
boolean wasUpdating = updating; |
|
|
271 |
boolean changed; |
| 250 |
updating = true; |
272 |
updating = true; |
| 251 |
try { |
273 |
try { |
| 252 |
element = property.move(source, oldIndex, newIndex); |
274 |
changed = property.setList(source, list, diff); |
| 253 |
modCount++; |
275 |
modCount++; |
| 254 |
} finally { |
276 |
} finally { |
| 255 |
updating = wasUpdating; |
277 |
updating = wasUpdating; |
| 256 |
} |
278 |
} |
| 257 |
|
279 |
|
| 258 |
cachedList = property.getList(source); |
280 |
if (changed) { |
| 259 |
fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(oldIndex, |
281 |
cachedList = getList(); |
| 260 |
false, element), Diffs.createListDiffEntry(newIndex, true, |
282 |
fireListChange(diff); |
| 261 |
element))); |
283 |
} |
| 262 |
|
284 |
|
| 263 |
return element; |
285 |
return element; |
| 264 |
} |
286 |
} |
|
Lines 266-272
Link Here
|
| 266 |
public boolean remove(Object o) { |
288 |
public boolean remove(Object o) { |
| 267 |
checkRealm(); |
289 |
checkRealm(); |
| 268 |
|
290 |
|
| 269 |
int index = property.indexOf(source, o); |
291 |
int index = getList().indexOf(o); |
| 270 |
if (index == -1) |
292 |
if (index == -1) |
| 271 |
return false; |
293 |
return false; |
| 272 |
|
294 |
|
|
Lines 283-290
Link Here
|
| 283 |
getterCalled(); |
305 |
getterCalled(); |
| 284 |
return new ListIterator() { |
306 |
return new ListIterator() { |
| 285 |
int expectedModCount = modCount; |
307 |
int expectedModCount = modCount; |
| 286 |
ListIterator delegate = new ArrayList(property.getList(source)) |
308 |
List list = new ArrayList(getList()); |
| 287 |
.listIterator(index); |
309 |
ListIterator iterator = list.listIterator(index); |
| 288 |
|
310 |
|
| 289 |
Object lastElement = null; |
311 |
Object lastElement = null; |
| 290 |
int lastIndex = -1; |
312 |
int lastIndex = -1; |
|
Lines 292-382
Link Here
|
| 292 |
public boolean hasNext() { |
314 |
public boolean hasNext() { |
| 293 |
getterCalled(); |
315 |
getterCalled(); |
| 294 |
checkForComodification(); |
316 |
checkForComodification(); |
| 295 |
return delegate.hasNext(); |
317 |
return iterator.hasNext(); |
| 296 |
} |
318 |
} |
| 297 |
|
319 |
|
| 298 |
public int nextIndex() { |
320 |
public int nextIndex() { |
| 299 |
getterCalled(); |
321 |
getterCalled(); |
| 300 |
checkForComodification(); |
322 |
checkForComodification(); |
| 301 |
return delegate.nextIndex(); |
323 |
return iterator.nextIndex(); |
| 302 |
} |
324 |
} |
| 303 |
|
325 |
|
| 304 |
public Object next() { |
326 |
public Object next() { |
| 305 |
getterCalled(); |
327 |
getterCalled(); |
| 306 |
checkForComodification(); |
328 |
checkForComodification(); |
| 307 |
lastElement = delegate.next(); |
329 |
lastElement = iterator.next(); |
| 308 |
lastIndex = delegate.previousIndex(); |
330 |
lastIndex = iterator.previousIndex(); |
| 309 |
return lastElement; |
331 |
return lastElement; |
| 310 |
} |
332 |
} |
| 311 |
|
333 |
|
| 312 |
public boolean hasPrevious() { |
334 |
public boolean hasPrevious() { |
| 313 |
getterCalled(); |
335 |
getterCalled(); |
| 314 |
checkForComodification(); |
336 |
checkForComodification(); |
| 315 |
return delegate.hasPrevious(); |
337 |
return iterator.hasPrevious(); |
| 316 |
} |
338 |
} |
| 317 |
|
339 |
|
| 318 |
public int previousIndex() { |
340 |
public int previousIndex() { |
| 319 |
getterCalled(); |
341 |
getterCalled(); |
| 320 |
checkForComodification(); |
342 |
checkForComodification(); |
| 321 |
return delegate.previousIndex(); |
343 |
return iterator.previousIndex(); |
| 322 |
} |
344 |
} |
| 323 |
|
345 |
|
| 324 |
public Object previous() { |
346 |
public Object previous() { |
| 325 |
getterCalled(); |
347 |
getterCalled(); |
| 326 |
checkForComodification(); |
348 |
checkForComodification(); |
| 327 |
lastElement = delegate.previous(); |
349 |
lastElement = iterator.previous(); |
| 328 |
lastIndex = delegate.nextIndex(); |
350 |
lastIndex = iterator.nextIndex(); |
| 329 |
return lastElement; |
351 |
return lastElement; |
| 330 |
} |
352 |
} |
| 331 |
|
353 |
|
| 332 |
public void add(Object o) { |
354 |
public void add(Object o) { |
| 333 |
checkRealm(); |
355 |
checkRealm(); |
| 334 |
checkForComodification(); |
356 |
checkForComodification(); |
| 335 |
int index = delegate.nextIndex(); |
357 |
int index = iterator.nextIndex(); |
| 336 |
|
358 |
|
| 337 |
delegate.add(o); // keep in sync |
359 |
iterator.add(o); // keep in sync |
| 338 |
|
360 |
|
|
|
361 |
List list = getList(); |
| 362 |
list.add(index, o); |
| 363 |
ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( |
| 364 |
index, true, o)); |
| 339 |
boolean wasUpdating = updating; |
365 |
boolean wasUpdating = updating; |
|
|
366 |
boolean changed; |
| 340 |
updating = true; |
367 |
updating = true; |
| 341 |
try { |
368 |
try { |
| 342 |
property.add(source, index, o); |
369 |
changed = property.setList(source, list, diff); |
| 343 |
modCount++; |
370 |
modCount++; |
| 344 |
} finally { |
371 |
} finally { |
| 345 |
updating = wasUpdating; |
372 |
updating = wasUpdating; |
| 346 |
} |
373 |
} |
| 347 |
|
374 |
|
| 348 |
cachedList = property.getList(source); |
375 |
if (changed) { |
| 349 |
fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( |
376 |
cachedList = getList(); |
| 350 |
index, true, o))); |
377 |
fireListChange(diff); |
| 351 |
|
378 |
|
| 352 |
lastElement = null; |
379 |
lastElement = null; |
| 353 |
lastIndex = -1; |
380 |
lastIndex = -1; |
| 354 |
expectedModCount = modCount; |
381 |
expectedModCount = modCount; |
|
|
382 |
} |
| 355 |
} |
383 |
} |
| 356 |
|
384 |
|
| 357 |
public void set(Object o) { |
385 |
public void set(Object o) { |
| 358 |
checkRealm(); |
386 |
checkRealm(); |
| 359 |
checkForComodification(); |
387 |
checkForComodification(); |
| 360 |
|
388 |
|
| 361 |
delegate.set(o); |
389 |
iterator.set(o); |
|
|
390 |
ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( |
| 391 |
lastIndex, false, lastElement), Diffs |
| 392 |
.createListDiffEntry(lastIndex, true, o)); |
| 362 |
|
393 |
|
| 363 |
boolean wasUpdating = updating; |
394 |
boolean wasUpdating = updating; |
|
|
395 |
boolean changed; |
| 364 |
updating = true; |
396 |
updating = true; |
| 365 |
try { |
397 |
try { |
| 366 |
property.set(source, lastIndex, o); |
398 |
changed = property.setList(source, list, diff); |
| 367 |
modCount++; |
399 |
modCount++; |
| 368 |
} finally { |
400 |
} finally { |
| 369 |
updating = wasUpdating; |
401 |
updating = wasUpdating; |
| 370 |
} |
402 |
} |
| 371 |
|
403 |
|
| 372 |
cachedList = property.getList(source); |
404 |
if (changed) { |
| 373 |
fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( |
405 |
cachedList = getList(); |
| 374 |
lastIndex, false, lastElement), Diffs |
406 |
fireListChange(diff); |
| 375 |
.createListDiffEntry(lastIndex, true, o))); |
|
|
| 376 |
|
407 |
|
| 377 |
lastElement = o; |
408 |
lastElement = o; |
| 378 |
|
409 |
|
| 379 |
expectedModCount = modCount; |
410 |
expectedModCount = modCount; |
|
|
411 |
} |
| 380 |
} |
412 |
} |
| 381 |
|
413 |
|
| 382 |
public void remove() { |
414 |
public void remove() { |
|
Lines 385-408
Link Here
|
| 385 |
if (lastIndex == -1) |
417 |
if (lastIndex == -1) |
| 386 |
throw new IllegalStateException(); |
418 |
throw new IllegalStateException(); |
| 387 |
|
419 |
|
| 388 |
delegate.remove(); // keep in sync |
420 |
iterator.remove(); // keep in sync |
|
|
421 |
ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( |
| 422 |
lastIndex, false, lastElement)); |
| 389 |
|
423 |
|
| 390 |
boolean wasUpdating = updating; |
424 |
boolean wasUpdating = updating; |
|
|
425 |
boolean changed; |
| 391 |
updating = true; |
426 |
updating = true; |
| 392 |
try { |
427 |
try { |
| 393 |
property.remove(source, lastIndex); |
428 |
changed = property.setList(source, list, diff); |
| 394 |
modCount++; |
429 |
modCount++; |
| 395 |
} finally { |
430 |
} finally { |
| 396 |
updating = wasUpdating; |
431 |
updating = wasUpdating; |
| 397 |
} |
432 |
} |
| 398 |
|
433 |
|
| 399 |
cachedList = property.getList(source); |
434 |
if (changed) { |
| 400 |
fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( |
435 |
cachedList = getList(); |
| 401 |
lastIndex, false, lastElement))); |
436 |
fireListChange(diff); |
| 402 |
|
437 |
|
| 403 |
lastElement = null; |
438 |
lastElement = null; |
| 404 |
lastIndex = -1; |
439 |
lastIndex = -1; |
| 405 |
expectedModCount = modCount; |
440 |
expectedModCount = modCount; |
|
|
441 |
} |
| 406 |
} |
442 |
} |
| 407 |
|
443 |
|
| 408 |
private void checkForComodification() { |
444 |
private void checkForComodification() { |
|
Lines 415-434
Link Here
|
| 415 |
public Object remove(int index) { |
451 |
public Object remove(int index) { |
| 416 |
checkRealm(); |
452 |
checkRealm(); |
| 417 |
|
453 |
|
| 418 |
Object element; |
454 |
List list = new ArrayList(getList()); |
|
|
455 |
Object element = list.remove(index); |
| 456 |
ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry(index, |
| 457 |
false, element)); |
| 419 |
|
458 |
|
| 420 |
boolean wasUpdating = updating; |
459 |
boolean wasUpdating = updating; |
|
|
460 |
boolean changed; |
| 421 |
updating = true; |
461 |
updating = true; |
| 422 |
try { |
462 |
try { |
| 423 |
element = property.remove(source, index); |
463 |
changed = property.setList(source, list, diff); |
| 424 |
modCount++; |
464 |
modCount++; |
| 425 |
} finally { |
465 |
} finally { |
| 426 |
updating = wasUpdating; |
466 |
updating = wasUpdating; |
| 427 |
} |
467 |
} |
| 428 |
|
468 |
|
| 429 |
cachedList = property.getList(source); |
469 |
if (changed) { |
| 430 |
fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(index, |
470 |
cachedList = getList(); |
| 431 |
false, element))); |
471 |
fireListChange(diff); |
|
|
472 |
} |
| 432 |
|
473 |
|
| 433 |
return element; |
474 |
return element; |
| 434 |
} |
475 |
} |
|
Lines 436-463
Link Here
|
| 436 |
public Object set(int index, Object o) { |
477 |
public Object set(int index, Object o) { |
| 437 |
checkRealm(); |
478 |
checkRealm(); |
| 438 |
|
479 |
|
| 439 |
Object oldElement; |
480 |
List list = new ArrayList(getList()); |
|
|
481 |
Object oldElement = list.set(index, o); |
| 482 |
|
| 483 |
ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry(index, |
| 484 |
false, oldElement), Diffs.createListDiffEntry(index, true, o)); |
| 440 |
|
485 |
|
| 441 |
boolean wasUpdating = updating; |
486 |
boolean wasUpdating = updating; |
|
|
487 |
boolean changed; |
| 442 |
updating = true; |
488 |
updating = true; |
| 443 |
try { |
489 |
try { |
| 444 |
oldElement = property.set(source, index, o); |
490 |
changed = property.setList(source, list, diff); |
| 445 |
modCount++; |
491 |
modCount++; |
| 446 |
} finally { |
492 |
} finally { |
| 447 |
updating = wasUpdating; |
493 |
updating = wasUpdating; |
| 448 |
} |
494 |
} |
| 449 |
|
495 |
|
| 450 |
cachedList = property.getList(source); |
496 |
if (changed) { |
| 451 |
fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(index, |
497 |
cachedList = getList(); |
| 452 |
false, oldElement), Diffs.createListDiffEntry(index, true, o))); |
498 |
fireListChange(diff); |
|
|
499 |
} |
| 453 |
|
500 |
|
| 454 |
return oldElement; |
501 |
return oldElement; |
| 455 |
} |
502 |
} |
| 456 |
|
503 |
|
| 457 |
public List subList(int fromIndex, int toIndex) { |
504 |
public List subList(int fromIndex, int toIndex) { |
| 458 |
getterCalled(); |
505 |
getterCalled(); |
| 459 |
return Collections.unmodifiableList(property.getList(source).subList( |
506 |
return Collections.unmodifiableList(getList().subList(fromIndex, |
| 460 |
fromIndex, toIndex)); |
507 |
toIndex)); |
| 461 |
} |
508 |
} |
| 462 |
|
509 |
|
| 463 |
// Bulk change operations |
510 |
// Bulk change operations |
|
Lines 465-471
Link Here
|
| 465 |
public boolean addAll(Collection c) { |
512 |
public boolean addAll(Collection c) { |
| 466 |
checkRealm(); |
513 |
checkRealm(); |
| 467 |
|
514 |
|
| 468 |
return addAll(property.size(source), c); |
515 |
return addAll(getList().size(), c); |
| 469 |
} |
516 |
} |
| 470 |
|
517 |
|
| 471 |
public boolean addAll(int index, Collection c) { |
518 |
public boolean addAll(int index, Collection c) { |
|
Lines 474-479
Link Here
|
| 474 |
if (c.isEmpty()) |
521 |
if (c.isEmpty()) |
| 475 |
return false; |
522 |
return false; |
| 476 |
|
523 |
|
|
|
524 |
List list = new ArrayList(getList()); |
| 525 |
list.addAll(index, c); |
| 526 |
|
| 477 |
ListDiffEntry[] entries = new ListDiffEntry[c.size()]; |
527 |
ListDiffEntry[] entries = new ListDiffEntry[c.size()]; |
| 478 |
int offsetIndex = 0; |
528 |
int offsetIndex = 0; |
| 479 |
for (Iterator it = c.iterator(); it.hasNext();) { |
529 |
for (Iterator it = c.iterator(); it.hasNext();) { |
|
Lines 482-502
Link Here
|
| 482 |
+ offsetIndex, true, element); |
532 |
+ offsetIndex, true, element); |
| 483 |
offsetIndex++; |
533 |
offsetIndex++; |
| 484 |
} |
534 |
} |
|
|
535 |
ListDiff diff = Diffs.createListDiff(entries); |
| 485 |
|
536 |
|
| 486 |
boolean changed; |
537 |
boolean changed; |
| 487 |
|
538 |
|
| 488 |
boolean wasUpdating = updating; |
539 |
boolean wasUpdating = updating; |
| 489 |
updating = true; |
540 |
updating = true; |
| 490 |
try { |
541 |
try { |
| 491 |
changed = property.addAll(source, index, c); |
542 |
changed = property.setList(source, list, diff); |
| 492 |
modCount++; |
543 |
modCount++; |
| 493 |
} finally { |
544 |
} finally { |
| 494 |
updating = wasUpdating; |
545 |
updating = wasUpdating; |
| 495 |
} |
546 |
} |
| 496 |
|
547 |
|
| 497 |
cachedList = property.getList(source); |
548 |
if (changed) { |
| 498 |
if (changed) |
549 |
cachedList = getList(); |
| 499 |
fireListChange(Diffs.createListDiff(entries)); |
550 |
fireListChange(diff); |
|
|
551 |
} |
| 500 |
|
552 |
|
| 501 |
return changed; |
553 |
return changed; |
| 502 |
} |
554 |
} |
|
Lines 504-520
Link Here
|
| 504 |
public boolean removeAll(Collection c) { |
556 |
public boolean removeAll(Collection c) { |
| 505 |
checkRealm(); |
557 |
checkRealm(); |
| 506 |
|
558 |
|
| 507 |
if (property.isEmpty(source) || c.isEmpty()) |
559 |
if (c.isEmpty()) |
| 508 |
return false; |
560 |
return false; |
| 509 |
|
561 |
|
| 510 |
boolean changed; |
562 |
List list = getList(); |
|
|
563 |
if (list.isEmpty()) |
| 564 |
return false; |
| 511 |
|
565 |
|
|
|
566 |
list = new ArrayList(list); |
| 512 |
List entries = new ArrayList(); |
567 |
List entries = new ArrayList(); |
|
|
568 |
ListDiff diff; |
| 513 |
|
569 |
|
| 514 |
boolean wasUpdating = updating; |
570 |
boolean wasUpdating = updating; |
|
|
571 |
boolean changed; |
| 515 |
updating = true; |
572 |
updating = true; |
| 516 |
try { |
573 |
try { |
| 517 |
List list = new ArrayList(property.getList(source)); |
|
|
| 518 |
for (ListIterator it = list.listIterator(); it.hasNext();) { |
574 |
for (ListIterator it = list.listIterator(); it.hasNext();) { |
| 519 |
Object element = it.next(); |
575 |
Object element = it.next(); |
| 520 |
int index = it.previousIndex(); |
576 |
int index = it.previousIndex(); |
|
Lines 524-540
Link Here
|
| 524 |
.createListDiffEntry(index, false, element)); |
580 |
.createListDiffEntry(index, false, element)); |
| 525 |
} |
581 |
} |
| 526 |
} |
582 |
} |
| 527 |
changed = property.removeAll(source, c); |
583 |
if (entries.isEmpty()) |
|
|
584 |
return false; |
| 585 |
|
| 586 |
diff = Diffs.createListDiff((ListDiffEntry[]) entries |
| 587 |
.toArray(new ListDiffEntry[entries.size()])); |
| 588 |
changed = property.setList(source, list, diff); |
| 528 |
modCount++; |
589 |
modCount++; |
| 529 |
} finally { |
590 |
} finally { |
| 530 |
updating = wasUpdating; |
591 |
updating = wasUpdating; |
| 531 |
} |
592 |
} |
| 532 |
|
593 |
|
| 533 |
cachedList = property.getList(source); |
594 |
if (changed) { |
| 534 |
|
595 |
cachedList = getList(); |
| 535 |
if (changed) |
596 |
fireListChange(diff); |
| 536 |
fireListChange(Diffs.createListDiff((ListDiffEntry[]) entries |
597 |
} |
| 537 |
.toArray(new ListDiffEntry[entries.size()]))); |
|
|
| 538 |
|
598 |
|
| 539 |
return changed; |
599 |
return changed; |
| 540 |
} |
600 |
} |
|
Lines 542-548
Link Here
|
| 542 |
public boolean retainAll(Collection c) { |
602 |
public boolean retainAll(Collection c) { |
| 543 |
checkRealm(); |
603 |
checkRealm(); |
| 544 |
|
604 |
|
| 545 |
if (property.isEmpty(source)) |
605 |
List list = getList(); |
|
|
606 |
if (list.isEmpty()) |
| 546 |
return false; |
607 |
return false; |
| 547 |
|
608 |
|
| 548 |
if (c.isEmpty()) { |
609 |
if (c.isEmpty()) { |
|
Lines 550-563
Link Here
|
| 550 |
return true; |
611 |
return true; |
| 551 |
} |
612 |
} |
| 552 |
|
613 |
|
| 553 |
boolean changed; |
614 |
list = new ArrayList(list); |
| 554 |
|
|
|
| 555 |
List entries = new ArrayList(); |
615 |
List entries = new ArrayList(); |
|
|
616 |
ListDiff diff; |
| 556 |
|
617 |
|
| 557 |
boolean wasUpdating = updating; |
618 |
boolean wasUpdating = updating; |
|
|
619 |
boolean changed; |
| 558 |
updating = true; |
620 |
updating = true; |
| 559 |
try { |
621 |
try { |
| 560 |
List list = new ArrayList(property.getList(source)); |
|
|
| 561 |
for (ListIterator it = list.listIterator(); it.hasNext();) { |
622 |
for (ListIterator it = list.listIterator(); it.hasNext();) { |
| 562 |
Object element = it.next(); |
623 |
Object element = it.next(); |
| 563 |
int index = it.previousIndex(); |
624 |
int index = it.previousIndex(); |
|
Lines 567-583
Link Here
|
| 567 |
.createListDiffEntry(index, false, element)); |
628 |
.createListDiffEntry(index, false, element)); |
| 568 |
} |
629 |
} |
| 569 |
} |
630 |
} |
| 570 |
changed = property.retainAll(source, c); |
631 |
if (entries.isEmpty()) |
|
|
632 |
return false; |
| 633 |
|
| 634 |
diff = Diffs.createListDiff((ListDiffEntry[]) entries |
| 635 |
.toArray(new ListDiffEntry[entries.size()])); |
| 636 |
changed = property.setList(source, list, diff); |
| 571 |
modCount++; |
637 |
modCount++; |
| 572 |
} finally { |
638 |
} finally { |
| 573 |
updating = wasUpdating; |
639 |
updating = wasUpdating; |
| 574 |
} |
640 |
} |
| 575 |
|
641 |
|
| 576 |
cachedList = property.getList(source); |
642 |
if (changed) { |
| 577 |
|
643 |
cachedList = getList(); |
| 578 |
if (changed) |
644 |
fireListChange(diff); |
| 579 |
fireListChange(Diffs.createListDiff((ListDiffEntry[]) entries |
645 |
} |
| 580 |
.toArray(new ListDiffEntry[entries.size()]))); |
|
|
| 581 |
|
646 |
|
| 582 |
return changed; |
647 |
return changed; |
| 583 |
} |
648 |
} |
|
Lines 585-621
Link Here
|
| 585 |
public void clear() { |
650 |
public void clear() { |
| 586 |
checkRealm(); |
651 |
checkRealm(); |
| 587 |
|
652 |
|
| 588 |
if (property.isEmpty(source)) |
653 |
List list = getList(); |
|
|
654 |
if (list.isEmpty()) |
| 589 |
return; |
655 |
return; |
| 590 |
|
656 |
|
| 591 |
List entries = new ArrayList(); |
657 |
List entries = new ArrayList(); |
| 592 |
for (Iterator it = property.getList(source).iterator(); it.hasNext();) { |
658 |
for (Iterator it = list.iterator(); it.hasNext();) { |
| 593 |
// always report 0 as the remove index |
659 |
// always report 0 as the remove index |
| 594 |
entries.add(Diffs.createListDiffEntry(0, false, it.next())); |
660 |
entries.add(Diffs.createListDiffEntry(0, false, it.next())); |
| 595 |
} |
661 |
} |
| 596 |
|
662 |
|
|
|
663 |
ListDiff diff = Diffs.createListDiff((ListDiffEntry[]) entries |
| 664 |
.toArray(new ListDiffEntry[entries.size()])); |
| 597 |
boolean wasUpdating = updating; |
665 |
boolean wasUpdating = updating; |
|
|
666 |
boolean changed; |
| 598 |
updating = true; |
667 |
updating = true; |
| 599 |
try { |
668 |
try { |
| 600 |
property.clear(source); |
669 |
changed = property.setList(source, Collections.EMPTY_LIST, diff); |
| 601 |
modCount++; |
670 |
modCount++; |
| 602 |
} finally { |
671 |
} finally { |
| 603 |
updating = wasUpdating; |
672 |
updating = wasUpdating; |
| 604 |
} |
673 |
} |
| 605 |
|
674 |
|
| 606 |
cachedList = property.getList(source); |
675 |
if (changed) { |
| 607 |
fireListChange(Diffs.createListDiff((ListDiffEntry[]) entries |
676 |
cachedList = getList(); |
| 608 |
.toArray(new ListDiffEntry[entries.size()]))); |
677 |
fireListChange(diff); |
|
|
678 |
} |
| 609 |
} |
679 |
} |
| 610 |
|
680 |
|
| 611 |
public boolean equals(Object o) { |
681 |
public boolean equals(Object o) { |
| 612 |
getterCalled(); |
682 |
getterCalled(); |
| 613 |
return property.equals(source, o); |
683 |
return getList().equals(o); |
| 614 |
} |
684 |
} |
| 615 |
|
685 |
|
| 616 |
public int hashCode() { |
686 |
public int hashCode() { |
| 617 |
getterCalled(); |
687 |
getterCalled(); |
| 618 |
return property.hashCode(source); |
688 |
return getList().hashCode(); |
| 619 |
} |
689 |
} |
| 620 |
|
690 |
|
| 621 |
public Object getObserved() { |
691 |
public Object getObserved() { |