Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 183052 - [DataBinding] Implement better list diff algorithm
Summary: [DataBinding] Implement better list diff algorithm
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3 M7   Edit
Assignee: Boris Bokowski CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 154132
  Show dependency tree
 
Reported: 2007-04-18 16:20 EDT by Boris Bokowski CLA
Modified: 2007-05-04 10:18 EDT (History)
1 user (show)

See Also:


Attachments
patch (3.56 KB, patch)
2007-04-18 16:28 EDT, Boris Bokowski CLA
bokowski: review?
Details | Diff
tests patch (13.15 KB, patch)
2007-04-21 14:18 EDT, Brad Reynolds CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Boris Bokowski CLA 2007-04-18 16:20:22 EDT
 
Comment 1 Boris Bokowski CLA 2007-04-18 16:28:33 EDT
Created attachment 64229 [details]
patch

This was adapted from EMF's ListDifferenceAnalyzer.  Needs tests though.
Comment 2 Boris Bokowski CLA 2007-04-18 16:30:36 EDT
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();
	}
}
Comment 3 Boris Bokowski CLA 2007-04-18 16:32:27 EDT
would be nice to have for 3.3
Comment 4 Brad Reynolds CLA 2007-04-18 20:17:32 EDT
I'll try to write some tests in the next couple of days.
Comment 5 Brad Reynolds CLA 2007-04-21 14:18:04 EDT
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.
Comment 6 Boris Bokowski CLA 2007-04-28 13:56:32 EDT
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.)
Comment 7 Boris Bokowski CLA 2007-05-04 10:18:35 EDT
Verified on Windows XP using I20070503-0842.