Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vietj/treesync
experiments about tree data synchronization
https://github.com/vietj/treesync
Last synced: 5 days ago
JSON representation
experiments about tree data synchronization
- Host: GitHub
- URL: https://github.com/vietj/treesync
- Owner: vietj
- Created: 2011-04-06T13:06:32.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2013-01-14T11:01:16.000Z (almost 12 years ago)
- Last Synced: 2024-10-20T05:02:19.731Z (3 months ago)
- Language: Java
- Homepage:
- Size: 194 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README
Awesome Lists containing this project
README
A framework that performs a diff on objects, two implementations are done:
- list : compare two lists of objects
- hierarchy : compare two hierarchies of objectsComparison is based on the Longest Common Subsequence (LCS) algorithm as explained here
http://en.wikipedia.org/wiki/Longest_common_subsequence_problemExemple usage for a list:
// The source list
String[] source = new String[]{"banana","strawberry","cherry"};// The destination list
List destination = Arrays.asList("apple", "banana", "raspberry","cherry");// Let's create the differ
ListDiff, String> diff = new ListDiff, String>(new ArrayAdapter(), new JavaUtilListAdapter());// Get a change iterator
ListChangeIterator, String> it = diff.iterator(source, destination);// +apple
Assert.assertEquals(ListChangeType.ADD, it.next());
assertEquals("apple", it.getElement());// banana
assertEquals(ListChangeType.SAME, it.next());
assertEquals("banana", it.getElement());// +raspberry
assertEquals(ListChangeType.ADD, it.next());
assertEquals("raspberry", it.getElement());// -strawberry
assertEquals(ListChangeType.REMOVE, it.next());
assertEquals("strawberry", it.getElement());// cherry
assertEquals(ListChangeType.SAME, it.next());
assertEquals("cherry", it.getElement());// Done
assertFalse(it.hasNext());Feel free to reuse it if you find it useful