comparison org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/Diffs.d @ 85:6be48cf9f95c

Work on databinding
author Frank Benoit <benoit@tionex.de>
date Sat, 18 Apr 2009 13:54:50 +0200
parents 0a55d2d5a946
children
comparison
equal deleted inserted replaced
84:fcf926c91ca4 85:6be48cf9f95c
20 import java.util.HashSet; 20 import java.util.HashSet;
21 import java.util.Iterator; 21 import java.util.Iterator;
22 import java.util.List; 22 import java.util.List;
23 import java.util.Map; 23 import java.util.Map;
24 import java.util.Set; 24 import java.util.Set;
25 import java.util.Map.Entry;
26 25
27 import org.eclipse.core.databinding.observable.list.ListDiff; 26 import org.eclipse.core.databinding.observable.list.ListDiff;
28 import org.eclipse.core.databinding.observable.list.ListDiffEntry; 27 import org.eclipse.core.databinding.observable.list.ListDiffEntry;
29 import org.eclipse.core.databinding.observable.map.MapDiff; 28 import org.eclipse.core.databinding.observable.map.MapDiff;
30 import org.eclipse.core.databinding.observable.set.SetDiff; 29 import org.eclipse.core.databinding.observable.set.SetDiff;
64 } else { 63 } else {
65 bool done; 64 bool done;
66 do { 65 do {
67 done = true; 66 done = true;
68 Object oldValue = oldList.get(index); 67 Object oldValue = oldList.get(index);
69 if (oldValue is null ? newValue !is null : !oldValue.equals(newValue)) { 68 if (oldValue is null ? newValue !is null : !oldValue.opEquals(newValue)) {
70 int oldIndexOfNewValue = listIndexOf(oldList, newValue, index); 69 int oldIndexOfNewValue = listIndexOf(oldList, newValue, index);
71 if (oldIndexOfNewValue !is -1) { 70 if (oldIndexOfNewValue !is -1) {
72 int newIndexOfOldValue = listIndexOf(newList, oldValue, index); 71 int newIndexOfOldValue = listIndexOf(newList, oldValue, index);
73 if (newIndexOfOldValue is -1) { 72 if (newIndexOfOldValue is -1) {
74 // removing oldValue from list[index] 73 // removing oldValue from list[index]
120 */ 119 */
121 private static int listIndexOf(List list, Object object, int index) { 120 private static int listIndexOf(List list, Object object, int index) {
122 int size = list.size(); 121 int size = list.size();
123 for (int i=index; i<size;i++) { 122 for (int i=index; i<size;i++) {
124 Object candidate = list.get(i); 123 Object candidate = list.get(i);
125 if (candidateisnull ? objectisnull : candidate.equals(object)) { 124 if (candidate is null ? object is null : candidate.opEquals(object)) {
126 return i; 125 return i;
127 } 126 }
128 } 127 }
129 return -1; 128 return -1;
130 } 129 }
140 * @return <code>true</code> if the two objects are equivalent; 139 * @return <code>true</code> if the two objects are equivalent;
141 * <code>false</code> otherwise. 140 * <code>false</code> otherwise.
142 */ 141 */
143 public static final bool equals(Object left, Object right) { 142 public static final bool equals(Object left, Object right) {
144 return left is null ? right is null : ((right !is null) && left 143 return left is null ? right is null : ((right !is null) && left
145 .equals(right)); 144 .opEquals(right));
146 } 145 }
147 146
148 /** 147 /**
149 * @param oldSet 148 * @param oldSet
150 * @param newSet 149 * @param newSet
173 final Set removedKeys = new HashSet(); 172 final Set removedKeys = new HashSet();
174 final Set changedKeys = new HashSet(); 173 final Set changedKeys = new HashSet();
175 final Map oldValues = new HashMap(); 174 final Map oldValues = new HashMap();
176 final Map newValues = new HashMap(); 175 final Map newValues = new HashMap();
177 for (Iterator it = oldMap.entrySet().iterator(); it.hasNext();) { 176 for (Iterator it = oldMap.entrySet().iterator(); it.hasNext();) {
178 Map.Entry oldEntry = cast(Entry) it.next(); 177 Map.Entry oldEntry = cast(Map.Entry) it.next();
179 Object oldKey = oldEntry.getKey(); 178 Object oldKey = oldEntry.getKey();
180 if (addedKeys.remove(oldKey)) { 179 if (addedKeys.remove(oldKey)) {
181 // potentially changed key since it is in oldMap and newMap 180 // potentially changed key since it is in oldMap and newMap
182 Object oldValue = oldEntry.getValue(); 181 Object oldValue = oldEntry.getValue();
183 Object newValue = newMap.get(oldKey); 182 Object newValue = newMap.get(oldKey);
221 /** 220 /**
222 * @param oldValue 221 * @param oldValue
223 * @param newValue 222 * @param newValue
224 * @return a value diff 223 * @return a value diff
225 */ 224 */
225 public static ValueDiff createValueDiff(String oldValue,
226 Object newValue) {
227 return createValueDiff( stringcast(oldValue), newValue );
228 }
229 public static ValueDiff createValueDiff(Object oldValue,
230 String newValue) {
231 return createValueDiff( oldValue, stringcast(newValue) );
232 }
233 public static ValueDiff createValueDiff(String oldValue,
234 String newValue) {
235 return createValueDiff( stringcast(oldValue), stringcast(newValue) );
236 }
226 public static ValueDiff createValueDiff(Object oldValue, 237 public static ValueDiff createValueDiff(Object oldValue,
227 Object newValue) { 238 Object newValue) {
228 return new class(oldValue, newValue) ValueDiff { 239 return new class(oldValue, newValue) ValueDiff {
229 Object oldValue_, newValue_; 240 Object oldValue_, newValue_;
230 this(Object a, Object b){ 241 this(Object a, Object b){