use of de.danielbechler.diff.ObjectDiffer in project modesti by jlsalmon.
the class RequestDiffer method diff.
public static ChangeEvent diff(Request modified, Request original, String idProperty) {
List<Point> originalPointsStillPresentCurrently = deleteRemovedPoints(original.getPoints(), modified.getPoints(), idProperty);
original.setPoints(originalPointsStillPresentCurrently);
ChangeEvent event = new ChangeEvent(new DateTime(DateTimeZone.UTC));
Request modifiedClone = new RequestImpl();
Request originalClone = new RequestImpl();
ChangeVisitor visitor = new ChangeVisitor(event, modifiedClone, originalClone);
Map<Object, Point> modifiedPointMap = getPointsMap(modified.getPoints(), idProperty);
for (Point originalPoint : original.getPoints()) {
Point modifiedPoint = modifiedPointMap.get(originalPoint.getValueByPropertyName(idProperty));
originalClone.setPoints(Arrays.asList((Point[]) new Point[] { originalPoint }));
if (modifiedPoint != null) {
modifiedClone.setPoints(Arrays.asList((Point[]) new Point[] { modifiedPoint }));
}
ObjectDiffer differ = ObjectDifferBuilder.startBuilding().identity().ofCollectionItems(NodePath.with("points")).via(new PointIdentityStrategy(idProperty)).and().build();
DiffNode root = differ.compare(modifiedClone, originalClone);
if (root.hasChanges()) {
root.visit(visitor);
}
}
return event;
}
Aggregations