@Override public AttributeDiff reversed() { if (type == TYPE.MODIFIED) { return new GeometryAttributeDiff(this.diff.reversed()); } else { return new GeometryAttributeDiff(oldGeometry, newGeometry); } }
@Override public Geometry applyOn(@Nullable Object value) { Preconditions.checkState(canBeAppliedOn(value)); switch (type) { case ADDED: return newGeometry; case REMOVED: return null; case MODIFIED: default: return diff.applyOn((Geometry) value); } }
@Test public void testConflictPatcheable() 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 45, 45 35, 30 30),(20 35, 45 10, 30 5, 10 30, 20 35))"); GeometryAttributeDiff diff = new GeometryAttributeDiff(oldGeom, newGeom); Geometry newGeom2 = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 31 6, 10 30, 20 35))"); GeometryAttributeDiff diff2 = new GeometryAttributeDiff(oldGeom, newGeom2); // it's a conflict for the sake of merging branches assertTrue(diff.conflicts(diff2)); // yet can be merged for the sake of applying a patch assertTrue(diff2.canBeAppliedOn(newGeom)); Geometry merged = diff2.applyOn(newGeom); assertNotNull(merged); assertEquals( "MULTILINESTRING ((40 40, 20 45, 45 35, 30 30), (20 35, 45 10, 31 6, 10 30, 20 35))", merged.toText()); }
@Test public void testNoConflictIfSameDiff() 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 45, 45 35, 30 30),(20 35, 45 10, 30 5, 10 30, 20 35))"); GeometryAttributeDiff diff = new GeometryAttributeDiff(oldGeom, newGeom); GeometryAttributeDiff diff2 = new GeometryAttributeDiff(oldGeom, newGeom); assertFalse(diff.conflicts(diff2)); }
ansi.a(pd.getName()).a(": "); ansi.reset(); String text = gd.getDiff().getDiffCoordsString(); for (int i = 0; i < text.length(); i++) { if (text.charAt(i) == '(') {
@Override public boolean conflicts(AttributeDiff ad) { if (!(ad instanceof GeometryAttributeDiff)) { return true; } final GeometryAttributeDiff gad = (GeometryAttributeDiff) ad; final TYPE myType = getType(); final TYPE otherType = ad.getType(); // if either side of the diff is a no change, then there's no conflict, regardless of the // type of the other side if (NO_CHANGE == myType || NO_CHANGE == otherType) { return false; } if (REMOVED == myType && REMOVED == otherType) { return false; } if (MODIFIED == myType && MODIFIED == otherType) { if (gad.diff.equals(diff)) { return false; } else { return true; } } if (ADDED == myType && ADDED == otherType) { return !gad.newGeometry.equalsExact(newGeometry); } return true; }
@Test public void testNoConflictAddingPoints() 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, 10 10, 20 45, 45 30, 30 30),(20 35, 45 10, 30 5, 10 30, 20 35))"); GeometryAttributeDiff diff = new GeometryAttributeDiff(oldGeom, newGeom); Geometry newGeom2 = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 31 6, 10 30, 20 35))"); GeometryAttributeDiff diff2 = new GeometryAttributeDiff(oldGeom, newGeom2); // the diff is conflicting assertTrue(diff.conflicts(diff2)); // yet it can be applied for patching assertTrue(diff2.canBeAppliedOn(newGeom)); Geometry merged = diff2.applyOn(newGeom); assertNotNull(merged); assertEquals( "MULTILINESTRING ((40 40, 10 10, 20 45, 45 30, 30 30), (20 35, 45 10, 31 6, 10 30, 20 35))", merged.toText()); }
@Test public void testNoConflictIfSameDiff() 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 45, 45 35, 30 30),(20 35, 45 10, 30 5, 10 30, 20 35))"); GeometryAttributeDiff diff = new GeometryAttributeDiff(oldGeom, newGeom); GeometryAttributeDiff diff2 = new GeometryAttributeDiff(oldGeom, newGeom); assertFalse(diff.conflicts(diff2)); }
ansi.a(pd.getName()).a(": "); ansi.reset(); String text = gd.getDiff().getDiffCoordsString(); for (int i = 0; i < text.length(); i++) { if (text.charAt(i) == '(') {
@Override public boolean conflicts(AttributeDiff ad) { if (!(ad instanceof GeometryAttributeDiff)) { return true; } final GeometryAttributeDiff gad = (GeometryAttributeDiff) ad; final TYPE myType = getType(); final TYPE otherType = ad.getType(); // if either side of the diff is a no change, then there's no conflict, regardless of the // type of the other side if (NO_CHANGE == myType || NO_CHANGE == otherType) { return false; } if (REMOVED == myType && REMOVED == otherType) { return false; } if (MODIFIED == myType && MODIFIED == otherType) { if (gad.diff.equals(diff)) { return false; } else { return true; } } if (ADDED == myType && ADDED == otherType) { return !gad.newGeometry.equalsExact(newGeometry); } return true; }
@Test public void testConflictPatcheable() 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 45, 45 35, 30 30),(20 35, 45 10, 30 5, 10 30, 20 35))"); GeometryAttributeDiff diff = new GeometryAttributeDiff(oldGeom, newGeom); Geometry newGeom2 = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 31 6, 10 30, 20 35))"); GeometryAttributeDiff diff2 = new GeometryAttributeDiff(oldGeom, newGeom2); // it's a conflict for the sake of merging branches assertTrue(diff.conflicts(diff2)); // yet can be merged for the sake of applying a patch assertTrue(diff2.canBeAppliedOn(newGeom)); Geometry merged = diff2.applyOn(newGeom); assertNotNull(merged); assertEquals( "MULTILINESTRING ((40 40, 20 45, 45 35, 30 30), (20 35, 45 10, 31 6, 10 30, 20 35))", merged.toText()); }
@Test public void testConflictEditedSamePoint() 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 45, 48 32, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))"); GeometryAttributeDiff diff = new GeometryAttributeDiff(oldGeom, newGeom); Geometry newGeom2 = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 41 33, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))"); GeometryAttributeDiff diff2 = new GeometryAttributeDiff(oldGeom, newGeom2); assertTrue(diff.conflicts(diff2)); }
@Override public AttributeDiff reversed() { if (type == TYPE.MODIFIED) { return new GeometryAttributeDiff(this.diff.reversed()); } else { return new GeometryAttributeDiff(oldGeometry, newGeometry); } }
ansi.a(pd.getName()).a(": "); ansi.reset(); String text = gd.getDiff().getDiffCoordsString(); for (int i = 0; i < text.length(); i++) { if (text.charAt(i) == '(') {
@Override public Geometry applyOn(@Nullable Object value) { Preconditions.checkState(canBeAppliedOn(value)); switch (type) { case ADDED: return newGeometry; case REMOVED: return null; case MODIFIED: default: return diff.applyOn((Geometry) value); } }
@Test public void testNoConflictAddingPoints() 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, 10 10, 20 45, 45 30, 30 30),(20 35, 45 10, 30 5, 10 30, 20 35))"); GeometryAttributeDiff diff = new GeometryAttributeDiff(oldGeom, newGeom); Geometry newGeom2 = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 31 6, 10 30, 20 35))"); GeometryAttributeDiff diff2 = new GeometryAttributeDiff(oldGeom, newGeom2); // the diff is conflicting assertTrue(diff.conflicts(diff2)); // yet it can be applied for patching assertTrue(diff2.canBeAppliedOn(newGeom)); Geometry merged = diff2.applyOn(newGeom); assertNotNull(merged); assertEquals( "MULTILINESTRING ((40 40, 10 10, 20 45, 45 30, 30 30), (20 35, 45 10, 31 6, 10 30, 20 35))", merged.toText()); }
@Test public void testConflict() 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 45),(20 35, 45 10, 20 35))"); GeometryAttributeDiff diff = new GeometryAttributeDiff(oldGeom, newGeom); Geometry newGeom2 = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 41 33, 25 25),(20 35, 45 10, 30 5, 10 30, 20 35))"); GeometryAttributeDiff diff2 = new GeometryAttributeDiff(oldGeom, newGeom2); assertTrue(diff.conflicts(diff2)); }
PropertyDescriptor descriptor = oldAttributes.get(i); if (Geometry.class.isAssignableFrom(descriptor.getType().getBinding())) { diffs.put(descriptor, new GeometryAttributeDiff((Geometry) oldValue.orNull(), (Geometry) null)); } else { PropertyDescriptor descriptor = newAttributes.get(i); if (Geometry.class.isAssignableFrom(descriptor.getType().getBinding())) { diffs.put(descriptor, new GeometryAttributeDiff((Geometry) null, (Geometry) newValue.orNull())); } else { if (Geometry.class .isAssignableFrom(oldAttributes.get(i).getType().getBinding())) { diffs.put(oldAttributes.get(i), new GeometryAttributeDiff( (Geometry) oldValue.orNull(), (Geometry) newValue.orNull())); } else { if (Geometry.class .isAssignableFrom(oldAttributes.get(i).getType().getBinding())) { diffs.put(oldAttributes.get(i), new GeometryAttributeDiff( (Geometry) oldValue.orNull(), (Geometry) null)); } else { PropertyDescriptor descriptor = newAttributes.get(i); if (Geometry.class.isAssignableFrom(descriptor.getType().getBinding())) { diffs.put(descriptor, new GeometryAttributeDiff((Geometry) null, (Geometry) newRevFeature.get(i).orNull())); } else {
@Test public void testConflictRemovingPoints() 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, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))"); GeometryAttributeDiff diff = new GeometryAttributeDiff(oldGeom, newGeom); Geometry newGeom2 = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 31 6, 10 30, 20 35))"); GeometryAttributeDiff diff2 = new GeometryAttributeDiff(oldGeom, newGeom2); // the diff reports a conflict assertTrue(diff.conflicts(diff2)); // yet it can be applied for patching assertTrue(diff2.canBeAppliedOn(newGeom)); Geometry merged = diff2.applyOn(newGeom); assertNotNull(merged); Geometry expected = new WKTReader().read( "MULTILINESTRING ((40 40, 45 30, 40 40), (20 35, 45 10, 31 6, 10 30, 20 35))"); assertEquals(expected, merged); }
@Test public void testConflict() 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 45),(20 35, 45 10, 20 35))"); GeometryAttributeDiff diff = new GeometryAttributeDiff(oldGeom, newGeom); Geometry newGeom2 = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 41 33, 25 25),(20 35, 45 10, 30 5, 10 30, 20 35))"); GeometryAttributeDiff diff2 = new GeometryAttributeDiff(oldGeom, newGeom2); assertTrue(diff.conflicts(diff2)); }