Community
Participate
Working Groups
Created attachment 64229 [details] patch This was adapted from EMF's ListDifferenceAnalyzer. Needs tests though.
Brad, do you have time to write a test for this? Here is what I've used to see if it is working: package foo; import java.util.Arrays; import java.util.List; import org.eclipse.core.databinding.observable.Diffs; import org.eclipse.core.databinding.observable.list.ListDiff; public class ListDiffTest { public static void main(String[] args) { test(new String[]{}, new String[]{}); test(new String[]{"a"}, new String[]{}); test(new String[]{}, new String[]{"a"}); test(new String[]{"a"}, new String[]{"a"}); test(new String[]{"a"}, new String[]{"b"}); test(new String[]{"a"}, new String[]{"a","b"}); test(new String[]{"a"}, new String[]{"b","a"}); test(new String[]{"a"}, new String[]{"b","b"}); test(new String[]{"a"}, new String[]{"a","b","c"}); test(new String[]{"b"}, new String[]{"a","b","c"}); test(new String[]{"c"}, new String[]{"a","b","c"}); test(new String[]{"a","b","c"}, new String[]{"a","b","c"}); test(new String[]{"a","b","c"}, new String[]{"b","c"}); test(new String[]{"a","b","c"}, new String[]{"a","c"}); test(new String[]{"a","b","c"}, new String[]{"a","b"}); test(new String[]{"a","b","c"}, new String[]{"c","b","a"}); test(new String[]{"a","b","c"}, new String[]{"c","b"}); } static void test(Object[] a1, Object[] a2) { List l1 = Arrays.asList(a1); List l2 = Arrays.asList(a2); ListDiff diff = Diffs.computeListDiff(l1, l2); System.out.println("================="); System.out.println(toString(a1)); System.out.println(toString(a2)); System.out.println(diff); } private static Object toString(Object[] a) { StringBuffer result = new StringBuffer(); result.append("["); for (int i = 0; i < a.length; i++) { if (i>0) { result.append(", "); } result.append(a[i].toString()); } result.append("]"); return result.toString(); } }
would be nice to have for 3.3
I'll try to write some tests in the next couple of days.
Created attachment 64512 [details] tests patch This is probably a little different than what you wanted but for me it was the most comfortable way to do this. I took the snippet you provided and turned them into screnarios. These tests pass against the OLD algorithm. Most tests fail against the new algorithm. But they're written in such a way that you should be able to update them very easily. I just wanted to make sure that the changes were what you expected and the easiest way to do that was to have you make that change.
I changed the tests to match the smaller diffs computed by the new algorithm. Released >20070428. (I also added a test decorator for the suite that sets the default locale to US. I was getting test failures because on my laptop, the default locale is German.)
Verified on Windows XP using I20070503-0842.