Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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 objects

Comparison is based on the Longest Common Subsequence (LCS) algorithm as explained here
http://en.wikipedia.org/wiki/Longest_common_subsequence_problem

Exemple 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