@Override public String asText() { switch (type) { case ADDED: return type.name().toCharArray()[0] + "\t" + TextValueSerializer.asString(newGeometry); case REMOVED: return type.name().toCharArray()[0] + "\t" + TextValueSerializer.asString(oldGeometry); case MODIFIED: default: return type.name().toCharArray()[0] + "\t" + diff.asText(); } }
@Override public String asText() { switch (type) { case ADDED: return type.name().toCharArray()[0] + "\t" + TextValueSerializer.asString(newGeometry); case REMOVED: return type.name().toCharArray()[0] + "\t" + TextValueSerializer.asString(oldGeometry); case MODIFIED: default: return type.name().toCharArray()[0] + "\t" + diff.asText(); } }
@Test public void testModifiedMultiPolygon() throws Exception { int NUM_COORDS = 10; Random rand = new Random(); List<Coordinate> list = Lists.newArrayList(); for (int i = 0; i < NUM_COORDS; i++) { list.add(new Coordinate(rand.nextInt(), rand.nextInt())); } Geometry oldGeom = new WKTReader().read( "MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),((20 35, 45 10, 30 5, 10 30, 20 35),(30 20, 20 25, 20 15, 30 20)))"); Geometry newGeom = new WKTReader().read( "MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),((20 35, 45 20, 30 5, 10 10, 10 30, 20 35)))"); LCSGeometryDiffImpl diff = new LCSGeometryDiffImpl(oldGeom, newGeom); LCSGeometryDiffImpl deserializedDiff = new LCSGeometryDiffImpl(diff.asText()); assertEquals(diff, deserializedDiff); assertEquals("4 point(s) deleted, 1 new point(s) added, 1 point(s) moved", diff.toString()); Geometry resultingGeom = diff.applyOn(oldGeom); assertEquals(newGeom, resultingGeom); }
@Test public void testModifiedMultiPolygon() throws Exception { int NUM_COORDS = 10; Random rand = new Random(); List<Coordinate> list = Lists.newArrayList(); for (int i = 0; i < NUM_COORDS; i++) { list.add(new Coordinate(rand.nextInt(), rand.nextInt())); } Geometry oldGeom = new WKTReader().read( "MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),((20 35, 45 10, 30 5, 10 30, 20 35),(30 20, 20 25, 20 15, 30 20)))"); Geometry newGeom = new WKTReader().read( "MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),((20 35, 45 20, 30 5, 10 10, 10 30, 20 35)))"); LCSGeometryDiffImpl diff = new LCSGeometryDiffImpl(oldGeom, newGeom); LCSGeometryDiffImpl deserializedDiff = new LCSGeometryDiffImpl(diff.asText()); assertEquals(diff, deserializedDiff); assertEquals("4 point(s) deleted, 1 new point(s) added, 1 point(s) moved", diff.toString()); Geometry resultingGeom = diff.applyOn(oldGeom); assertEquals(newGeom, resultingGeom); }
@Test public void testNoOldGeometry() throws Exception { 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((Geometry) null, newGeom); LCSGeometryDiffImpl deserializedDiff = new LCSGeometryDiffImpl(diff.asText()); assertEquals(diff, deserializedDiff); assertEquals("0 point(s) deleted, 13 new point(s) added, 0 point(s) moved", diff.toString()); }
@Test public void testNoOldGeometry() throws Exception { 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((Geometry) null, newGeom); LCSGeometryDiffImpl deserializedDiff = new LCSGeometryDiffImpl(diff.asText()); assertEquals(diff, deserializedDiff); assertEquals("0 point(s) deleted, 13 new point(s) added, 0 point(s) moved", diff.toString()); }
@Test public void testNoNewGeometry() 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))"); LCSGeometryDiffImpl diff = new LCSGeometryDiffImpl(oldGeom, (Geometry) null); LCSGeometryDiffImpl deserializedDiff = new LCSGeometryDiffImpl(diff.asText()); assertEquals(diff, deserializedDiff); assertEquals("9 point(s) deleted, 0 new point(s) added, 0 point(s) moved", diff.toString()); Geometry resultingGeom = diff.applyOn(oldGeom); assertNull(resultingGeom); }
@Test public void testNoNewGeometry() 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))"); LCSGeometryDiffImpl diff = new LCSGeometryDiffImpl(oldGeom, (Geometry) null); LCSGeometryDiffImpl deserializedDiff = new LCSGeometryDiffImpl(diff.asText()); assertEquals(diff, deserializedDiff); assertEquals("9 point(s) deleted, 0 new point(s) added, 0 point(s) moved", diff.toString()); Geometry resultingGeom = diff.applyOn(oldGeom); assertNull(resultingGeom); }
@Test public void testModifiedMultiLineString() 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); LCSGeometryDiffImpl deserializedDiff = new LCSGeometryDiffImpl(diff.asText()); assertEquals(diff, deserializedDiff); assertEquals("0 point(s) deleted, 4 new point(s) added, 3 point(s) moved", diff.toString()); Geometry resultingGeom = diff.applyOn(oldGeom); assertEquals(newGeom, resultingGeom); }
@Test public void testModifiedMultiLineString() 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); LCSGeometryDiffImpl deserializedDiff = new LCSGeometryDiffImpl(diff.asText()); assertEquals(diff, deserializedDiff); assertEquals("0 point(s) deleted, 4 new point(s) added, 3 point(s) moved", diff.toString()); Geometry resultingGeom = diff.applyOn(oldGeom); assertEquals(newGeom, resultingGeom); }
@Test public void testSameMultiPolygon() throws Exception { String wkt = "MULTIPOLYGON (((-75.0740073 38.6938098, -75.0739683 38.6935296, " + "-75.0745695 38.6934786, -75.0745824 38.6935715, -75.0741091 38.6936117, " + "-75.0741352 38.6937989, -75.0740073 38.6938098)))"; Geometry oldGeom = new WKTReader().read(wkt); Geometry newGeom = new WKTReader().read(wkt); assertTrue(oldGeom.equalsExact(newGeom)); LCSGeometryDiffImpl diff = new LCSGeometryDiffImpl(oldGeom, newGeom); String asText = diff.asText(); LCSGeometryDiffImpl deserializedDiff = new LCSGeometryDiffImpl(asText); assertEquals(diff, deserializedDiff); assertEquals("0 point(s) deleted, 0 new point(s) added, 0 point(s) moved", diff.toString()); Geometry resultingGeom = diff.applyOn(oldGeom); assertEquals(newGeom, resultingGeom); }
@Test public void testSameMultiPolygon() throws Exception { String wkt = "MULTIPOLYGON (((-75.0740073 38.6938098, -75.0739683 38.6935296, " + "-75.0745695 38.6934786, -75.0745824 38.6935715, -75.0741091 38.6936117, " + "-75.0741352 38.6937989, -75.0740073 38.6938098)))"; Geometry oldGeom = new WKTReader().read(wkt); Geometry newGeom = new WKTReader().read(wkt); assertTrue(oldGeom.equalsExact(newGeom)); LCSGeometryDiffImpl diff = new LCSGeometryDiffImpl(oldGeom, newGeom); String asText = diff.asText(); LCSGeometryDiffImpl deserializedDiff = new LCSGeometryDiffImpl(asText); assertEquals(diff, deserializedDiff); assertEquals("0 point(s) deleted, 0 new point(s) added, 0 point(s) moved", diff.toString()); Geometry resultingGeom = diff.applyOn(oldGeom); assertEquals(newGeom, resultingGeom); }