Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 93650 Details for
Bug 208434
[DataBinding] ObservableList iterator implementation does not delegate back to outer class
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Make iterators modifiable in WritableSet and WritableList -- needs unit tests
clipboard.txt (text/plain), 7.29 KB, created by
Matthew Hall
on 2008-03-26 13:56:05 EDT
(
hide
)
Description:
Make iterators modifiable in WritableSet and WritableList -- needs unit tests
Filename:
MIME Type:
Creator:
Matthew Hall
Created:
2008-03-26 13:56:05 EDT
Size:
7.29 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.core.databinding >Index: src/org/eclipse/core/databinding/observable/set/WritableSet.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/WritableSet.java,v >retrieving revision 1.8 >diff -u -r1.8 WritableSet.java >--- src/org/eclipse/core/databinding/observable/set/WritableSet.java 4 Mar 2008 23:53:55 -0000 1.8 >+++ src/org/eclipse/core/databinding/observable/set/WritableSet.java 26 Mar 2008 17:53:51 -0000 >@@ -8,13 +8,14 @@ > * Contributors: > * IBM Corporation - initial API and implementation > * Brad Reynolds - bug 147515 >- * Matthew Hall - bug 221351 >+ * Matthew Hall - bug 221351, 208434 > *******************************************************************************/ > > package org.eclipse.core.databinding.observable.set; > > import java.util.Collection; > import java.util.Collections; >+import java.util.ConcurrentModificationException; > import java.util.HashSet; > import java.util.Iterator; > import java.util.Set; >@@ -161,6 +162,40 @@ > fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, removes)); > } > >+ public Iterator iterator() { >+ getterCalled(); >+ final Set set = wrappedSet; >+ final Iterator wrappedIterator = set.iterator(); >+ return new Iterator() { >+ Object last; >+ >+ public void remove() { >+ getterCalled(); >+ checkForComodification(); >+ wrappedIterator.remove(); >+ fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, >+ Collections.singleton(last))); >+ } >+ >+ public boolean hasNext() { >+ getterCalled(); >+ checkForComodification(); >+ return wrappedIterator.hasNext(); >+ } >+ >+ public Object next() { >+ getterCalled(); >+ checkForComodification(); >+ return last = wrappedIterator.next(); >+ } >+ >+ private void checkForComodification() { >+ if (set != wrappedSet) >+ throw new ConcurrentModificationException(); >+ } >+ }; >+ } >+ > /** > * @param elementType can be <code>null</code> > * @return new instance with the default realm >Index: src/org/eclipse/core/databinding/observable/list/WritableList.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/WritableList.java,v >retrieving revision 1.15 >diff -u -r1.15 WritableList.java >--- src/org/eclipse/core/databinding/observable/list/WritableList.java 24 Mar 2008 19:13:39 -0000 1.15 >+++ src/org/eclipse/core/databinding/observable/list/WritableList.java 26 Mar 2008 17:53:51 -0000 >@@ -11,20 +11,22 @@ > * Brad Reynolds - bug 167204 > * Gautam Saggar - bug 169529 > * Brad Reynolds - bug 147515 >- * Matthew Hall - bug 208858, 213145 >+ * Matthew Hall - bug 208858, 213145, 208434 > *******************************************************************************/ > package org.eclipse.core.databinding.observable.list; > > import java.util.ArrayList; > import java.util.Collection; >+import java.util.ConcurrentModificationException; > import java.util.Iterator; > import java.util.List; >+import java.util.ListIterator; > > import org.eclipse.core.databinding.observable.Diffs; > import org.eclipse.core.databinding.observable.Realm; > > /** >- * Mutable observable list backed by an ArrayList. >+ * Mutable observable list backed by a java.util.List. > * > * <p> > * This class is thread safe. All state accessing methods must be invoked from >@@ -71,7 +73,7 @@ > * > * @param realm > * @param toWrap >- * The java.utilList to wrap >+ * The java.util.List to wrap > * @param elementType > * can be <code>null</code> > */ >@@ -213,6 +215,8 @@ > > public void clear() { > checkRealm(); >+ if (wrappedList.isEmpty()) >+ return; > List entries = new ArrayList(); > for (Iterator it = wrappedList.iterator(); it.hasNext();) { > Object element = it.next(); >@@ -224,6 +228,132 @@ > .toArray(new ListDiffEntry[entries.size()]))); > } > >+ public Iterator iterator() { >+ getterCalled(); >+ final List list = wrappedList; >+ final ListIterator wrappedIterator = list.listIterator(); >+ return new Iterator() { >+ Object last = null; >+ >+ public boolean hasNext() { >+ getterCalled(); >+ checkForComodification(); >+ return wrappedIterator.hasNext(); >+ } >+ >+ public Object next() { >+ getterCalled(); >+ checkForComodification(); >+ return last = wrappedIterator.next(); >+ } >+ >+ public void remove() { >+ checkRealm(); >+ checkForComodification(); >+ int index = wrappedIterator.previousIndex(); >+ wrappedIterator.remove(); >+ ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( >+ index, false, last)); >+ fireListChange(diff); >+ } >+ >+ private void checkForComodification() { >+ if (list != wrappedList) >+ throw new ConcurrentModificationException(); >+ } >+ }; >+ } >+ >+ public ListIterator listIterator() { >+ return listIterator(0); >+ } >+ >+ public ListIterator listIterator(int index) { >+ getterCalled(); >+ final List list = wrappedList; >+ final ListIterator wrappedIterator = list.listIterator(index); >+ return new ListIterator() { >+ int lastIndex = -1; >+ Object last = null; >+ >+ public void add(Object o) { >+ checkRealm(); >+ checkForComodification(); >+ wrappedIterator.add(o); >+ lastIndex = previousIndex(); >+ ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( >+ lastIndex, true, o)); >+ fireListChange(diff); >+ } >+ >+ public boolean hasNext() { >+ getterCalled(); >+ checkForComodification(); >+ return wrappedIterator.hasNext(); >+ } >+ >+ public boolean hasPrevious() { >+ getterCalled(); >+ checkForComodification(); >+ return wrappedIterator.hasPrevious(); >+ } >+ >+ public Object next() { >+ getterCalled(); >+ checkForComodification(); >+ last = wrappedIterator.next(); >+ lastIndex = previousIndex(); >+ return last; >+ } >+ >+ public int nextIndex() { >+ getterCalled(); >+ checkForComodification(); >+ return wrappedIterator.nextIndex(); >+ } >+ >+ public Object previous() { >+ getterCalled(); >+ checkForComodification(); >+ last = wrappedIterator.previous(); >+ lastIndex = nextIndex(); >+ return last; >+ } >+ >+ public int previousIndex() { >+ getterCalled(); >+ checkForComodification(); >+ return wrappedIterator.previousIndex(); >+ } >+ >+ public void remove() { >+ checkRealm(); >+ checkForComodification(); >+ wrappedIterator.remove(); >+ ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( >+ lastIndex, false, last)); >+ lastIndex = -1; >+ fireListChange(diff); >+ } >+ >+ public void set(Object o) { >+ checkRealm(); >+ checkForComodification(); >+ wrappedIterator.set(o); >+ ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( >+ lastIndex, false, last), Diffs.createListDiffEntry( >+ lastIndex, true, o)); >+ last = o; >+ fireListChange(diff); >+ } >+ >+ private void checkForComodification() { >+ if (list != wrappedList) >+ throw new ConcurrentModificationException(); >+ } >+ }; >+ } >+ > /** > * @param elementType > * can be <code>null</code>
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 208434
:
88735
|
88736
| 93650 |
93651