|
Lines 11-30
Link Here
|
| 11 |
* Brad Reynolds - bug 167204 |
11 |
* Brad Reynolds - bug 167204 |
| 12 |
* Gautam Saggar - bug 169529 |
12 |
* Gautam Saggar - bug 169529 |
| 13 |
* Brad Reynolds - bug 147515 |
13 |
* Brad Reynolds - bug 147515 |
| 14 |
* Matthew Hall - bug 208858, 213145 |
14 |
* Matthew Hall - bug 208858, 213145, 208434 |
| 15 |
*******************************************************************************/ |
15 |
*******************************************************************************/ |
| 16 |
package org.eclipse.core.databinding.observable.list; |
16 |
package org.eclipse.core.databinding.observable.list; |
| 17 |
|
17 |
|
| 18 |
import java.util.ArrayList; |
18 |
import java.util.ArrayList; |
| 19 |
import java.util.Collection; |
19 |
import java.util.Collection; |
|
|
20 |
import java.util.ConcurrentModificationException; |
| 20 |
import java.util.Iterator; |
21 |
import java.util.Iterator; |
| 21 |
import java.util.List; |
22 |
import java.util.List; |
|
|
23 |
import java.util.ListIterator; |
| 22 |
|
24 |
|
| 23 |
import org.eclipse.core.databinding.observable.Diffs; |
25 |
import org.eclipse.core.databinding.observable.Diffs; |
| 24 |
import org.eclipse.core.databinding.observable.Realm; |
26 |
import org.eclipse.core.databinding.observable.Realm; |
| 25 |
|
27 |
|
| 26 |
/** |
28 |
/** |
| 27 |
* Mutable observable list backed by an ArrayList. |
29 |
* Mutable observable list backed by a java.util.List. |
| 28 |
* |
30 |
* |
| 29 |
* <p> |
31 |
* <p> |
| 30 |
* This class is thread safe. All state accessing methods must be invoked from |
32 |
* This class is thread safe. All state accessing methods must be invoked from |
|
Lines 71-77
Link Here
|
| 71 |
* |
73 |
* |
| 72 |
* @param realm |
74 |
* @param realm |
| 73 |
* @param toWrap |
75 |
* @param toWrap |
| 74 |
* The java.utilList to wrap |
76 |
* The java.util.List to wrap |
| 75 |
* @param elementType |
77 |
* @param elementType |
| 76 |
* can be <code>null</code> |
78 |
* can be <code>null</code> |
| 77 |
*/ |
79 |
*/ |
|
Lines 213-218
Link Here
|
| 213 |
|
215 |
|
| 214 |
public void clear() { |
216 |
public void clear() { |
| 215 |
checkRealm(); |
217 |
checkRealm(); |
|
|
218 |
if (wrappedList.isEmpty()) |
| 219 |
return; |
| 216 |
List entries = new ArrayList(); |
220 |
List entries = new ArrayList(); |
| 217 |
for (Iterator it = wrappedList.iterator(); it.hasNext();) { |
221 |
for (Iterator it = wrappedList.iterator(); it.hasNext();) { |
| 218 |
Object element = it.next(); |
222 |
Object element = it.next(); |
|
Lines 224-229
Link Here
|
| 224 |
.toArray(new ListDiffEntry[entries.size()]))); |
228 |
.toArray(new ListDiffEntry[entries.size()]))); |
| 225 |
} |
229 |
} |
| 226 |
|
230 |
|
|
|
231 |
public Iterator iterator() { |
| 232 |
getterCalled(); |
| 233 |
final List list = wrappedList; |
| 234 |
final ListIterator wrappedIterator = list.listIterator(); |
| 235 |
return new Iterator() { |
| 236 |
Object last = null; |
| 237 |
|
| 238 |
public boolean hasNext() { |
| 239 |
getterCalled(); |
| 240 |
checkForComodification(); |
| 241 |
return wrappedIterator.hasNext(); |
| 242 |
} |
| 243 |
|
| 244 |
public Object next() { |
| 245 |
getterCalled(); |
| 246 |
checkForComodification(); |
| 247 |
return last = wrappedIterator.next(); |
| 248 |
} |
| 249 |
|
| 250 |
public void remove() { |
| 251 |
checkRealm(); |
| 252 |
checkForComodification(); |
| 253 |
int index = wrappedIterator.previousIndex(); |
| 254 |
wrappedIterator.remove(); |
| 255 |
ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( |
| 256 |
index, false, last)); |
| 257 |
fireListChange(diff); |
| 258 |
} |
| 259 |
|
| 260 |
private void checkForComodification() { |
| 261 |
if (list != wrappedList) |
| 262 |
throw new ConcurrentModificationException(); |
| 263 |
} |
| 264 |
}; |
| 265 |
} |
| 266 |
|
| 267 |
public ListIterator listIterator() { |
| 268 |
return listIterator(0); |
| 269 |
} |
| 270 |
|
| 271 |
public ListIterator listIterator(int index) { |
| 272 |
getterCalled(); |
| 273 |
final List list = wrappedList; |
| 274 |
final ListIterator wrappedIterator = list.listIterator(index); |
| 275 |
return new ListIterator() { |
| 276 |
int lastIndex = -1; |
| 277 |
Object last = null; |
| 278 |
|
| 279 |
public void add(Object o) { |
| 280 |
checkRealm(); |
| 281 |
checkForComodification(); |
| 282 |
wrappedIterator.add(o); |
| 283 |
lastIndex = previousIndex(); |
| 284 |
ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( |
| 285 |
lastIndex, true, o)); |
| 286 |
fireListChange(diff); |
| 287 |
} |
| 288 |
|
| 289 |
public boolean hasNext() { |
| 290 |
getterCalled(); |
| 291 |
checkForComodification(); |
| 292 |
return wrappedIterator.hasNext(); |
| 293 |
} |
| 294 |
|
| 295 |
public boolean hasPrevious() { |
| 296 |
getterCalled(); |
| 297 |
checkForComodification(); |
| 298 |
return wrappedIterator.hasPrevious(); |
| 299 |
} |
| 300 |
|
| 301 |
public Object next() { |
| 302 |
getterCalled(); |
| 303 |
checkForComodification(); |
| 304 |
last = wrappedIterator.next(); |
| 305 |
lastIndex = previousIndex(); |
| 306 |
return last; |
| 307 |
} |
| 308 |
|
| 309 |
public int nextIndex() { |
| 310 |
getterCalled(); |
| 311 |
checkForComodification(); |
| 312 |
return wrappedIterator.nextIndex(); |
| 313 |
} |
| 314 |
|
| 315 |
public Object previous() { |
| 316 |
getterCalled(); |
| 317 |
checkForComodification(); |
| 318 |
last = wrappedIterator.previous(); |
| 319 |
lastIndex = nextIndex(); |
| 320 |
return last; |
| 321 |
} |
| 322 |
|
| 323 |
public int previousIndex() { |
| 324 |
getterCalled(); |
| 325 |
checkForComodification(); |
| 326 |
return wrappedIterator.previousIndex(); |
| 327 |
} |
| 328 |
|
| 329 |
public void remove() { |
| 330 |
checkRealm(); |
| 331 |
checkForComodification(); |
| 332 |
wrappedIterator.remove(); |
| 333 |
ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( |
| 334 |
lastIndex, false, last)); |
| 335 |
lastIndex = -1; |
| 336 |
fireListChange(diff); |
| 337 |
} |
| 338 |
|
| 339 |
public void set(Object o) { |
| 340 |
checkRealm(); |
| 341 |
checkForComodification(); |
| 342 |
wrappedIterator.set(o); |
| 343 |
ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( |
| 344 |
lastIndex, false, last), Diffs.createListDiffEntry( |
| 345 |
lastIndex, true, o)); |
| 346 |
last = o; |
| 347 |
fireListChange(diff); |
| 348 |
} |
| 349 |
|
| 350 |
private void checkForComodification() { |
| 351 |
if (list != wrappedList) |
| 352 |
throw new ConcurrentModificationException(); |
| 353 |
} |
| 354 |
}; |
| 355 |
} |
| 356 |
|
| 227 |
/** |
357 |
/** |
| 228 |
* @param elementType |
358 |
* @param elementType |
| 229 |
* can be <code>null</code> |
359 |
* can be <code>null</code> |