Search in sources :

Example 1 with ObjectDiffer

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;
}
Also used : Request(cern.modesti.request.Request) DiffNode(de.danielbechler.diff.node.DiffNode) Point(cern.modesti.point.Point) DateTime(org.joda.time.DateTime) RequestImpl(cern.modesti.request.RequestImpl) ObjectDiffer(de.danielbechler.diff.ObjectDiffer)

Aggregations

Point (cern.modesti.point.Point)1 Request (cern.modesti.request.Request)1 RequestImpl (cern.modesti.request.RequestImpl)1 ObjectDiffer (de.danielbechler.diff.ObjectDiffer)1 DiffNode (de.danielbechler.diff.node.DiffNode)1 DateTime (org.joda.time.DateTime)1