@Override public boolean canBeAppliedOn(@Nullable Object value) { switch (this.type) { case ADDED: return value == null; case REMOVED: checkNotNull(oldGeometry); checkNotNull(value); Geometry geom = (Geometry) value; return geom.equalsExact(oldGeometry); case MODIFIED: default: return diff.canBeAppliedOn((Geometry) value); } }
@Override public boolean canBeAppliedOn(@Nullable Object value) { switch (this.type) { case ADDED: return value == null; case REMOVED: checkNotNull(oldGeometry); checkNotNull(value); Geometry geom = (Geometry) value; return geom.equalsExact(oldGeometry); case MODIFIED: default: return diff.canBeAppliedOn((Geometry) value); } }
@Nullable public Geometry applyOn(@Nullable Geometry obj) { Preconditions.checkState(canBeAppliedOn(obj)); String wkt = obj == null ? "" : obj.toText(); String res = (String) diffMatchPatch.patch_apply(patches, wkt)[0]; if (!res.isEmpty()) { return (Geometry) TextValueSerializer.fromString(FieldType.forBinding(Geometry.class), res); } return null; }
@Nullable public Geometry applyOn(@Nullable Geometry obj) { Preconditions.checkState(canBeAppliedOn(obj)); String wkt = obj == null ? "" : obj.toText(); String res = (String) diffMatchPatch.patch_apply(patches, wkt)[0]; if (!res.isEmpty()) { return (Geometry) TextValueSerializer.fromString(FieldType.forBinding(Geometry.class), res); } return null; }
@Test public void testCanApply() throws Exception { Geometry oldGeom = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))"); Geometry newGeom = new WKTReader().read( "MULTILINESTRING ((40 40, 20 35, 45 30, 40 40),(20 35, 45 20, 30 15, 10 10, 10 30, 20 35),(10 10, 20 20, 35 30))"); LCSGeometryDiffImpl diff = new LCSGeometryDiffImpl(oldGeom, newGeom); Geometry oldGeomModified = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 41),(20 35, 45 10, 30 5, 10 30, 20 35))"); assertTrue(diff.canBeAppliedOn(oldGeomModified)); Geometry oldGeomModified2 = new WKTReader().read("MULTILINESTRING ((40 40, 10 10))"); assertFalse(diff.canBeAppliedOn(oldGeomModified2)); }
@Test public void testCanApply() throws Exception { Geometry oldGeom = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))"); Geometry newGeom = new WKTReader().read( "MULTILINESTRING ((40 40, 20 35, 45 30, 40 40),(20 35, 45 20, 30 15, 10 10, 10 30, 20 35),(10 10, 20 20, 35 30))"); LCSGeometryDiffImpl diff = new LCSGeometryDiffImpl(oldGeom, newGeom); Geometry oldGeomModified = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 41),(20 35, 45 10, 30 5, 10 30, 20 35))"); assertTrue(diff.canBeAppliedOn(oldGeomModified)); Geometry oldGeomModified2 = new WKTReader().read("MULTILINESTRING ((40 40, 10 10))"); assertFalse(diff.canBeAppliedOn(oldGeomModified2)); }