-
Notifications
You must be signed in to change notification settings - Fork 177
Description
This is lovely tool and you have set up a nice hierarchical structure for diffing.
Below is my first example and its output, which raises several issues:
- Not sure about the log4 messages, I assume googling will address it.
- It would be nice to distinguish Lists from collections, and have property paths name indices rather than elements. This seems like an easy addition, all you have to do is call indexOf given the element and the list. Instead of Collection path element now you would have a List path element.
- Most important, the nested list output goes against intuition. If a first level diff is being on the list, then we should be told that the first element (a list) of the nested base list has been replaced by the first element of the nested working list. If a second level diff is being done, then the output should be the same as the output of the flat list (except for the paths). Instead we have a second level diff in which all elements of the base list are considered deleted and the elements of the working list are considered added.
- I thought of trying to extend your tool but lots of classes (PropertyPath, Collection element) are final and there is no way to add your own diff factories without changing your code, which I did not want to do, as I want to keep getting your updates.
Still this a wonderful tool and the problems above can be addressed with a post processing of the output.
Program:
public static void main (String[] args) {
String[] stringsWorking = {"b1", "w1", "w2", "b4"};
String[] stringsBase = {"b1", "b2", "b3", "b4"};
List listWorking = Arrays.asList(stringsWorking);
List listBase = Arrays.asList(stringsBase);
List nestedListWorking = new ArrayList();
List nestedListBase = new ArrayList();
nestedListWorking.add(listWorking);
nestedListBase.add(listBase);
ObjectDiffer objectDiffer = ObjectDifferFactory.getInstance();
Node listRoot = objectDiffer.compare(listWorking, listBase);
listRoot.visit(new PrintingVisitor(listWorking, listBase));
Node nestedListRoot = objectDiffer.compare(nestedListWorking, nestedListBase);
nestedListRoot.visit(new PrintingVisitor(nestedListWorking, nestedListBase));
}
Output:
log4j:WARN No appenders could be found for logger (de.danielbechler.util.Classes).
log4j:WARN Please initialize the log4j system properly.
Property at path '/[w1]' has been added => [ w1 ]
Property at path '/[w2]' has been added => [ w2 ]
Property at path '/[b2]' with value [ b2 ] has been removed
Property at path '/[b3]' with value [ b3 ] has been removed
Property at path '/[[b1, w1, w2, b4]][b1]' has been added => [ b1 ]
Property at path '/[[b1, w1, w2, b4]][w1]' has been added => [ w1 ]
Property at path '/[[b1, w1, w2, b4]][w2]' has been added => [ w2 ]
Property at path '/[[b1, w1, w2, b4]][b4]' has been added => [ b4 ]
Property at path '/[[b1, b2, b3, b4]][b1]' with value [ b1 ] has been removed
Property at path '/[[b1, b2, b3, b4]][b2]' with value [ b2 ] has been removed
Property at path '/[[b1, b2, b3, b4]][b3]' with value [ b3 ] has been removed
Property at path '/[[b1, b2, b3, b4]][b4]' with value [ b4 ] has been removed