From 4a56f945c4ff169b748e8fec46d98638e5a5c8de Mon Sep 17 00:00:00 2001 From: Johannes Visintini Date: Fri, 30 Oct 2020 17:42:46 +0100 Subject: [PATCH 1/9] fix non-javadoc checkstyle warnings in oshdb-util --- .../bigspatialdata/oshdb/util/TableNames.java | 10 ++-- .../oshdb/util/celliterator/CellIterator.java | 15 +++--- .../OSHDBKeytablesNotFoundException.java | 3 +- .../util/geometry/fip/FastBboxInPolygon.java | 21 ++++---- .../geometry/fip/FastBboxOutsidePolygon.java | 22 ++++---- .../util/geometry/fip/FastInPolygon.java | 53 +++++++++++++------ .../geometry/fip/FastPolygonOperations.java | 41 ++++++++------ .../taginterpreter/BaseTagInterpreter.java | 1 - .../taginterpreter/DefaultTagInterpreter.java | 16 +++--- .../oshdb/util/tagtranslator/OSMTag.java | 4 +- .../util/tagtranslator/TagTranslator.java | 3 +- .../util/time/OSHDBTimestampInterval.java | 6 +-- .../oshdb/util/time/OSHDBTimestampList.java | 2 +- 13 files changed, 118 insertions(+), 79 deletions(-) diff --git a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/TableNames.java b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/TableNames.java index 91c36a72b..085a108e1 100644 --- a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/TableNames.java +++ b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/TableNames.java @@ -1,8 +1,7 @@ package org.heigit.bigspatialdata.oshdb.util; -import org.heigit.bigspatialdata.oshdb.osm.OSMType; - import java.util.Optional; +import org.heigit.bigspatialdata.oshdb.osm.OSMType; /** * Names for JDBC-Tables. @@ -54,13 +53,14 @@ public String toString() { } public String toString(String prefix) { - if(prefix != null && !prefix.trim().isEmpty()) - return prefix+"_"+this.toString(); + if (prefix != null && !prefix.trim().isEmpty()) { + return prefix + "_" + this.toString(); + } return this.toString(); } public static Optional forOSMType(OSMType type) { - switch(type) { + switch (type) { case NODE: return Optional.of(T_NODES); case WAY: return Optional.of(T_WAYS); case RELATION: return Optional.of(T_RELATIONS); diff --git a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/celliterator/CellIterator.java b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/celliterator/CellIterator.java index f52aae52a..27dbac6d4 100644 --- a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/celliterator/CellIterator.java +++ b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/celliterator/CellIterator.java @@ -267,7 +267,7 @@ public Stream iterateByTimestamps(GridOSHEntity cell) { || !allFullyInside && ( !oshEntity.getBoundingBox().intersects(boundingBox) || (isBoundByPolygon && bboxOutsidePolygon.test(oshEntity.getBoundingBox())) - )) { + )) { // this osh entity doesn't match the prefilter or is fully outside the requested // area of interest -> skip it return Stream.empty(); @@ -312,8 +312,8 @@ public Stream iterateByTimestamps(GridOSHEntity cell) { OSHEntities.getByTimestamps(oshEntity, new ArrayList<>(queryTs.keySet())); List results = new LinkedList<>(); - osmEntityLoop: - for (Map.Entry entity : osmEntityByTimestamps.entrySet()) { + osmEntityLoop: for (Map.Entry entity : + osmEntityByTimestamps.entrySet()) { OSHDBTimestamp timestamp = entity.getKey(); OSMEntity osmEntity = entity.getValue(); @@ -321,9 +321,10 @@ public Stream iterateByTimestamps(GridOSHEntity cell) { // skip because this entity is deleted at this timestamp continue; } - if (osmEntity instanceof OSMWay && ((OSMWay)osmEntity).getRefs().length == 0 + if (osmEntity instanceof OSMWay && ( + (OSMWay)osmEntity).getRefs().length == 0 || osmEntity instanceof OSMRelation - && ((OSMRelation)osmEntity).getMembers().length == 0) { + && ((OSMRelation)osmEntity).getMembers().length == 0) { // skip way/relation with zero nodes/members continue; } @@ -556,7 +557,7 @@ public Stream iterateByContribution(GridOSHEntity cell) { if (!oshEntityPreFilter.test(oshEntity) || !allFullyInside && ( !oshEntity.getBoundingBox().intersects(boundingBox) - || (isBoundByPolygon && bboxOutsidePolygon.test(oshEntity.getBoundingBox())) + || (isBoundByPolygon && bboxOutsidePolygon.test(oshEntity.getBoundingBox())) )) { // this osh entity doesn't match the prefilter or is fully outside the requested // area of interest -> skip it @@ -569,7 +570,7 @@ public Stream iterateByContribution(GridOSHEntity cell) { boolean fullyInside = allFullyInside || ( oshEntity.getBoundingBox().isInside(boundingBox) - && (!isBoundByPolygon || bboxInPolygon.test(oshEntity.getBoundingBox())) + && (!isBoundByPolygon || bboxInPolygon.test(oshEntity.getBoundingBox())) ); Map changesetTs = OSHEntities.getChangesetTimestamps(oshEntity); diff --git a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/exceptions/OSHDBKeytablesNotFoundException.java b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/exceptions/OSHDBKeytablesNotFoundException.java index c49b4f4b4..fe06bd566 100644 --- a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/exceptions/OSHDBKeytablesNotFoundException.java +++ b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/exceptions/OSHDBKeytablesNotFoundException.java @@ -3,6 +3,7 @@ public class OSHDBKeytablesNotFoundException extends Exception { public OSHDBKeytablesNotFoundException() { super("Keytables database not found, or db doesn't contain the required \"keytables\" tables. " - + "Make sure you have specified the right keytables database, for example by calling `keytables()` when using the OSHDB-API."); + + "Make sure you have specified the right keytables database, for example by calling " + + "`keytables()` when using the OSHDB-API."); } } diff --git a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxInPolygon.java b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxInPolygon.java index 8cded3179..2cae0ff66 100644 --- a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxInPolygon.java +++ b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxInPolygon.java @@ -32,11 +32,12 @@ public

FastBboxInPolygon(P geom) { polys.add((Polygon)geom); } else if (geom instanceof MultiPolygon) { MultiPolygon mp = (MultiPolygon)geom; - for (int i=0; i= innerBBox.getMaxY() && - boundingBox.getMinLon() <= innerBBox.getMinX() && boundingBox.getMaxLon() >= innerBBox.getMaxX()) { + if (boundingBox.getMinLat() <= innerBBox.getMinY() + && boundingBox.getMaxLat() >= innerBBox.getMaxY() + && boundingBox.getMinLon() <= innerBBox.getMinX() + && boundingBox.getMaxLon() >= innerBBox.getMaxX()) { return false; // the bounding box fully covers at least one of the polygon's inner rings } } diff --git a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxOutsidePolygon.java b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxOutsidePolygon.java index 243b64b49..97d903b4a 100644 --- a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxOutsidePolygon.java +++ b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxOutsidePolygon.java @@ -32,8 +32,9 @@ public

FastBboxOutsidePolygon(P geom) { polys.add((Polygon)geom); } else if (geom instanceof MultiPolygon) { MultiPolygon mp = (MultiPolygon)geom; - for (int i=0; i= innerBBox.getMaxY() && - boundingBox.getMinLon() <= innerBBox.getMinX() && boundingBox.getMaxLon() >= innerBBox.getMaxX()) { - return false; // the bounding box fully covers at least one of the (multi)polygon's outer rings + if (boundingBox.getMinLat() <= innerBBox.getMinY() + && boundingBox.getMaxLat() >= innerBBox.getMaxY() + && boundingBox.getMinLon() <= innerBBox.getMinX() + && boundingBox.getMaxLon() >= innerBBox.getMaxX()) { + // the bounding box fully covers at least one of the (multi)polygon's outer rings + return false; } } return true; diff --git a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastInPolygon.java b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastInPolygon.java index 2bfe09b30..25bbb7f23 100644 --- a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastInPolygon.java +++ b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastInPolygon.java @@ -33,7 +33,8 @@ private class Segment implements Serializable { } } - private final int AVERAGE_SEGMENTS_PER_BAND = 10; // something in the order of 10-20 works fine according to the link above + // something in the order of 10-20 works fine according to the link above + private static final int AVERAGE_SEGMENTS_PER_BAND = 10; private int numBands; @@ -46,10 +47,11 @@ private class Segment implements Serializable { protected

FastInPolygon(P geom) { MultiPolygon mp; - if (geom instanceof Polygon) + if (geom instanceof Polygon) { mp = (new GeometryFactory()).createMultiPolygon(new Polygon[]{(Polygon) geom}); - else + } else { mp = (MultiPolygon) geom; + } List segments = new LinkedList<>(); for (int i = 0; i < mp.getNumGeometries(); i++) { @@ -69,24 +71,36 @@ protected

FastInPolygon(P geom) { } } } - this.numBands = Math.max(1, segments.size() / AVERAGE_SEGMENTS_PER_BAND); // possible optimization: start with this value of numBands, and if the result has over-full bands, increase numBands (e.g. x2) and do it again + // possible optimization: start with this value of numBands, and if the result has over-full + // bands, increase numBands (e.g. x2) and do it again + this.numBands = Math.max(1, segments.size() / AVERAGE_SEGMENTS_PER_BAND); this.horizBands = new ArrayList<>(numBands); - for (int i = 0; i < numBands; i++) this.horizBands.add(new LinkedList<>()); + for (int i = 0; i < numBands; i++) { + this.horizBands.add(new LinkedList<>()); + } this.vertBands = new ArrayList<>(numBands); - for (int i = 0; i < numBands; i++) this.vertBands.add(new LinkedList<>()); + for (int i = 0; i < numBands; i++) { + this.vertBands.add(new LinkedList<>()); + } this.env = mp.getEnvelopeInternal(); this.envWidth = env.getMaxX() - env.getMinX(); this.envHeight = env.getMaxY() - env.getMinY(); segments.forEach(segment -> { - int startHorizBand = Math.max(0, Math.min(numBands - 1, (int) Math.floor(((segment.startY - env.getMinY()) / envHeight) * numBands))); - int endHorizBand = Math.max(0, Math.min(numBands - 1, (int) Math.floor(((segment.endY - env.getMinY()) / envHeight) * numBands))); - for (int i = Math.min(startHorizBand, endHorizBand); i <= Math.max(startHorizBand, endHorizBand); i++) { + int startHorizBand = Math.max(0, Math.min(numBands - 1, + (int) Math.floor(((segment.startY - env.getMinY()) / envHeight) * numBands))); + int endHorizBand = Math.max(0, Math.min(numBands - 1, + (int) Math.floor(((segment.endY - env.getMinY()) / envHeight) * numBands))); + for (int i = Math.min(startHorizBand, endHorizBand); + i <= Math.max(startHorizBand, endHorizBand); i++) { horizBands.get(i).add(segment); } - int startVertBand = Math.max(0, Math.min(numBands - 1, (int) Math.floor(((segment.startX - env.getMinX()) / envWidth) * numBands))); - int endVertBand = Math.max(0, Math.min(numBands - 1, (int) Math.floor(((segment.endX - env.getMinX()) / envWidth) * numBands))); - for (int i = Math.min(startVertBand, endVertBand); i <= Math.max(startVertBand, endVertBand); i++) { + int startVertBand = Math.max(0, Math.min(numBands - 1, + (int) Math.floor(((segment.startX - env.getMinX()) / envWidth) * numBands))); + int endVertBand = Math.max(0, Math.min(numBands - 1, + (int) Math.floor(((segment.endX - env.getMinX()) / envWidth) * numBands))); + for (int i = Math.min(startVertBand, endVertBand); + i <= Math.max(startVertBand, endVertBand); i++) { vertBands.get(i).add(segment); } }); @@ -98,7 +112,8 @@ protected

FastInPolygon(P geom) { * * @param point * @param dir boolean: true -> horizontal test, false -> vertical test - * @return crossing number of this point in the chosen direction, if the value is even the point is outside of the polygon, otherwise it is inside + * @return crossing number of this point in the chosen direction, + * if the value is even the point is outside of the polygon, otherwise it is inside */ protected int crossingNumber(Point point, boolean dir) { return dir ? crossingNumberX(point) : crossingNumberY(point); @@ -121,7 +136,8 @@ private int crossingNumberX(Point point) { if (P.x < V[i].x + vt * (V[i+1].x - V[i].x)) // P.x < intersect ++cn; // a valid crossing of y=P.y right of P.x*/ double vt = (point.getY() - segment.startY) / (segment.endY - segment.startY); - if (point.getX() < segment.startX + vt * (segment.endX - segment.startX)) { // P.x < intersect + if (point.getX() < segment.startX + + vt * (segment.endX - segment.startX)) { // P.x < intersect cn++; // a valid crossing of y=P.y right of P.x } } @@ -137,11 +153,14 @@ private int crossingNumberY(Point point) { int cn = 0; // crossing number counter for (Segment segment : band) { - if ((segment.startX <= point.getX() && segment.endX > point.getX()) || // an "upward" crossing - (segment.startX > point.getX() && segment.endX <= point.getX())) { // a "downward" crossing + if ((segment.startX <= point.getX() + && segment.endX > point.getX()) // an "upward" crossing + || (segment.startX > point.getX() + && segment.endX <= point.getX())) { // a "downward" crossing // compute the actual edge-ray intersect x-coordinate double vt = (point.getX() - segment.startX) / (segment.endX - segment.startX); - if (point.getY() < segment.startY + vt * (segment.endY - segment.startY)) { // P.y < intersect + if (point.getY() < segment.startY + + vt * (segment.endY - segment.startY)) { // P.y < intersect cn++; // a valid crossing of x=P.x below of P.y } } diff --git a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPolygonOperations.java b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPolygonOperations.java index 790047cb7..757f6c7db 100644 --- a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPolygonOperations.java +++ b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPolygonOperations.java @@ -1,19 +1,19 @@ package org.heigit.bigspatialdata.oshdb.util.geometry.fip; +import java.io.Serializable; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.locationtech.jts.geom.GeometryCollection; -import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.Envelope; import org.locationtech.jts.geom.Geometry; +import org.locationtech.jts.geom.GeometryCollection; +import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.MultiPolygon; import org.locationtech.jts.geom.Polygon; import org.locationtech.jts.geom.Polygonal; -import java.io.Serializable; -import java.util.ArrayList; public class FastPolygonOperations implements Serializable { - private final int AVERAGE_VERTICES_PER_BLOCK = 40; // todo: finetune this value + private static final int AVERAGE_VERTICES_PER_BLOCK = 40; // todo: finetune this value private int numBands; @@ -24,7 +24,8 @@ public class FastPolygonOperations implements Serializable { private double envHeight; public

FastPolygonOperations(P geom) { - double optNumBands = Math.max(1.0, Math.sqrt(1.0 * geom.getNumPoints() / AVERAGE_VERTICES_PER_BLOCK)); + double optNumBands = Math.max(1.0, + Math.sqrt(1.0 * geom.getNumPoints() / AVERAGE_VERTICES_PER_BLOCK)); final int bandIterations = (int) Math.ceil(Math.log(optNumBands) / Math.log(2)); numBands = (int) Math.pow(2, bandIterations); @@ -34,7 +35,7 @@ public

FastPolygonOperations(P geom) { GeometryFactory gf = new GeometryFactory(); - Geometry[] result = new Geometry[numBands*numBands]; + Geometry[] result = new Geometry[numBands * numBands]; traverseQuads(bandIterations, 0,0, env, geom, gf, result); blocks = new ArrayList<>(Arrays.asList(result)); @@ -77,25 +78,25 @@ private void traverseQuads( int index = y + x * numBands; resultBuffer[index] = theGeom; } else { - Envelope bottomLeftPart = new Envelope( + final Envelope bottomLeftPart = new Envelope( quadEnv.getMinX(), (quadEnv.getMinX() + quadEnv.getMaxX()) / 2, quadEnv.getMinY(), (quadEnv.getMinY() + quadEnv.getMaxY()) / 2 ); - Envelope topLeftPart = new Envelope( + final Envelope topLeftPart = new Envelope( quadEnv.getMinX(), (quadEnv.getMinX() + quadEnv.getMaxX()) / 2, (quadEnv.getMinY() + quadEnv.getMaxY()) / 2, quadEnv.getMaxY() ); - Envelope bottomRightPart = new Envelope( + final Envelope bottomRightPart = new Envelope( (quadEnv.getMinX() + quadEnv.getMaxX()) / 2, quadEnv.getMaxX(), quadEnv.getMinY(), (quadEnv.getMinY() + quadEnv.getMaxY()) / 2 ); - Envelope topRightPart = new Envelope( + final Envelope topRightPart = new Envelope( (quadEnv.getMinX() + quadEnv.getMaxX()) / 2, quadEnv.getMaxX(), (quadEnv.getMinY() + quadEnv.getMaxY()) / 2, @@ -133,19 +134,25 @@ private void traverseQuads( } public Geometry intersection(Geometry other) { - if (other == null || other.isEmpty()) return other; + if (other == null || other.isEmpty()) { + return other; + } Envelope otherEnv = other.getEnvelopeInternal(); - int minBandX = Math.max(0, Math.min(numBands - 1, (int)Math.floor((otherEnv.getMinX() - env.getMinX())/envWidth * numBands))); - int maxBandX = Math.max(0, Math.min(numBands - 1, (int)Math.floor((otherEnv.getMaxX() - env.getMinX())/envWidth * numBands))); - int minBandY = Math.max(0, Math.min(numBands - 1, (int)Math.floor((otherEnv.getMinY() - env.getMinY())/envHeight * numBands))); - int maxBandY = Math.max(0, Math.min(numBands - 1, (int)Math.floor((otherEnv.getMaxY() - env.getMinY())/envHeight * numBands))); + int minBandX = Math.max(0, Math.min(numBands - 1, + (int) Math.floor((otherEnv.getMinX() - env.getMinX()) / envWidth * numBands))); + int maxBandX = Math.max(0, Math.min(numBands - 1, + (int) Math.floor((otherEnv.getMaxX() - env.getMinX()) / envWidth * numBands))); + int minBandY = Math.max(0, Math.min(numBands - 1, + (int) Math.floor((otherEnv.getMinY() - env.getMinY()) / envHeight * numBands))); + int maxBandY = Math.max(0, Math.min(numBands - 1, + (int) Math.floor((otherEnv.getMaxY() - env.getMinY()) / envHeight * numBands))); Geometry intersector = null; for (int x = minBandX; x <= maxBandX; x++) { for (int y = minBandY; y <= maxBandY; y++) { - Geometry block = blocks.get(y + x*numBands); + Geometry block = blocks.get(y + x * numBands); if (intersector == null) { intersector = block; } else { diff --git a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/taginterpreter/BaseTagInterpreter.java b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/taginterpreter/BaseTagInterpreter.java index 5ac742d86..b8cf816f6 100644 --- a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/taginterpreter/BaseTagInterpreter.java +++ b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/taginterpreter/BaseTagInterpreter.java @@ -2,7 +2,6 @@ import java.util.Map; import java.util.Set; - import org.heigit.bigspatialdata.oshdb.osh.OSHWay; import org.heigit.bigspatialdata.oshdb.osm.OSMEntity; import org.heigit.bigspatialdata.oshdb.osm.OSMMember; diff --git a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/taginterpreter/DefaultTagInterpreter.java b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/taginterpreter/DefaultTagInterpreter.java index 5add8b3aa..92ae7e617 100644 --- a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/taginterpreter/DefaultTagInterpreter.java +++ b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/taginterpreter/DefaultTagInterpreter.java @@ -30,8 +30,9 @@ public class DefaultTagInterpreter extends BaseTagInterpreter { private int typeBoundaryValue = -1; private int typeRouteValue = -1; - private final static String defaultAreaTagsDefinitionFile = "json/polygon-features.json"; - private final static String defaultUninterestingTagsDefinitionFile = "json/uninterestingTags.json"; + private static final String defaultAreaTagsDefinitionFile = "json/polygon-features.json"; + private static final String defaultUninterestingTagsDefinitionFile + = "json/uninterestingTags.json"; /** * @@ -64,7 +65,9 @@ public DefaultTagInterpreter( Map> wayAreaTags = new HashMap<>(); JSONParser parser = new JSONParser(); - JSONArray tagList = (JSONArray)parser.parse(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(areaTagsDefinitionFile))); + JSONArray tagList = (JSONArray)parser.parse(new InputStreamReader( + Thread.currentThread().getContextClassLoader().getResourceAsStream(areaTagsDefinitionFile) + )); // todo: check json schema for validity @SuppressWarnings("unchecked") // we expect only JSON objects here in a valid definition file @@ -168,11 +171,12 @@ public boolean isLine(OSMEntity entity) { private boolean evaluateRelationForArea(OSMRelation entity) { int[] tags = entity.getRawTags(); // skip area=no check, since that doesn't make much sense for multipolygon relations (does it??) - // the following is slightly faster than running `return entity.hasTagValue(k1,v1) || entity.hasTagValue(k2,v2);` + // the following is slightly faster than running + // `return entity.hasTagValue(k1,v1) || entity.hasTagValue(k2,v2);` for (int i = 0; i < tags.length; i += 2) { - if (tags[i] == typeKey) + if (tags[i] == typeKey) { return tags[i + 1] == typeMultipolygonValue || tags[i + 1] == typeBoundaryValue; - else if (tags[i] > typeKey) { + } else if (tags[i] > typeKey) { return false; } } diff --git a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/tagtranslator/OSMTag.java b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/tagtranslator/OSMTag.java index bab13bfd4..d59900969 100644 --- a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/tagtranslator/OSMTag.java +++ b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/tagtranslator/OSMTag.java @@ -19,8 +19,8 @@ public String getValue() { @Override public boolean equals(Object o) { - return o instanceof OSMTag && - ((OSMTag)o).key.equals(this.key) && ((OSMTag)o).value.equals(this.value); + return o instanceof OSMTag + && ((OSMTag) o).key.equals(this.key) && ((OSMTag) o).value.equals(this.value); } @Override diff --git a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/tagtranslator/TagTranslator.java b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/tagtranslator/TagTranslator.java index 92ecef48b..4ccb36126 100644 --- a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/tagtranslator/TagTranslator.java +++ b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/tagtranslator/TagTranslator.java @@ -232,7 +232,8 @@ public OSHDBTag getOSHDBTagOf(OSMTag tag) { try (ResultSet values = valueIdQuery.executeQuery()) { if (!values.next()) { LOG.info("Unable to find tag {}={} in keytables.", tag.getKey(), tag.getValue()); - tagInt = new OSHDBTag(this.getOSHDBTagKeyOf(tag.getKey()).toInt(), getFakeId(tag.getValue())); + tagInt = new OSHDBTag( + this.getOSHDBTagKeyOf(tag.getKey()).toInt(), getFakeId(tag.getValue())); } else { tagInt = new OSHDBTag(values.getInt("KEYID"), values.getInt("VALUEID")); } diff --git a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/time/OSHDBTimestampInterval.java b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/time/OSHDBTimestampInterval.java index 1c6f1ad2c..50971cb33 100644 --- a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/time/OSHDBTimestampInterval.java +++ b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/time/OSHDBTimestampInterval.java @@ -46,8 +46,8 @@ public int compareTo(@Nonnull OSHDBTimestampInterval o) { @Override public boolean equals(Object o) { - return o != null && o instanceof OSHDBTimestampInterval && - this.fromTimestamp.equals(((OSHDBTimestampInterval) o).fromTimestamp) && - this.toTimestamp.equals(((OSHDBTimestampInterval) o).toTimestamp); + return o != null && o instanceof OSHDBTimestampInterval + && this.fromTimestamp.equals(((OSHDBTimestampInterval) o).fromTimestamp) + && this.toTimestamp.equals(((OSHDBTimestampInterval) o).toTimestamp); } } \ No newline at end of file diff --git a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/time/OSHDBTimestampList.java b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/time/OSHDBTimestampList.java index cca06ca2a..cc76807a9 100644 --- a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/time/OSHDBTimestampList.java +++ b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/time/OSHDBTimestampList.java @@ -18,7 +18,7 @@ public interface OSHDBTimestampList extends Serializable { SortedSet get(); /** - * Convenience method that converts the timestamp list into raw unix timestamps (long values) + * Convenience method that converts the timestamp list into raw unix timestamps (long values). * * @return this list of timestamps as raw unix timestamps (measured in seconds) */ From d201f3837dfac3c17c9b1ffcb52314c46c7605d5 Mon Sep 17 00:00:00 2001 From: Johannes Visintini Date: Tue, 3 Nov 2020 22:04:49 +0100 Subject: [PATCH 2/9] fix checkstyle warnings in oshdb-util tests --- .../util/celliterator/IterateAllTest.java | 14 +- .../IterateByContributionNodesTest.java | 61 ++-- ...eByContributionNotOsmTypeSpecificTest.java | 59 +-- .../IterateByContributionRelationsTest.java | 211 +++++------ ...ByContributionTypeNotMultipolygonTest.java | 107 +++--- .../IterateByContributionWaysTest.java | 11 +- ...rateByTimestampNotOsmTypeSpecificTest.java | 56 +-- .../IterateByTimestampsNodesTest.java | 78 ++-- .../IterateByTimestampsRelationsTest.java | 178 ++++----- .../IterateByTimestampsWaysTest.java | 8 +- .../celliterator/helpers/GridOSHFactory.java | 25 +- .../oshdb/util/geometry/GeoTest.java | 8 +- .../geometry/OSHDBGeometryBuilderTest.java | 8 +- .../geometry/fip/FastBboxInPolygonTest.java | 8 +- .../fip/FastBboxOutsidePolygonTest.java | 4 +- .../geometry/fip/FastPointInPolygonTest.java | 20 +- .../fip/FastPolygonOperationsTest.java | 33 +- .../geometry/helpers/FakeTagInterpreter.java | 29 +- .../helpers/OSMXmlReaderTagInterpreter.java | 7 +- ...yBuilderTestPolygonIncompleteDataTest.java | 16 +- ...metryBuilderTestWayIncompleteDataTest.java | 17 +- ...uilderTestOsmHistoryTestDataNodesTest.java | 22 +- ...ryTestDataRelationNotMultipolygonTest.java | 243 ++++++------- ...derTestOsmHistoryTestDataRelationTest.java | 140 ++++---- ...BuilderTestOsmHistoryTestDataWaysTest.java | 37 +- ...GeometryBuilderTestOsmTestData1xxTest.java | 71 ++-- ...GeometryBuilderTestOsmTestData3xxTest.java | 31 +- ...GeometryBuilderTestOsmTestData7xxTest.java | 168 +++++---- ...yBuilderMultipolygonInvalidOutersTest.java | 2 +- ...tryBuilderRelationOuterDirectionsTest.java | 20 +- ...uilderRelationTypeNotMultipolygonTest.java | 28 +- .../util/tagtranslator/TagTranslatorTest.java | 9 +- .../util/time/IsoDateTimeParserTest.java | 339 +++++++++--------- .../oshdb/util/time/OSHDBTimestampsTest.java | 32 +- .../util/time/TimestampFormatterTest.java | 5 +- .../util/xmlreader/MutableOSMEntity.java | 3 +- .../oshdb/util/xmlreader/MutableOSMNode.java | 4 +- .../oshdb/util/xmlreader/OSMXmlReader.java | 36 +- 38 files changed, 1103 insertions(+), 1045 deletions(-) diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateAllTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateAllTest.java index 4fd774887..316357f57 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateAllTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateAllTest.java @@ -45,11 +45,14 @@ public static void breakDownClass() throws SQLException { IterateAllTest.conn.close(); } - public IterateAllTest() {} + public IterateAllTest() { + } @Test - public void testIssue108() throws SQLException, IOException, ClassNotFoundException, ParseException, OSHDBKeytablesNotFoundException { - ResultSet oshCellsRawData = conn.prepareStatement("select data from " + TableNames.T_NODES).executeQuery(); + public void testIssue108() throws SQLException, IOException, ClassNotFoundException, + ParseException, OSHDBKeytablesNotFoundException { + ResultSet oshCellsRawData = conn.prepareStatement( + "select data from " + TableNames.T_NODES).executeQuery(); int countTotal = 0; int countCreated = 0; @@ -78,10 +81,11 @@ public void testIssue108() throws SQLException, IOException, ClassNotFoundExcept ).collect(Collectors.toList()); countTotal += result.size(); for (IterateAllEntry entry : result) { - if (entry.activities.contains(ContributionType.CREATION)) + if (entry.activities.contains(ContributionType.CREATION)) { countCreated++; - else + } else { countOther++; + } } } } diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionNodesTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionNodesTest.java index db529dc35..38b0fcf4d 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionNodesTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionNodesTest.java @@ -1,5 +1,9 @@ package org.heigit.bigspatialdata.oshdb.util.celliterator; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.util.EnumSet; import java.util.List; @@ -20,10 +24,6 @@ import org.locationtech.jts.geom.Point; import org.locationtech.jts.geom.Polygon; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - public class IterateByContributionNodesTest { private GridOSHNodes oshdbDataGridCell; private final OSMXmlReader osmXmlTestData = new OSMXmlReader(); @@ -412,13 +412,13 @@ public void testTagChangeTagFilterWithoutSuccess() { @Test public void testPolygonIntersectingDataPartly() { // lon lat changes, so that node in v2 is outside bbox - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,22.7); - coords[2]=new Coordinate(22.7,22.7); - coords[3]=new Coordinate(22.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,22.7); + coords[2] = new Coordinate(22.7,22.7); + coords[3] = new Coordinate(22.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -440,13 +440,14 @@ public void testPolygonIntersectingDataPartly() { @Test public void testTagFilterAndPolygonIntersectingDataPartly() { // lon lat changes, so that node in v2 is outside bbox - GeometryFactory geometryFactory = new GeometryFactory(); // create clipping polygon for area of interest - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,22.7); - coords[2]=new Coordinate(22.7,22.7); - coords[3]=new Coordinate(22.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + // create clipping polygon for area of interest + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,22.7); + coords[2] = new Coordinate(22.7,22.7); + coords[3] = new Coordinate(22.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -457,24 +458,25 @@ public void testTagFilterAndPolygonIntersectingDataPartly() { polygonFromCoordinates,// clipping polygon areaDecider, oshEntity -> oshEntity.getId() == 6, - osmEntity -> osmEntity.hasTagKey(osmXmlTestData.keys().get("shop")),// filter entity for tag = shop + // filter entity for tag = shop + osmEntity -> osmEntity.hasTagKey(osmXmlTestData.keys().get("shop")), false )).iterateByContribution( oshdbDataGridCell ).collect(Collectors.toList()); // result size =2 becuase if tag filtered for disappears it's a deletion - assertEquals(2,result.size());// one version with tag shop + assertEquals(2,result.size()); // one version with tag shop } @Test public void testCoordinatesRelativeToPolygon() throws IOException { - //different cases of relative position between node coordinate(s) and cell bbox / query polygon - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[4]; - coords[0]=new Coordinate(0.0,0.0); - coords[1]=new Coordinate(1.5,0.0); - coords[2]=new Coordinate(0.0,1.5); - coords[3]=new Coordinate(0.0,0.0); + // different cases of relative position between node coordinate(s) and cell bbox / query polygon + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[4]; + coords[0] = new Coordinate(0.0,0.0); + coords[1] = new Coordinate(1.5,0.0); + coords[2] = new Coordinate(0.0,1.5); + coords[3] = new Coordinate(0.0,0.0); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -487,9 +489,8 @@ public void testCoordinatesRelativeToPolygon() throws IOException { oshEntity -> oshEntity.getId() >= 10 && oshEntity.getId() < 20, osmEntity -> true, false - )).iterateByContribution( - GridOSHFactory.getGridOSHNodes(osmXmlTestData, 6, (new XYGrid(6)).getId(1.0, 1.0)/* approx. 0,0,5.6,5.6*/) - ).collect(Collectors.toList()); + )).iterateByContribution(GridOSHFactory.getGridOSHNodes(osmXmlTestData, 6, (new XYGrid(6)) + .getId(1.0, 1.0)/* approx. 0,0,5.6,5.6*/)).collect(Collectors.toList()); assertEquals(2, result.size()); assertTrue(result.get(0).osmEntity.getId() == 13); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionNotOsmTypeSpecificTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionNotOsmTypeSpecificTest.java index 7cf275c42..9c837295f 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionNotOsmTypeSpecificTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionNotOsmTypeSpecificTest.java @@ -1,5 +1,7 @@ package org.heigit.bigspatialdata.oshdb.util.celliterator; +import static org.junit.Assert.assertTrue; + import com.google.common.collect.Lists; import java.io.IOException; import java.util.Collections; @@ -18,14 +20,12 @@ import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.Polygon; -import static org.junit.Assert.assertTrue; - public class IterateByContributionNotOsmTypeSpecificTest { private final OSMXmlReader osmXmlTestData = new OSMXmlReader(); TagInterpreter areaDecider; private final List oshRelations; - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public IterateByContributionNotOsmTypeSpecificTest() throws IOException { osmXmlTestData.add("./src/test/resources/different-timestamps/polygon.osm"); @@ -36,16 +36,16 @@ public IterateByContributionNotOsmTypeSpecificTest() throws IOException { @Test public void testCellOutsidePolygon() throws IOException { - GridOSHRelations oshdbDataGridCell = GridOSHRelations.compact(69120, 12, 0, 0, 0, 0, Collections - .emptyList()); - - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,12.7); - coords[2]=new Coordinate(12.7,12.7); - coords[3]=new Coordinate(12.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GridOSHRelations oshdbDataGridCell = GridOSHRelations.compact(69120, 12, 0, 0, 0, 0, + Collections.emptyList()); + + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,12.7); + coords[2] = new Coordinate(12.7,12.7); + coords[3] = new Coordinate(12.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List resultPoly = (new CellIterator( @@ -63,17 +63,19 @@ public void testCellOutsidePolygon() throws IOException { ).collect(Collectors.toList()); assertTrue(resultPoly.isEmpty()); } + @Test public void testCellCoveringPolygon() throws IOException { - GridOSHRelations oshdbDataGridCell = GridOSHRelations.compact(0, 0, 0, 0, 0, 0, oshRelations); + final GridOSHRelations oshdbDataGridCell = GridOSHRelations.compact(0, 0, 0, 0, 0, 0, + oshRelations); - GeometryFactory geometryFactory = new GeometryFactory(); + final GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[4]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(12.7,12.7); - coords[2]=new Coordinate(12.7,10.3); - coords[3]=new Coordinate(10.8,10.3); + Coordinate[] coords = new Coordinate[4]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(12.7,12.7); + coords[2] = new Coordinate(12.7,10.3); + coords[3] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List resultPoly = (new CellIterator( @@ -94,16 +96,17 @@ public void testCellCoveringPolygon() throws IOException { @Test public void testCellFullyInsidePolygon() throws IOException { - GridOSHRelations oshdbDataGridCell = GridOSHRelations.compact(69120, 12, 0, 0, 0, 0, oshRelations); + final GridOSHRelations oshdbDataGridCell = GridOSHRelations.compact(69120, 12, 0, 0, 0, 0, + oshRelations); - GeometryFactory geometryFactory = new GeometryFactory(); + final GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(-180,-90); - coords[1]=new Coordinate(180 ,-90); - coords[2]=new Coordinate(180,90); - coords[3]=new Coordinate(-180,90); - coords[4]=new Coordinate(-180,-90); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(-180,-90); + coords[1] = new Coordinate(180,-90); + coords[2] = new Coordinate(180,90); + coords[3] = new Coordinate(-180,90); + coords[4] = new Coordinate(-180,-90); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List resultPoly = (new CellIterator( diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionRelationsTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionRelationsTest.java index 43b18c800..d76c4466f 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionRelationsTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionRelationsTest.java @@ -1,5 +1,10 @@ package org.heigit.bigspatialdata.oshdb.util.celliterator; +import static junit.framework.TestCase.fail; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.util.EnumSet; import java.util.List; @@ -20,16 +25,11 @@ import org.locationtech.jts.geom.MultiPolygon; import org.locationtech.jts.geom.Polygon; -import static junit.framework.TestCase.fail; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - public class IterateByContributionRelationsTest { private GridOSHRelations oshdbDataGridCell; private final OSMXmlReader osmXmlTestData = new OSMXmlReader(); TagInterpreter areaDecider; - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public IterateByContributionRelationsTest() throws IOException { osmXmlTestData.add("./src/test/resources/different-timestamps/polygon.osm");// read osm xml data @@ -44,19 +44,23 @@ public void testGeometryChange() { // relation: creation and two geometry changes, but no tag changes // relation getting more ways, one disappears List result = (new CellIterator( + // get in this time interval every contribution new OSHDBTimestamps( "2000-01-01T00:00:00Z", "2020-01-01T00:00:00Z" - ).get(),// get in this timeinterval every contribution - new OSHDBBoundingBox(-180,-90, 180, 90),// look at dat in this bbox - areaDecider,// needed to create actual geometries from OSM data - oshEntity -> oshEntity.getId() == 500,// oshEntityPreFilter: get data of relation with id 500 + ).get(), + // look at dat in this bbox + new OSHDBBoundingBox(-180,-90, 180, 90), + // needed to create actual geometries from OSM data + areaDecider, + // oshEntityPreFilter: get data of relation with id 500 + oshEntity -> oshEntity.getId() == 500, osmEntity -> true,// osmEntityFilter: true -> get all false )).iterateByContribution( oshdbDataGridCell ).collect(Collectors.toList()); - // one creation and two gemotry changes should give a result with 3 elements + // one creation and two geomotry changes should give a result with 3 elements assertEquals(3, result.size()); // check if the contribution types are correct assertEquals( @@ -133,8 +137,7 @@ public void testWaysNotExistent() { )).iterateByContribution( oshdbDataGridCell ).collect(Collectors.toList()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -342,8 +345,7 @@ public void testNodesOfWaysNotExistent() { )).iterateByContribution( oshdbDataGridCell ).collect(Collectors.toList()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -613,13 +615,13 @@ public void testWaySplitUpInTwo() { @Test public void testPolygonIntersectingDataPartly() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,22.7); - coords[2]=new Coordinate(22.7,22.7); - coords[3]=new Coordinate(22.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,22.7); + coords[2] = new Coordinate(22.7,22.7); + coords[3] = new Coordinate(22.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -641,13 +643,13 @@ public void testPolygonIntersectingDataPartly() { @Test public void testPolygonIntersectingDataOnlyAtBorderLine() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.7,10.4); - coords[1]=new Coordinate(10.94,10.4); - coords[2]=new Coordinate(10.94,10.9); - coords[3]=new Coordinate(10.7,10.9); - coords[4]=new Coordinate(10.7,10.4); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.7,10.4); + coords[1] = new Coordinate(10.94,10.4); + coords[2] = new Coordinate(10.94,10.9); + coords[3] = new Coordinate(10.7,10.9); + coords[4] = new Coordinate(10.7,10.4); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -669,13 +671,13 @@ public void testPolygonIntersectingDataOnlyAtBorderLine() { @Test public void testPolygonIntersectingDataCompletely() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,52.7); - coords[2]=new Coordinate(52.7,52.7); - coords[3]=new Coordinate(52.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,52.7); + coords[2] = new Coordinate(52.7,52.7); + coords[3] = new Coordinate(52.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -697,13 +699,13 @@ public void testPolygonIntersectingDataCompletely() { @Test public void testPolygonNotIntersectingData() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(48,49); - coords[1]=new Coordinate(48 ,50); - coords[2]=new Coordinate(49,50); - coords[3]=new Coordinate(49,49); - coords[4]=new Coordinate(48,49); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(48,49); + coords[1] = new Coordinate(48,50); + coords[2] = new Coordinate(49,50); + coords[3] = new Coordinate(49,49); + coords[4] = new Coordinate(48,49); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -755,13 +757,13 @@ public void testNodeChangeOutsideBbox() { @Test public void testPolygonIntersectingDataCompletelyTimeIntervalAfterChanges() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,52.7); - coords[2]=new Coordinate(52.7,52.7); - coords[3]=new Coordinate(52.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,52.7); + coords[2] = new Coordinate(52.7,52.7); + coords[3] = new Coordinate(52.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -860,13 +862,13 @@ public void testSelfIntersectingPolygonClipped() { // Polygon with self crossing way // partly intersected by bbox polygon // happy if it works without crashing - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(7.31,1.0); - coords[1]=new Coordinate(7.335,1.0); - coords[2]=new Coordinate(7.335,2.0); - coords[3]=new Coordinate(7.31,2.0); - coords[4]=new Coordinate(7.31,1.0); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(7.31,1.0); + coords[1] = new Coordinate(7.335,1.0); + coords[2] = new Coordinate(7.335,2.0); + coords[3] = new Coordinate(7.31,2.0); + coords[4] = new Coordinate(7.31,1.0); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -887,7 +889,8 @@ public void testSelfIntersectingPolygonClipped() { @Test public void testMembersDisappear() { - // relation with one way member(nodes of way have changes in 2009 and 2011), in version 2 member is deleted + // relation with one way member(nodes of way have changes in 2009 and 2011), in version 2 member + // is deleted List result = (new CellIterator( new OSHDBTimestamps( "2000-01-01T00:00:00Z", @@ -912,7 +915,7 @@ public void testMembersDisappear() { @Test public void testTimeIntervalAfterDeletionInVersion2() { - // relation in second version visible = false, timeinterval includes version 3 + // relation in second version visible = false, time interval includes version 3 List result = (new CellIterator( new OSHDBTimestamps( "2016-01-01T00:00:00Z", @@ -936,7 +939,7 @@ public void testTimeIntervalAfterDeletionInVersion2() { @Test public void testTimeIntervalAfterDeletionInCurrentVersion() { - // relation in first and third version visible = false, timeinterval includes version 3 + // relation in first and third version visible = false, time interval includes version 3 List result = (new CellIterator( new OSHDBTimestamps( "2016-01-01T00:00:00Z", @@ -960,7 +963,7 @@ public void testTimeIntervalAfterDeletionInCurrentVersion() { @Test public void testExcludingVersion2() { - // relation in second version visible = false, timeinterval includes version 3 + // relation in second version visible = false, time interval includes version 3 List result = (new CellIterator( new OSHDBTimestamps( "2012-01-01T00:00:00Z", @@ -969,7 +972,7 @@ public void testExcludingVersion2() { new OSHDBBoundingBox(-180,-90, 180, 90), areaDecider, oshEntity -> oshEntity.getId() == 500, - osmEntity -> !(osmEntity.getVersion()==2), + osmEntity -> !(osmEntity.getVersion() == 2), false )).iterateByContribution( oshdbDataGridCell @@ -985,14 +988,15 @@ public void testExcludingVersion2() { @Test public void testMembersDisappearClipped() { - // relation with one way member(nodes of way have changes in 2009 and 2011), in version 2 member is deleted - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,22.7); - coords[2]=new Coordinate(22.7,22.7); - coords[3]=new Coordinate(22.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + // relation with one way member(nodes of way have changes in 2009 and 2011), in version 2 member + // is deleted + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,22.7); + coords[2] = new Coordinate(22.7,22.7); + coords[3] = new Coordinate(22.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -1023,14 +1027,14 @@ public void testMembersDisappearClipped() { @Test public void testTimeIntervalAfterDeletionInVersion2Clipped() { - // relation in second version visible = false, timeinterval includes version 3 - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,22.7); - coords[2]=new Coordinate(22.7,22.7); - coords[3]=new Coordinate(22.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + // relation in second version visible = false, time interval includes version 3 + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,22.7); + coords[2] = new Coordinate(22.7,22.7); + coords[3] = new Coordinate(22.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -1057,14 +1061,14 @@ public void testTimeIntervalAfterDeletionInVersion2Clipped() { @Test public void testTimeIntervalAfterDeletionInCurrentVersionClipped() { - // relation in first and third version visible = false, timeinterval includes version 3 - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,22.7); - coords[2]=new Coordinate(22.7,22.7); - coords[3]=new Coordinate(22.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + // relation in first and third version visible = false, time interval includes version 3 + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,22.7); + coords[2] = new Coordinate(22.7,22.7); + coords[3] = new Coordinate(22.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -1090,14 +1094,14 @@ public void testTimeIntervalAfterDeletionInCurrentVersionClipped() { @Test public void testExcludingVersion2Clipped() { - // relation in second version visible = false, timeinterval includes version 3 - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(7.31,1.0); - coords[1]=new Coordinate(7.335,1.0); - coords[2]=new Coordinate(7.335,2.0); - coords[3]=new Coordinate(7.31,2.0); - coords[4]=new Coordinate(7.31,1.0); + // relation in second version visible = false, time interval includes version 3 + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(7.31,1.0); + coords[1] = new Coordinate(7.335,1.0); + coords[2] = new Coordinate(7.335,2.0); + coords[3] = new Coordinate(7.31,2.0); + coords[4] = new Coordinate(7.31,1.0); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -1108,7 +1112,7 @@ public void testExcludingVersion2Clipped() { polygonFromCoordinates, areaDecider, oshEntity -> oshEntity.getId() == 500, - osmEntity -> !(osmEntity.getVersion()==2), + osmEntity -> !(osmEntity.getVersion() == 2), false )).iterateByContribution( oshdbDataGridCell @@ -1125,13 +1129,13 @@ public void testExcludingVersion2Clipped() { @Test public void testClippingPolygonIsVeryBig() { // relation with two way members(nodes of ways have changes in 2009 and 2011) - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(-180,-90); - coords[1]=new Coordinate(180 ,-90); - coords[2]=new Coordinate(180,90); - coords[3]=new Coordinate(-180,90); - coords[4]=new Coordinate(-180,-90); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(-180,-90); + coords[1] = new Coordinate(180,-90); + coords[2] = new Coordinate(180,90); + coords[3] = new Coordinate(-180,90); + coords[4] = new Coordinate(-180,-90); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -1150,7 +1154,4 @@ public void testClippingPolygonIsVeryBig() { assertEquals(3, result.size()); } - - - } diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionTypeNotMultipolygonTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionTypeNotMultipolygonTest.java index 7476f67b0..f5719bd5b 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionTypeNotMultipolygonTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionTypeNotMultipolygonTest.java @@ -1,5 +1,10 @@ package org.heigit.bigspatialdata.oshdb.util.celliterator; +import static junit.framework.TestCase.fail; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.util.EnumSet; import java.util.List; @@ -19,11 +24,6 @@ import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.Polygon; -import static junit.framework.TestCase.fail; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - public class IterateByContributionTypeNotMultipolygonTest { private GridOSHRelations oshdbDataGridCell; private final OSMXmlReader osmXmlTestData = new OSMXmlReader(); @@ -126,8 +126,7 @@ public void testWaysNotExistent() { )).iterateByContribution( oshdbDataGridCell ).collect(Collectors.toList()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -336,8 +335,7 @@ public void testNodesOfWaysNotExistent() { )).iterateByContribution( oshdbDataGridCell ).collect(Collectors.toList()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -598,13 +596,13 @@ public void testWaySplitUpInTwo() { @Test public void testPolygonIntersectingDataPartly() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,22.7); - coords[2]=new Coordinate(22.7,22.7); - coords[3]=new Coordinate(22.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,22.7); + coords[2] = new Coordinate(22.7,22.7); + coords[3] = new Coordinate(22.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -626,13 +624,13 @@ public void testPolygonIntersectingDataPartly() { @Test public void testPolygonIntersectingDataCompletely() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,52.7); - coords[2]=new Coordinate(52.7,52.7); - coords[3]=new Coordinate(52.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,52.7); + coords[2] = new Coordinate(52.7,52.7); + coords[3] = new Coordinate(52.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -654,13 +652,13 @@ public void testPolygonIntersectingDataCompletely() { @Test public void testPolygonNotIntersectingData() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(48,49); - coords[1]=new Coordinate(48 ,50); - coords[2]=new Coordinate(49,50); - coords[3]=new Coordinate(49,49); - coords[4]=new Coordinate(48,49); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(48,49); + coords[1] = new Coordinate(48,50); + coords[2] = new Coordinate(49,50); + coords[3] = new Coordinate(49,49); + coords[4] = new Coordinate(48,49); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -713,13 +711,13 @@ public void testNodeChangeOutsideBbox() { @Test public void testPolygonIntersectingDataCompletelyTimeIntervalAfterChanges() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,52.7); - coords[2]=new Coordinate(52.7,52.7); - coords[3]=new Coordinate(52.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,52.7); + coords[2] = new Coordinate(52.7,52.7); + coords[3] = new Coordinate(52.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -781,13 +779,13 @@ public void testBboxOutsidePolygon() { @Test public void testSelfIntersectingPolygonClipped() { // Polygon with self crossing way - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(7.31,1.0); - coords[1]=new Coordinate(7.335,1.0); - coords[2]=new Coordinate(7.335,2.0); - coords[3]=new Coordinate(7.31,2.0); - coords[4]=new Coordinate(7.31,1.0); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(7.31,1.0); + coords[1] = new Coordinate(7.335,1.0); + coords[2] = new Coordinate(7.335,2.0); + coords[3] = new Coordinate(7.31,2.0); + coords[4] = new Coordinate(7.31,1.0); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -810,7 +808,8 @@ public void testSelfIntersectingPolygonClipped() { @Test public void testMembersDisappear() { - // relation with one way member(nodes of way have changes in 2009 and 2011), in version 2 member is deleted + // relation with one way member(nodes of way have changes in 2009 and 2011), in version 2 member + // is deleted List result = (new CellIterator( new OSHDBTimestamps( "2000-01-01T00:00:00Z", @@ -835,7 +834,7 @@ public void testMembersDisappear() { @Test public void testMembersDisappearAndPreviousIsNull() { // relation in last version without members, previous version visible=false - // timeinterval includes only last version + // time interval includes only last version List result = (new CellIterator( new OSHDBTimestamps( "2012-01-01T00:00:00Z", @@ -854,14 +853,14 @@ public void testMembersDisappearAndPreviousIsNull() { @Test public void testTimeIntervalAfterDeletionInCurrentVersionClipped() { - // relation in first and third version visible = false, timeinterval includes version 3 - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,22.7); - coords[2]=new Coordinate(22.7,22.7); - coords[3]=new Coordinate(22.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + // relation in first and third version visible = false, time interval includes version 3 + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,22.7); + coords[2] = new Coordinate(22.7,22.7); + coords[3] = new Coordinate(22.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionWaysTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionWaysTest.java index d6142895b..f0e42297f 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionWaysTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionWaysTest.java @@ -1,5 +1,9 @@ package org.heigit.bigspatialdata.oshdb.util.celliterator; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.util.EnumSet; import java.util.List; @@ -17,10 +21,6 @@ import org.locationtech.jts.geom.LineString; import org.locationtech.jts.geom.Polygon; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - public class IterateByContributionWaysTest { private GridOSHWays oshdbDataGridCell; private final OSMXmlReader osmXmlTestData = new OSMXmlReader(); @@ -548,7 +548,8 @@ public void testNodeRefsDeletedInVersion2() { assertEquals( EnumSet.of(ContributionType.CREATION), result.get(0).activities.get() - );assertEquals( + ); + assertEquals( EnumSet.of(ContributionType.GEOMETRY_CHANGE), result.get(1).activities.get() ); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampNotOsmTypeSpecificTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampNotOsmTypeSpecificTest.java index 948c3a6e7..b2037e217 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampNotOsmTypeSpecificTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampNotOsmTypeSpecificTest.java @@ -1,5 +1,7 @@ package org.heigit.bigspatialdata.oshdb.util.celliterator; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -30,8 +32,6 @@ import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.Polygon; -import static org.junit.Assert.assertTrue; - public class IterateByTimestampNotOsmTypeSpecificTest { private final OSMXmlReader osmXmlTestData = new OSMXmlReader(); TagInterpreter areaDecider; @@ -54,7 +54,8 @@ public IterateByTimestampNotOsmTypeSpecificTest() throws IOException { )); } - for (Entry> entry : osmXmlTestData.relations().asMap().entrySet()) { + for (Entry> entry : + osmXmlTestData.relations().asMap().entrySet()) { Collection relationVersions = entry.getValue(); oshRelations.add(OSHRelationImpl.build(new ArrayList<>(relationVersions), relationVersions.stream().flatMap(osmRelation -> @@ -74,14 +75,15 @@ public IterateByTimestampNotOsmTypeSpecificTest() throws IOException { @Test public void testCellOutsidePolygon() throws IOException { // GridOSHRelations cell-bbox is not covering query polygon - GridOSHRelations oshdbDataGridCell = GridOSHRelations.compact(69120, 12, 0, 0, 0, 0, oshRelations); - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,12.7); - coords[2]=new Coordinate(12.7,12.7); - coords[3]=new Coordinate(12.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GridOSHRelations oshdbDataGridCell = GridOSHRelations.compact(69120, 12, 0, 0, 0, 0, + oshRelations); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,12.7); + coords[2] = new Coordinate(12.7,12.7); + coords[3] = new Coordinate(12.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -104,13 +106,14 @@ public void testCellOutsidePolygon() throws IOException { @Test public void testCellCoveringPolygon() throws IOException { // GridOSHRelations cell-bbox is completely covering query polygon - GridOSHRelations oshdbDataGridCell = GridOSHRelations.compact(0, 0, 0, 0, 0, 0, oshRelations); - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[4]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(12.7,12.7); - coords[2]=new Coordinate(12.7,10.3); - coords[3]=new Coordinate(10.8,10.3); + final GridOSHRelations oshdbDataGridCell = GridOSHRelations.compact(0, 0, 0, 0, 0, 0, + oshRelations); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[4]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(12.7,12.7); + coords[2] = new Coordinate(12.7,10.3); + coords[3] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -133,14 +136,15 @@ public void testCellCoveringPolygon() throws IOException { @Test public void testCellFullyInsidePolygon() throws IOException { // GridOSHRelations cell-bbox is inside query polygon - GridOSHRelations oshdbDataGridCell = GridOSHRelations.compact(69120, 12, 0, 0, 0, 0, oshRelations); - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(-180,-90); - coords[1]=new Coordinate(180 ,-90); - coords[2]=new Coordinate(180,90); - coords[3]=new Coordinate(-180,90); - coords[4]=new Coordinate(-180,-90); + final GridOSHRelations oshdbDataGridCell = GridOSHRelations.compact(69120, 12, 0, 0, 0, 0, + oshRelations); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(-180,-90); + coords[1] = new Coordinate(180,-90); + coords[2] = new Coordinate(180,90); + coords[3] = new Coordinate(-180,90); + coords[4] = new Coordinate(-180,-90); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsNodesTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsNodesTest.java index 28de62019..9c67c24a3 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsNodesTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsNodesTest.java @@ -1,5 +1,10 @@ package org.heigit.bigspatialdata.oshdb.util.celliterator; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.util.List; import java.util.stream.Collectors; @@ -17,11 +22,6 @@ import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.Polygon; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - public class IterateByTimestampsNodesTest { private GridOSHNodes oshdbDataGridCell; private final OSMXmlReader osmXmlTestData = new OSMXmlReader(); @@ -54,8 +54,10 @@ public void testGeometryChange() { ).collect(Collectors.toList()); assertEquals(11, result.size()); - assertNotEquals(result.get(1).geometry.get().getCoordinates(), result.get(0).geometry.get().getCoordinates()); - assertNotEquals(result.get(2).geometry.get().getCoordinates(), result.get(1).geometry.get().getCoordinates()); + assertNotEquals(result.get(1).geometry.get().getCoordinates(), + result.get(0).geometry.get().getCoordinates()); + assertNotEquals(result.get(2).geometry.get().getCoordinates(), + result.get(1).geometry.get().getCoordinates()); } @Test @@ -136,17 +138,28 @@ public void testMultipleChanges() { ).collect(Collectors.toList()); assertEquals(11, result.size()); - assertNotEquals(result.get(1).geometry.get().getCoordinates(), result.get(0).geometry.get().getCoordinates()); - assertArrayEquals(result.get(2).geometry.get().getCoordinates(), result.get(1).geometry.get().getCoordinates()); - assertNotEquals(result.get(3).geometry.get().getCoordinates(), result.get(2).geometry.get().getCoordinates()); - assertArrayEquals(result.get(5).geometry.get().getCoordinates(), result.get(3).geometry.get().getCoordinates()); - assertNotEquals(result.get(6).geometry.get().getCoordinates(), result.get(3).geometry.get().getCoordinates()); - assertArrayEquals(result.get(9).geometry.get().getCoordinates(), result.get(6).geometry.get().getCoordinates()); - assertNotEquals(result.get(1).osmEntity.getRawTags(), result.get(0).osmEntity.getRawTags()); - assertEquals(result.get(2).osmEntity.getRawTags(), result.get(1).osmEntity.getRawTags()); - assertNotEquals(result.get(3).osmEntity.getRawTags(), result.get(2).osmEntity.getRawTags()); - assertEquals(result.get(5).osmEntity.getRawTags(), result.get(4).osmEntity.getRawTags()); - assertNotEquals(result.get(9).osmEntity.getRawTags(), result.get(6).osmEntity.getRawTags()); + assertNotEquals(result.get(1).geometry.get().getCoordinates(), + result.get(0).geometry.get().getCoordinates()); + assertArrayEquals(result.get(2).geometry.get().getCoordinates(), + result.get(1).geometry.get().getCoordinates()); + assertNotEquals(result.get(3).geometry.get().getCoordinates(), + result.get(2).geometry.get().getCoordinates()); + assertArrayEquals(result.get(5).geometry.get().getCoordinates(), + result.get(3).geometry.get().getCoordinates()); + assertNotEquals(result.get(6).geometry.get().getCoordinates(), + result.get(3).geometry.get().getCoordinates()); + assertArrayEquals(result.get(9).geometry.get().getCoordinates(), + result.get(6).geometry.get().getCoordinates()); + assertNotEquals(result.get(1).osmEntity.getRawTags(), + result.get(0).osmEntity.getRawTags()); + assertEquals(result.get(2).osmEntity.getRawTags(), + result.get(1).osmEntity.getRawTags()); + assertNotEquals(result.get(3).osmEntity.getRawTags(), + result.get(2).osmEntity.getRawTags()); + assertEquals(result.get(5).osmEntity.getRawTags(), + result.get(4).osmEntity.getRawTags()); + assertNotEquals(result.get(9).osmEntity.getRawTags(), + result.get(6).osmEntity.getRawTags()); } @Test @@ -192,13 +205,13 @@ public void testTagChangeTagFilterWithoutSuccess() { @Test public void testTagFilterAndPolygonIntersectingDataPartly() { // lon lat changes, so that node in v2 is outside bbox - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,22.7); - coords[2]=new Coordinate(22.7,22.7); - coords[3]=new Coordinate(22.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,22.7); + coords[2] = new Coordinate(22.7,22.7); + coords[3] = new Coordinate(22.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -221,12 +234,12 @@ public void testTagFilterAndPolygonIntersectingDataPartly() { @Test public void testCoordinatesRelativeToPolygon() throws IOException { //different cases of relative position between node coordinate(s) and cell bbox / query polygon - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[4]; - coords[0]=new Coordinate(0.0,0.0); - coords[1]=new Coordinate(1.5,0.0); - coords[2]=new Coordinate(0.0,1.5); - coords[3]=new Coordinate(0.0,0.0); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[4]; + coords[0] = new Coordinate(0.0,0.0); + coords[1] = new Coordinate(1.5,0.0); + coords[2] = new Coordinate(0.0,1.5); + coords[3] = new Coordinate(0.0,0.0); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -241,7 +254,8 @@ public void testCoordinatesRelativeToPolygon() throws IOException { osmEntity -> true, false )).iterateByTimestamps( - GridOSHFactory.getGridOSHNodes(osmXmlTestData, 6, (new XYGrid(6)).getId(1.0, 1.0)/* approx. 0,0,5.6,5.6*/) + GridOSHFactory.getGridOSHNodes(osmXmlTestData, 6, (new XYGrid(6)) + .getId(1.0, 1.0)/* approx. 0,0,5.6,5.6*/) ).collect(Collectors.toList()); assertEquals(3, result.size()); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsRelationsTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsRelationsTest.java index 4f351b5f3..34318c119 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsRelationsTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsRelationsTest.java @@ -1,5 +1,10 @@ package org.heigit.bigspatialdata.oshdb.util.celliterator; +import static junit.framework.TestCase.fail; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.util.List; import java.util.stream.Collectors; @@ -19,11 +24,6 @@ import org.locationtech.jts.geom.MultiPolygon; import org.locationtech.jts.geom.Polygon; -import static junit.framework.TestCase.fail; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - public class IterateByTimestampsRelationsTest { private GridOSHRelations oshdbDataGridCell; private final OSMXmlReader osmXmlTestData = new OSMXmlReader(); @@ -106,8 +106,7 @@ public void testWaysNotExistent() { )).iterateByTimestamps( oshdbDataGridCell ).collect(Collectors.toList()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -269,8 +268,7 @@ public void testNodesOfWaysNotExistent() { )).iterateByTimestamps( oshdbDataGridCell ).collect(Collectors.toList()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -470,13 +468,13 @@ public void testWaySplitUpInTwo() { @Test public void testPolygonIntersectingDataPartly() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,22.7); - coords[2]=new Coordinate(22.7,22.7); - coords[3]=new Coordinate(22.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,22.7); + coords[2] = new Coordinate(22.7,22.7); + coords[3] = new Coordinate(22.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -500,13 +498,13 @@ public void testPolygonIntersectingDataPartly() { @Test public void testPolygonIntersectingDataOnlyAtBorderLine() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.7,10.4); - coords[1]=new Coordinate(10.94,10.4); - coords[2]=new Coordinate(10.94,10.9); - coords[3]=new Coordinate(10.7,10.9); - coords[4]=new Coordinate(10.7,10.4); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.7,10.4); + coords[1] = new Coordinate(10.94,10.4); + coords[2] = new Coordinate(10.94,10.9); + coords[3] = new Coordinate(10.7,10.9); + coords[4] = new Coordinate(10.7,10.4); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -529,13 +527,13 @@ public void testPolygonIntersectingDataOnlyAtBorderLine() { @Test public void testPolygonIntersectingDataCompletely() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,52.7); - coords[2]=new Coordinate(52.7,52.7); - coords[3]=new Coordinate(52.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,52.7); + coords[2] = new Coordinate(52.7,52.7); + coords[3] = new Coordinate(52.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -559,13 +557,13 @@ public void testPolygonIntersectingDataCompletely() { @Test public void testPolygonNotIntersectingData() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(48,49); - coords[1]=new Coordinate(48 ,50); - coords[2]=new Coordinate(49,50); - coords[3]=new Coordinate(49,49); - coords[4]=new Coordinate(48,49); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(48,49); + coords[1] = new Coordinate(48,50); + coords[2] = new Coordinate(49,50); + coords[3] = new Coordinate(49,49); + coords[4] = new Coordinate(48,49); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List resultPoly = (new CellIterator( @@ -612,13 +610,13 @@ public void testNodeChangeOutsideBbox() { @Test public void testPolygonIntersectingDataCompletelyTimeIntervalAfterChanges() { - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,52.7); - coords[2]=new Coordinate(52.7,52.7); - coords[3]=new Coordinate(52.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,52.7); + coords[2] = new Coordinate(52.7,52.7); + coords[3] = new Coordinate(52.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -715,13 +713,13 @@ public void testSelfIntersectingPolygonClipped() { // Polygon with self crossing way // partly intersected by bbox polygon // happy if it works without crashing - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(7.31,1.0); - coords[1]=new Coordinate(7.335,1.0); - coords[2]=new Coordinate(7.335,2.0); - coords[3]=new Coordinate(7.31,2.0); - coords[4]=new Coordinate(7.31,1.0); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(7.31,1.0); + coords[1] = new Coordinate(7.335,1.0); + coords[2] = new Coordinate(7.335,2.0); + coords[3] = new Coordinate(7.31,2.0); + coords[4] = new Coordinate(7.31,1.0); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -743,7 +741,8 @@ public void testSelfIntersectingPolygonClipped() { @Test public void testMembersDisappear() { - // relation with one way member(nodes of way have changes in 2009 and 2011), in version 2 member is deleted + // relation with one way member(nodes of way have changes in 2009 and 2011), in version 2 member + // is deleted List result = (new CellIterator( new OSHDBTimestamps( "2000-01-01T00:00:00Z", @@ -805,14 +804,15 @@ public void testTimeIntervalAfterDeletionInCurrentVersion() { @Test public void testMembersDisappearClipped() { - // relation with one way member(nodes of way have changes in 2009 and 2011), in version 2 member is deleted - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,22.7); - coords[2]=new Coordinate(22.7,22.7); - coords[3]=new Coordinate(22.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + // relation with one way member(nodes of way have changes in 2009 and 2011), in version 2 member + // is deleted + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,22.7); + coords[2] = new Coordinate(22.7,22.7); + coords[3] = new Coordinate(22.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -836,13 +836,13 @@ public void testMembersDisappearClipped() { @Test public void testTimeIntervalAfterDeletionInVersion2Clipped() { // relation in second version visible = false, timeinterval includes version 3 - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,22.7); - coords[2]=new Coordinate(22.7,22.7); - coords[3]=new Coordinate(22.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,22.7); + coords[2] = new Coordinate(22.7,22.7); + coords[3] = new Coordinate(22.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -866,13 +866,13 @@ public void testTimeIntervalAfterDeletionInVersion2Clipped() { @Test public void testTimeIntervalAfterDeletionInCurrentVersionClipped() { // relation in first and third version visible = false, timeinterval includes version 3 - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(10.8,10.3); - coords[1]=new Coordinate(10.8 ,22.7); - coords[2]=new Coordinate(22.7,22.7); - coords[3]=new Coordinate(22.7,10.3); - coords[4]=new Coordinate(10.8,10.3); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(10.8,10.3); + coords[1] = new Coordinate(10.8,22.7); + coords[2] = new Coordinate(22.7,22.7); + coords[3] = new Coordinate(22.7,10.3); + coords[4] = new Coordinate(10.8,10.3); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -896,13 +896,13 @@ public void testTimeIntervalAfterDeletionInCurrentVersionClipped() { @Test public void testExcludingVersion2Clipped() { // relation in second version visible = false, timeinterval includes version 3 - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(7.31,1.0); - coords[1]=new Coordinate(7.335,1.0); - coords[2]=new Coordinate(7.335,2.0); - coords[3]=new Coordinate(7.31,2.0); - coords[4]=new Coordinate(7.31,1.0); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(7.31,1.0); + coords[1] = new Coordinate(7.335,1.0); + coords[2] = new Coordinate(7.335,2.0); + coords[3] = new Coordinate(7.31,2.0); + coords[4] = new Coordinate(7.31,1.0); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( @@ -914,7 +914,7 @@ public void testExcludingVersion2Clipped() { polygonFromCoordinates, areaDecider, oshEntity -> oshEntity.getId() == 500, - osmEntity -> !(osmEntity.getVersion()==2), + osmEntity -> !(osmEntity.getVersion() == 2), false )).iterateByTimestamps( oshdbDataGridCell @@ -926,13 +926,13 @@ public void testExcludingVersion2Clipped() { @Test public void testClippingPolygonIsVeryBig() { // relation with two way members(nodes of ways have changes in 2009 and 2011) - GeometryFactory geometryFactory = new GeometryFactory(); - Coordinate[] coords=new Coordinate[5]; - coords[0]=new Coordinate(-180,-90); - coords[1]=new Coordinate(180 ,-90); - coords[2]=new Coordinate(180,90); - coords[3]=new Coordinate(-180,90); - coords[4]=new Coordinate(-180,-90); + final GeometryFactory geometryFactory = new GeometryFactory(); + Coordinate[] coords = new Coordinate[5]; + coords[0] = new Coordinate(-180,-90); + coords[1] = new Coordinate(180,-90); + coords[2] = new Coordinate(180,90); + coords[3] = new Coordinate(-180,90); + coords[4] = new Coordinate(-180,-90); Polygon polygonFromCoordinates = geometryFactory.createPolygon(coords); List result = (new CellIterator( diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsWaysTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsWaysTest.java index 8ffe810dc..541c91c13 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsWaysTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsWaysTest.java @@ -1,5 +1,9 @@ package org.heigit.bigspatialdata.oshdb.util.celliterator; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.util.List; import java.util.stream.Collectors; @@ -17,10 +21,6 @@ import org.locationtech.jts.geom.LineString; import org.locationtech.jts.geom.Polygon; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - public class IterateByTimestampsWaysTest { private GridOSHWays oshdbDataGridCell; diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/helpers/GridOSHFactory.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/helpers/GridOSHFactory.java index b3e2951ab..9bff7263d 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/helpers/GridOSHFactory.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/helpers/GridOSHFactory.java @@ -37,15 +37,8 @@ public static GridOSHNodes getGridOSHNodes(OSMXmlReader osmXmlReader) throws IOE return getGridOSHNodes(osmXmlReader, -1, -1); } - public static GridOSHWays getGridOSHWays(OSMXmlReader osmXmlReader) throws IOException { - return getGridOSHWays(osmXmlReader, -1, -1); - } - - public static GridOSHRelations getGridOSHRelations(OSMXmlReader osmXmlReader) throws IOException { - return getGridOSHRelations(osmXmlReader, -1, -1); - } - - public static GridOSHNodes getGridOSHNodes(OSMXmlReader osmXmlReader, int cellZoom, long cellId) throws IOException { + public static GridOSHNodes getGridOSHNodes(OSMXmlReader osmXmlReader, int cellZoom, long cellId) + throws IOException { GridOSHNodes oshdbDataGridCellNodes; List oshNodes = new ArrayList<>(); for (Entry> entry : osmXmlReader.nodes().asMap().entrySet()) { @@ -57,7 +50,12 @@ public static GridOSHNodes getGridOSHNodes(OSMXmlReader osmXmlReader, int cellZo return oshdbDataGridCellNodes; } - public static GridOSHWays getGridOSHWays(OSMXmlReader osmXmlReader, int cellZoom, long cellId) throws IOException { + public static GridOSHWays getGridOSHWays(OSMXmlReader osmXmlReader) throws IOException { + return getGridOSHWays(osmXmlReader, -1, -1); + } + + public static GridOSHWays getGridOSHWays(OSMXmlReader osmXmlReader, int cellZoom, long cellId) + throws IOException { GridOSHWays oshdbDataGridCellWays; Map oshNodes = getOSHNodes(osmXmlReader); List oshWays = new ArrayList<>(); @@ -73,7 +71,12 @@ public static GridOSHWays getGridOSHWays(OSMXmlReader osmXmlReader, int cellZoom return oshdbDataGridCellWays; } - public static GridOSHRelations getGridOSHRelations(OSMXmlReader osmXmlReader, int cellZoom, long cellId) throws IOException { + public static GridOSHRelations getGridOSHRelations(OSMXmlReader osmXmlReader) throws IOException { + return getGridOSHRelations(osmXmlReader, -1, -1); + } + + public static GridOSHRelations getGridOSHRelations(OSMXmlReader osmXmlReader, int cellZoom, + long cellId) throws IOException { Map oshNodes = getOSHNodes(osmXmlReader); Map oshWays = getOSHWays(osmXmlReader); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/GeoTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/GeoTest.java index b3ab49e2c..104db5c60 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/GeoTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/GeoTest.java @@ -1,5 +1,7 @@ package org.heigit.bigspatialdata.oshdb.util.geometry; +import static org.junit.Assert.assertEquals; + import org.junit.Test; import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.Geometry; @@ -12,12 +14,10 @@ import org.locationtech.jts.geom.Point; import org.locationtech.jts.geom.Polygon; -import static org.junit.Assert.assertEquals; - public class GeoTest { private final GeometryFactory gf = new GeometryFactory(); - private Coordinate[] constructCoordinates(double ...coordValues) { + private Coordinate[] constructCoordinates(double...coordValues) { Coordinate[] coords = new Coordinate[coordValues.length / 2]; for (int i = 0; i < coordValues.length / 2; i++) { coords[i] = new Coordinate(coordValues[i * 2], coordValues[i * 2 + 1]); @@ -25,7 +25,7 @@ private Coordinate[] constructCoordinates(double ...coordValues) { return coords; } - private LinearRing constructRing(double ...coordValues) { + private LinearRing constructRing(double...coordValues) { return gf.createLinearRing(constructCoordinates(coordValues)); } diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/OSHDBGeometryBuilderTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/OSHDBGeometryBuilderTest.java index 801c63e36..20567c8bb 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/OSHDBGeometryBuilderTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/OSHDBGeometryBuilderTest.java @@ -1,5 +1,8 @@ package org.heigit.bigspatialdata.oshdb.util.geometry; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import org.heigit.bigspatialdata.oshdb.osm.OSMEntity; import org.heigit.bigspatialdata.oshdb.util.OSHDBBoundingBox; import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp; @@ -20,13 +23,10 @@ import org.locationtech.jts.io.ParseException; import org.locationtech.jts.io.WKTReader; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public class OSHDBGeometryBuilderTest { private final OSMXmlReader testData = new OSMXmlReader(); - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public OSHDBGeometryBuilderTest() { testData.add("./src/test/resources/geometryBuilder.osh"); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxInPolygonTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxInPolygonTest.java index d03256f6d..ad04664c0 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxInPolygonTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxInPolygonTest.java @@ -1,11 +1,13 @@ package org.heigit.bigspatialdata.oshdb.util.geometry.fip; -import org.locationtech.jts.geom.*; +import static org.junit.Assert.assertEquals; + import org.heigit.bigspatialdata.oshdb.util.OSHDBBoundingBox; import org.heigit.bigspatialdata.oshdb.util.geometry.OSHDBGeometryBuilder; import org.junit.Test; - -import static org.junit.Assert.assertEquals; +import org.locationtech.jts.geom.GeometryFactory; +import org.locationtech.jts.geom.MultiPolygon; +import org.locationtech.jts.geom.Polygon; public class FastBboxInPolygonTest { diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxOutsidePolygonTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxOutsidePolygonTest.java index 4c3c1858c..8b834e531 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxOutsidePolygonTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxOutsidePolygonTest.java @@ -2,10 +2,10 @@ import static org.junit.Assert.assertEquals; -import org.locationtech.jts.geom.MultiPolygon; -import org.locationtech.jts.geom.Polygon; import org.heigit.bigspatialdata.oshdb.util.OSHDBBoundingBox; import org.junit.Test; +import org.locationtech.jts.geom.MultiPolygon; +import org.locationtech.jts.geom.Polygon; public class FastBboxOutsidePolygonTest { diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPointInPolygonTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPointInPolygonTest.java index 90cf4bb61..ca42108ea 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPointInPolygonTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPointInPolygonTest.java @@ -2,8 +2,12 @@ import static org.junit.Assert.assertEquals; -import org.locationtech.jts.geom.*; import org.junit.Test; +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.GeometryFactory; +import org.locationtech.jts.geom.LinearRing; +import org.locationtech.jts.geom.MultiPolygon; +import org.locationtech.jts.geom.Polygon; public class FastPointInPolygonTest { @@ -11,18 +15,18 @@ public class FastPointInPolygonTest { * @return a reversed "Σ"-shaped concave polygon */ public static Polygon createPolygon() { - GeometryFactory gf = new GeometryFactory(); + final GeometryFactory gf = new GeometryFactory(); Coordinate[] coordinates = new Coordinate[100]; coordinates[0] = new Coordinate(0,0); coordinates[1] = new Coordinate(1,1); coordinates[2] = new Coordinate(-1,1); - for (int i=3; i<=96; i++) { - coordinates[i] = new Coordinate(-1.0, 1.0 - 2.0*(i-2)/95); + for (int i = 3; i <= 96; i++) { + coordinates[i] = new Coordinate(-1.0, 1.0 - 2.0 * (i - 2) / 95); } coordinates[97] = new Coordinate(-1,-1); coordinates[98] = new Coordinate(1,-1); coordinates[99] = new Coordinate(0,0); - LinearRing linear = new GeometryFactory().createLinearRing(coordinates); + LinearRing linear = gf.createLinearRing(coordinates); return new Polygon(linear, null, gf); } @@ -30,21 +34,21 @@ public static Polygon createPolygon() { * @return a square with a central square hole */ public static Polygon createPolygonWithHole() { - GeometryFactory gf = new GeometryFactory(); + final GeometryFactory gf = new GeometryFactory(); Coordinate[] coordinates1 = new Coordinate[5]; coordinates1[0] = new Coordinate(4,-1); coordinates1[1] = new Coordinate(4,1); coordinates1[2] = new Coordinate(2,1); coordinates1[3] = new Coordinate(2,-1); coordinates1[4] = new Coordinate(4,-1); - LinearRing linear1 = new GeometryFactory().createLinearRing(coordinates1); + final LinearRing linear1 = gf.createLinearRing(coordinates1); Coordinate[] coordinates2 = new Coordinate[5]; coordinates2[0] = new Coordinate(3.5,-0.5); coordinates2[1] = new Coordinate(3.5,0.5); coordinates2[2] = new Coordinate(2.5,0.5); coordinates2[3] = new Coordinate(2.5,-0.5); coordinates2[4] = new Coordinate(3.5,-0.5); - LinearRing linear2 = new GeometryFactory().createLinearRing(coordinates2); + final LinearRing linear2 = gf.createLinearRing(coordinates2); return new Polygon(linear1, new LinearRing[] { linear2 }, gf); } diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPolygonOperationsTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPolygonOperationsTest.java index aaa29430d..c03d077b5 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPolygonOperationsTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPolygonOperationsTest.java @@ -3,14 +3,12 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import org.junit.Test; import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.Geometry; -import org.locationtech.jts.geom.GeometryCollection; import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.Polygon; -import org.junit.Test; import org.locationtech.jts.io.ParseException; import org.locationtech.jts.io.WKTReader; @@ -40,11 +38,36 @@ public void testNullGeometryPolygon() { public void testBug206() throws ParseException { // see https://github.com/GIScience/oshdb/pull/204 - String polyWkt = "POLYGON ((-0.0473915 51.5539955,-0.0473872 51.5540543,-0.0473811 51.554121,-0.0473792 51.5541494,-0.0473193 51.5541485,-0.047305 51.5540903,-0.0472924 51.5540904,-0.0472852 51.5540674,-0.0472735 51.5540681,-0.0472692 51.5540517,-0.0472852 51.5540499,-0.0472602 51.5539917,-0.0472317 51.553925,-0.0472157 51.5539254,-0.0472097 51.5539106,-0.0473992 51.5538913,-0.0474735 51.5538845,-0.0475498 51.5538774,-0.0476179 51.5538712,-0.0476923 51.5538643,-0.0476923 51.5538575,-0.0477741 51.5538544,-0.0478501 51.5538516,-0.0479217 51.553849,-0.0479986 51.5538462,-0.0480796 51.5538432,-0.0481503 51.5538406,-0.0482264 51.5538378,-0.0482708 51.5538377,-0.0483561 51.5538358,-0.0484275 51.5538343,-0.0485046 51.5538325,-0.0485294 51.553832,-0.0485255 51.5539171,-0.0485813 51.5539157,-0.0485787 51.5539268,-0.0485505 51.5540481,-0.048532 51.5540479,-0.0485309 51.5539901,-0.0484762 51.5539897,-0.0484784 51.5540545,-0.0484507 51.5540541,-0.0484187 51.5540536,-0.0484198 51.5539893,-0.0483923 51.5539892,-0.0483925 51.5539796,-0.0483729 51.5539795,-0.048362 51.5539794,-0.0483618 51.553989,-0.0483251 51.5539888,-0.0483241 51.5540522,-0.0482959 51.5540518,-0.0482676 51.5540514,-0.0482697 51.5539916,-0.0482366 51.5539911,-0.0482369 51.5539847,-0.0482236 51.5539846,-0.0482067 51.5539843,-0.0482064 51.5539907,-0.0481825 51.5539904,-0.0481803 51.5540561,-0.0481466 51.5540562,-0.0481136 51.5540562,-0.048115 51.5539953,-0.0480721 51.5539945,-0.048072 51.5540025,-0.0480546 51.5540021,-0.0480539 51.5540142,-0.0480194 51.5540138,-0.048018 51.5540561,-0.04799 51.5540558,-0.0479623 51.5540556,-0.047964 51.5540149,-0.0479185 51.5540142,-0.0478768 51.5540135,-0.047875 51.5540547,-0.0478614 51.5540546,-0.0478616 51.5540458,-0.0478423 51.5540457,-0.0478439 51.554006,-0.0477667 51.5540059,-0.0476868 51.5540057,-0.0476872 51.5539952,-0.047616 51.5539953,-0.0475449 51.5539954,-0.0474682 51.5539954,-0.0473915 51.5539955))"; + String polyWkt = "POLYGON ((-0.0473915 51.5539955,-0.0473872 51.5540543,-0.0473811 51.554121," + + "-0.0473792 51.5541494,-0.0473193 51.5541485,-0.047305 51.5540903,-0.0472924 51.5540904," + + "-0.0472852 51.5540674,-0.0472735 51.5540681,-0.0472692 51.5540517,-0.0472852 51.5540499," + + "-0.0472602 51.5539917,-0.0472317 51.553925,-0.0472157 51.5539254,-0.0472097 51.5539106," + + "-0.0473992 51.5538913,-0.0474735 51.5538845,-0.0475498 51.5538774,-0.0476179 51.5538712," + + "-0.0476923 51.5538643,-0.0476923 51.5538575,-0.0477741 51.5538544,-0.0478501 51.5538516," + + "-0.0479217 51.553849,-0.0479986 51.5538462,-0.0480796 51.5538432,-0.0481503 51.5538406," + + "-0.0482264 51.5538378,-0.0482708 51.5538377,-0.0483561 51.5538358,-0.0484275 51.5538343," + + "-0.0485046 51.5538325,-0.0485294 51.553832,-0.0485255 51.5539171,-0.0485813 51.5539157," + + "-0.0485787 51.5539268,-0.0485505 51.5540481,-0.048532 51.5540479,-0.0485309 51.5539901," + + "-0.0484762 51.5539897,-0.0484784 51.5540545,-0.0484507 51.5540541,-0.0484187 51.5540536," + + "-0.0484198 51.5539893,-0.0483923 51.5539892,-0.0483925 51.5539796,-0.0483729 51.5539795," + + "-0.048362 51.5539794,-0.0483618 51.553989,-0.0483251 51.5539888,-0.0483241 51.5540522," + + "-0.0482959 51.5540518,-0.0482676 51.5540514,-0.0482697 51.5539916,-0.0482366 51.5539911," + + "-0.0482369 51.5539847,-0.0482236 51.5539846,-0.0482067 51.5539843,-0.0482064 51.5539907," + + "-0.0481825 51.5539904,-0.0481803 51.5540561,-0.0481466 51.5540562,-0.0481136 51.5540562," + + "-0.048115 51.5539953,-0.0480721 51.5539945,-0.048072 51.5540025,-0.0480546 51.5540021," + + "-0.0480539 51.5540142,-0.0480194 51.5540138,-0.048018 51.5540561,-0.04799 51.5540558," + + "-0.0479623 51.5540556,-0.047964 51.5540149,-0.0479185 51.5540142,-0.0478768 51.5540135," + + "-0.047875 51.5540547,-0.0478614 51.5540546,-0.0478616 51.5540458,-0.0478423 51.5540457," + + "-0.0478439 51.554006,-0.0477667 51.5540059,-0.0476868 51.5540057,-0.0476872 51.5539952," + + "-0.047616 51.5539953,-0.0475449 51.5539954,-0.0474682 51.5539954,-0.0473915 51.5539955)" + + ")"; Polygon poly = (Polygon) (new WKTReader()).read(polyWkt); FastPolygonOperations pop = new FastPolygonOperations(poly); - String testWkt = "POLYGON ((-0.0478421 51.5540544,-0.0478399 51.5541248,-0.0478499 51.5541249,-0.0478549 51.5541307,-0.0478795 51.5541313,-0.0478858 51.5541252,-0.0479136 51.5541254,-0.0479185 51.5540142,-0.0478768 51.5540135,-0.047875 51.5540547,-0.0478614 51.5540546,-0.0478616 51.5540458,-0.0478423 51.5540457,-0.0478421 51.5540544))"; + String testWkt = "POLYGON ((-0.0478421 51.5540544,-0.0478399 51.5541248,-0.0478499 51.5541249," + + "-0.0478549 51.5541307,-0.0478795 51.5541313,-0.0478858 51.5541252,-0.0479136 51.5541254," + + "-0.0479185 51.5540142,-0.0478768 51.5540135,-0.047875 51.5540547,-0.0478614 51.5540546," + + "-0.0478616 51.5540458,-0.0478423 51.5540457,-0.0478421 51.5540544))"; Geometry test = (new WKTReader()).read(testWkt); assertNotNull(pop.intersection(test)); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/helpers/FakeTagInterpreter.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/helpers/FakeTagInterpreter.java index 9aadb184c..b5f616e44 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/helpers/FakeTagInterpreter.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/helpers/FakeTagInterpreter.java @@ -7,15 +7,32 @@ public abstract class FakeTagInterpreter implements TagInterpreter { @Override - public boolean isArea(OSMEntity entity) { return false; } + public boolean isArea(OSMEntity entity) { + return false; + } + @Override - public boolean isLine(OSMEntity entity) { return false; } + public boolean isLine(OSMEntity entity) { + return false; + } + @Override - public boolean hasInterestingTagKey(OSMEntity osm) { return false; } + public boolean hasInterestingTagKey(OSMEntity osm) { + return false; + } + @Override - public boolean isMultipolygonOuterMember(OSMMember osmMember) { return false; } + public boolean isMultipolygonOuterMember(OSMMember osmMember) { + return false; + } + @Override - public boolean isMultipolygonInnerMember(OSMMember osmMember) { return false; } + public boolean isMultipolygonInnerMember(OSMMember osmMember) { + return false; + } + @Override - public boolean isOldStyleMultipolygon(OSMRelation osmRelation) { return false; } + public boolean isOldStyleMultipolygon(OSMRelation osmRelation) { + return false; + } } diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/helpers/OSMXmlReaderTagInterpreter.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/helpers/OSMXmlReaderTagInterpreter.java index 928d200c8..1bc8a90c7 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/helpers/OSMXmlReaderTagInterpreter.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/helpers/OSMXmlReaderTagInterpreter.java @@ -21,7 +21,8 @@ public OSMXmlReaderTagInterpreter(OSMXmlReader osmXmlReader) { area = osmXmlReader.keys().getOrDefault("area", -1); areaYes = area == -1 ? -1 : osmXmlReader.keyValues().get(area).getOrDefault("yes", -1); type = osmXmlReader.keys().getOrDefault("type", -1); - typeMultipolygon = type == -1 ? -1 : osmXmlReader.keyValues().get(type).getOrDefault("multipolygon", -1); + typeMultipolygon = type == -1 ? -1 : osmXmlReader.keyValues().get(type) + .getOrDefault("multipolygon", -1); emptyRole = osmXmlReader.roles().getOrDefault("", -1); outer = osmXmlReader.roles().getOrDefault("outer", -1); inner = osmXmlReader.roles().getOrDefault("inner", -1); @@ -31,8 +32,8 @@ public OSMXmlReaderTagInterpreter(OSMXmlReader osmXmlReader) { public boolean isArea(OSMEntity e) { if (e instanceof OSMWay) { OSMMember[] nds = ((OSMWay) e).getRefs(); - return nds.length >= 4 && nds[0].getId() == nds[nds.length - 1].getId() && - e.hasTagValue(area, areaYes); + return nds.length >= 4 && nds[0].getId() == nds[nds.length - 1].getId() + && e.hasTagValue(area, areaYes); } if (e instanceof OSMRelation) { return e.hasTagValue(type, typeMultipolygon); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/incomplete/OSHDBGeometryBuilderTestPolygonIncompleteDataTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/incomplete/OSHDBGeometryBuilderTestPolygonIncompleteDataTest.java index c167462ba..778fda7ad 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/incomplete/OSHDBGeometryBuilderTestPolygonIncompleteDataTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/incomplete/OSHDBGeometryBuilderTestPolygonIncompleteDataTest.java @@ -1,5 +1,9 @@ package org.heigit.bigspatialdata.oshdb.util.geometry.incomplete; +import static junit.framework.TestCase.fail; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import org.heigit.bigspatialdata.oshdb.osm.OSMEntity; import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp; import org.heigit.bigspatialdata.oshdb.util.geometry.OSHDBGeometryBuilder; @@ -13,16 +17,12 @@ import org.locationtech.jts.io.ParseException; import org.locationtech.jts.io.WKTReader; -import static junit.framework.TestCase.fail; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public class OSHDBGeometryBuilderTestPolygonIncompleteDataTest { private final OSMXmlReader testData = new OSMXmlReader(); TagInterpreter areaDecider; private final OSHDBTimestamp timestamp = TimestampParser.toOSHDBTimestamp("2014-01-01T00:00:00Z"); - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public OSHDBGeometryBuilderTestPolygonIncompleteDataTest() { testData.add("./src/test/resources/incomplete-osm/polygon.osm"); @@ -62,7 +62,8 @@ public void testWayNotExistent() throws ParseException { // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( - "MULTIPOLYGON(((7.31 1.04, 7.33 1.05, 7.33 1.04, 7.32 1.04, 7.31 1.01,7.31 1.01,7.31 1.04)))" + "MULTIPOLYGON(((7.31 1.04, 7.33 1.05, 7.33 1.04, 7.32 1.04, 7.31 1.01,7.31 1.01," + + "7.31 1.04)))" ); Geometry intersection = result.intersection(expectedPolygon); assertEquals(expectedPolygon.getArea(), intersection.getArea(), DELTA); @@ -75,8 +76,7 @@ public void testAllNodesOfWayNotExistent() { Geometry result1 = null; try { result1 = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/incomplete/OSHDBGeometryBuilderTestWayIncompleteDataTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/incomplete/OSHDBGeometryBuilderTestWayIncompleteDataTest.java index dc38561bd..2e33b2abe 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/incomplete/OSHDBGeometryBuilderTestWayIncompleteDataTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/incomplete/OSHDBGeometryBuilderTestWayIncompleteDataTest.java @@ -1,5 +1,8 @@ package org.heigit.bigspatialdata.oshdb.util.geometry.incomplete; +import static junit.framework.TestCase.fail; +import static org.junit.Assert.assertTrue; + import org.heigit.bigspatialdata.oshdb.osm.OSMEntity; import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp; import org.heigit.bigspatialdata.oshdb.util.geometry.OSHDBGeometryBuilder; @@ -11,15 +14,12 @@ import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.LineString; -import static junit.framework.TestCase.fail; -import static org.junit.Assert.assertTrue; - public class OSHDBGeometryBuilderTestWayIncompleteDataTest { private final OSMXmlReader testData = new OSMXmlReader(); TagInterpreter areaDecider; private final OSHDBTimestamp timestamp = TimestampParser.toOSHDBTimestamp("2014-01-01T00:00:00Z"); - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public OSHDBGeometryBuilderTestWayIncompleteDataTest() { testData.add("./src/test/resources/incomplete-osm/way.osm"); @@ -34,8 +34,7 @@ public void testOneOfNodesNotExistent() { Geometry result1 = null; try { result1 = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -51,8 +50,7 @@ public void testWayAreaYes() { Geometry result1 = null; try { result1 = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -69,8 +67,7 @@ public void testAllNodesNotExistent() { try { result1 = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); assertTrue(result1.getCoordinates().length == 0); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataNodesTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataNodesTest.java index 134ee5ab5..85f13f45e 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataNodesTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataNodesTest.java @@ -1,5 +1,8 @@ package org.heigit.bigspatialdata.oshdb.util.geometry.osmhistorytestdata; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import org.heigit.bigspatialdata.oshdb.osm.OSMEntity; import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp; import org.heigit.bigspatialdata.oshdb.util.geometry.OSHDBGeometryBuilder; @@ -11,13 +14,10 @@ import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.Point; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public class OSHDBGeometryBuilderTestOsmHistoryTestDataNodesTest { private final OSMXmlReader testData = new OSMXmlReader(); TagInterpreter areaDecider; - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public OSHDBGeometryBuilderTestOsmHistoryTestDataNodesTest() { testData.add("./src/test/resources/different-timestamps/node.osm"); @@ -50,11 +50,11 @@ public void testGeometryChange() { assertEquals(1.425, ((Point) result3).getX(), DELTA); assertEquals(1.23, ((Point) result3).getY(), DELTA); // timestamp after newest timestamp - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2012-01-01T00:00:00Z"); - Geometry result_after = OSHDBGeometryBuilder.getGeometry(entity3, timestamp_after, areaDecider); - assertTrue(result_after instanceof Point); - assertEquals(1.425, ((Point) result_after).getX(), DELTA); - assertEquals(1.23, ((Point) result_after).getY(), DELTA); + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2012-01-01T00:00:00Z"); + Geometry resultAfter = OSHDBGeometryBuilder.getGeometry(entity3, timestampAfter, areaDecider); + assertTrue(resultAfter instanceof Point); + assertEquals(1.425, ((Point) resultAfter).getX(), DELTA); + assertEquals(1.23, ((Point) resultAfter).getY(), DELTA); } @Test(expected = AssertionError.class) @@ -62,8 +62,8 @@ public void testInvalidAccess() { // A single node, lat lon changed over time OSMEntity entity = testData.nodes().get(1L).get(0); // timestamp before oldest timestamp - OSHDBTimestamp timestamp_before = TimestampParser.toOSHDBTimestamp("2007-01-01T00:00:00Z"); - Geometry result_before = OSHDBGeometryBuilder.getGeometry(entity, timestamp_before, areaDecider); + OSHDBTimestamp timestampBefore = TimestampParser.toOSHDBTimestamp("2007-01-01T00:00:00Z"); + Geometry resultBefore = OSHDBGeometryBuilder.getGeometry(entity, timestampBefore, areaDecider); } @Test diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataRelationNotMultipolygonTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataRelationNotMultipolygonTest.java index 50f7060ea..684303a4e 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataRelationNotMultipolygonTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataRelationNotMultipolygonTest.java @@ -1,5 +1,9 @@ package org.heigit.bigspatialdata.oshdb.util.geometry.osmhistorytestdata; +import static junit.framework.TestCase.fail; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import org.heigit.bigspatialdata.oshdb.osm.OSMEntity; import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp; import org.heigit.bigspatialdata.oshdb.util.geometry.OSHDBGeometryBuilder; @@ -16,14 +20,10 @@ import org.locationtech.jts.geom.Polygonal; import org.locationtech.jts.io.ParseException; -import static junit.framework.TestCase.fail; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - public class OSHDBGeometryBuilderTestOsmHistoryTestDataRelationNotMultipolygonTest { private final OSMXmlReader testData = new OSMXmlReader(); TagInterpreter areaDecider; - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public OSHDBGeometryBuilderTestOsmHistoryTestDataRelationNotMultipolygonTest() { testData.add("./src/test/resources/different-timestamps/type-not-multipolygon.osm"); @@ -39,8 +39,7 @@ public void testGeometryChange() throws ParseException { Geometry result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, areaDecider); assertTrue(result instanceof GeometryCollection); assertTrue(result.isValid()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -51,8 +50,7 @@ public void testGeometryChange() throws ParseException { Geometry result1 = OSHDBGeometryBuilder.getGeometry(entity1, timestamp1, areaDecider); assertTrue(result1 instanceof GeometryCollection); assertTrue(result1.isValid()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -63,8 +61,7 @@ public void testGeometryChange() throws ParseException { Geometry result2 = OSHDBGeometryBuilder.getGeometry(entity1, timestamp2, areaDecider); assertTrue(result2 instanceof GeometryCollection || result2 instanceof Polygonal); assertTrue(result2.getNumGeometries() == 3); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -82,8 +79,7 @@ public void testVisibleChange() throws ParseException { assertTrue(result.getNumGeometries() == 2); assertTrue(result.getGeometryN(0) instanceof LineString); assertTrue(result.getGeometryN(1) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -93,8 +89,7 @@ public void testVisibleChange() throws ParseException { try { Geometry result1 = OSHDBGeometryBuilder.getGeometry(entity1, timestamp1, areaDecider); assertTrue(result1.isEmpty()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -108,8 +103,7 @@ public void testVisibleChange() throws ParseException { assertTrue(result2.getNumGeometries() == 2); assertTrue(result2.getGeometryN(0) instanceof LineString); assertTrue(result2.getGeometryN(1) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -126,8 +120,7 @@ public void testWaysNotExistent() { assertTrue(result instanceof GeometryCollection); assertTrue(result.isValid()); assertTrue(result.isEmpty()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -144,8 +137,7 @@ public void testTagChange() throws ParseException { assertTrue(result.isValid()); assertTrue(result.getNumGeometries() == 1); assertTrue(result.getGeometryN(0) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -158,8 +150,7 @@ public void testTagChange() throws ParseException { assertTrue(result1.isValid()); assertTrue(result1.getNumGeometries() == 1); assertTrue(result1.getGeometryN(0) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -172,8 +163,7 @@ public void testTagChange() throws ParseException { assertTrue(result2.isValid()); assertTrue(result2.getNumGeometries() == 1); assertTrue(result2.getGeometryN(0) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -191,8 +181,7 @@ public void testGeometryChangeOfNodeRefsInWays() throws ParseException { assertTrue(result.getNumGeometries() == 2); assertTrue(result.getGeometryN(0) instanceof LineString); assertTrue(result.getGeometryN(1) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -206,24 +195,22 @@ public void testGeometryChangeOfNodeRefsInWays() throws ParseException { assertTrue(result1.getNumGeometries() == 2); assertTrue(result1.getGeometryN(0) instanceof LineString); assertTrue(result1.getGeometryN(1) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } // version in between - OSMEntity entity_between = testData.relations().get(504L).get(0); - OSHDBTimestamp timestamp_between = TimestampParser.toOSHDBTimestamp("2012-02-01T00:00:00Z"); + OSMEntity entityBetween = testData.relations().get(504L).get(0); + OSHDBTimestamp timestampBetween = TimestampParser.toOSHDBTimestamp("2012-02-01T00:00:00Z"); try { - Geometry result_between = OSHDBGeometryBuilder - .getGeometry(entity_between, timestamp_between, areaDecider); - assertTrue(result_between instanceof GeometryCollection); - assertTrue(result_between.isValid()); - assertTrue(result_between.getNumGeometries() == 2); - assertTrue(result_between.getGeometryN(0) instanceof LineString); - assertTrue(result_between.getGeometryN(1) instanceof LineString); - } - catch(Exception e){ + Geometry resultBetween = OSHDBGeometryBuilder + .getGeometry(entityBetween, timestampBetween, areaDecider); + assertTrue(resultBetween instanceof GeometryCollection); + assertTrue(resultBetween.isValid()); + assertTrue(resultBetween.getNumGeometries() == 2); + assertTrue(resultBetween.getGeometryN(0) instanceof LineString); + assertTrue(resultBetween.getGeometryN(1) instanceof LineString); + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -240,23 +227,21 @@ public void testGeometryChangeOfNodeCoordinatesInWay() throws ParseException { assertTrue(result.isValid()); assertTrue(result.getNumGeometries() == 1); assertTrue(result.getGeometryN(0) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } // version after - OSMEntity entity_after = testData.relations().get(505L).get(0); - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2012-02-01T00:00:00Z"); + OSMEntity entityAfter = testData.relations().get(505L).get(0); + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2012-02-01T00:00:00Z"); try { - Geometry result_after = OSHDBGeometryBuilder - .getGeometry(entity_after, timestamp_after, areaDecider); - assertTrue(result_after instanceof GeometryCollection); - assertTrue(result_after.isValid()); - assertTrue(result_after.getNumGeometries() == 1); - assertTrue(result_after.getGeometryN(0) instanceof LineString); - } - catch(Exception e){ + Geometry resultAfter = OSHDBGeometryBuilder + .getGeometry(entityAfter, timestampAfter, areaDecider); + assertTrue(resultAfter instanceof GeometryCollection); + assertTrue(resultAfter.isValid()); + assertTrue(resultAfter.getNumGeometries() == 1); + assertTrue(resultAfter.getGeometryN(0) instanceof LineString); + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -275,24 +260,23 @@ public void testGeometryChangeOfNodeCoordinatesInRelationAndWay() throws ParseEx assertTrue(result.getGeometryN(0) instanceof Point); assertTrue(result.getGeometryN(1) instanceof Point); assertTrue(result.getGeometryN(2) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } // version after - OSMEntity entity_after = testData.relations().get(506L).get(0); - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2012-02-01T00:00:00Z"); + OSMEntity entityAfter = testData.relations().get(506L).get(0); + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2012-02-01T00:00:00Z"); try { - Geometry result_after = OSHDBGeometryBuilder.getGeometry(entity_after, timestamp_after, areaDecider); - assertTrue(result_after instanceof GeometryCollection); - assertTrue(result_after.isValid()); - assertTrue(result_after.getNumGeometries() == 3); - assertTrue(result_after.getGeometryN(0) instanceof Point); - assertTrue(result_after.getGeometryN(1) instanceof Point); - assertTrue(result_after.getGeometryN(2) instanceof LineString); - } - catch(Exception e){ + Geometry resultAfter = OSHDBGeometryBuilder.getGeometry(entityAfter, timestampAfter, + areaDecider); + assertTrue(resultAfter instanceof GeometryCollection); + assertTrue(resultAfter.isValid()); + assertTrue(resultAfter.getNumGeometries() == 3); + assertTrue(resultAfter.getGeometryN(0) instanceof Point); + assertTrue(resultAfter.getGeometryN(1) instanceof Point); + assertTrue(resultAfter.getGeometryN(2) instanceof LineString); + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -308,8 +292,7 @@ public void testGeometryCollection() { assertTrue(result instanceof GeometryCollection); assertTrue(result.getNumGeometries() == 6); assertFalse(result instanceof MultiPolygon); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -325,8 +308,7 @@ public void testNodesOfWaysNotExistent() { result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, areaDecider); assertTrue(result instanceof GeometryCollection); assertTrue(result.isValid()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -344,23 +326,22 @@ public void testVisibleChangeOfNodeInWay() throws ParseException { assertTrue(result.isValid()); assertTrue(result.getNumGeometries() == 1); assertTrue(result.getGeometryN(0) instanceof LineString); - } - catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } // version after - OSMEntity entity_after = testData.relations().get(509L).get(0); + OSMEntity entityAfter = testData.relations().get(509L).get(0); // timestamp where node 52 visible is true - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2014-02-01T00:00:00Z"); + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2014-02-01T00:00:00Z"); try { - Geometry result_after = OSHDBGeometryBuilder.getGeometry(entity_after, timestamp_after, areaDecider); - assertTrue(result_after instanceof GeometryCollection); - assertTrue(result_after.isValid()); - assertTrue(result_after.getNumGeometries() == 1); - assertTrue(result_after.getGeometryN(0) instanceof LineString); - } - catch (Exception e) { + Geometry resultAfter = OSHDBGeometryBuilder.getGeometry(entityAfter, timestampAfter, + areaDecider); + assertTrue(resultAfter instanceof GeometryCollection); + assertTrue(resultAfter.isValid()); + assertTrue(resultAfter.getNumGeometries() == 1); + assertTrue(resultAfter.getGeometryN(0) instanceof LineString); + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -377,23 +358,21 @@ public void testTagChangeOfNodeInWay() throws ParseException { assertTrue(result.isValid()); assertTrue(result.getNumGeometries() == 1); assertTrue(result.getGeometryN(0) instanceof LineString); - } - catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } // version after - OSMEntity entity_after = testData.relations().get(510L).get(0); - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2014-02-01T00:00:00Z"); + OSMEntity entityAfter = testData.relations().get(510L).get(0); + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2014-02-01T00:00:00Z"); try { - Geometry result_after = OSHDBGeometryBuilder - .getGeometry(entity_after, timestamp_after, areaDecider); - assertTrue(result_after instanceof GeometryCollection); - assertTrue(result_after.isValid()); - assertTrue(result_after.getNumGeometries() == 1); - assertTrue(result_after.getGeometryN(0) instanceof LineString); - } - catch (Exception e) { + Geometry resultAfter = OSHDBGeometryBuilder + .getGeometry(entityAfter, timestampAfter, areaDecider); + assertTrue(resultAfter instanceof GeometryCollection); + assertTrue(resultAfter.isValid()); + assertTrue(resultAfter.getNumGeometries() == 1); + assertTrue(resultAfter.getGeometryN(0) instanceof LineString); + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -410,20 +389,19 @@ public void testVisibleChangeOfWay() throws ParseException { assertTrue(result.isValid()); assertTrue(result.getNumGeometries() == 1); assertTrue(result.getGeometryN(0) instanceof LineString); - } - catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } // version after, visible false - OSMEntity entity_after = testData.relations().get(511L).get(0); - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2017-02-01T00:00:00Z"); + OSMEntity entityAfter = testData.relations().get(511L).get(0); + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2017-02-01T00:00:00Z"); try { - Geometry result_after = OSHDBGeometryBuilder.getGeometry(entity_after, timestamp_after, areaDecider); - assertTrue(result_after instanceof GeometryCollection); - assertTrue(result_after.isEmpty()); - } - catch (Exception e) { + Geometry resultAfter = OSHDBGeometryBuilder.getGeometry(entityAfter, timestampAfter, + areaDecider); + assertTrue(resultAfter instanceof GeometryCollection); + assertTrue(resultAfter.isEmpty()); + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -441,22 +419,21 @@ public void testVisibleChangeOfOneWayOfOuterRing() throws ParseException { assertTrue(result.getNumGeometries() == 2); assertTrue(result.getGeometryN(0) instanceof LineString); assertTrue(result.getGeometryN(1) instanceof LineString); - } - catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } // version after: way 120 does not exit any more - OSMEntity entity_after = testData.relations().get(512L).get(0); - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2018-02-01T00:00:00Z"); + OSMEntity entityAfter = testData.relations().get(512L).get(0); + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2018-02-01T00:00:00Z"); try { - Geometry result_after = OSHDBGeometryBuilder.getGeometry(entity_after, timestamp_after, areaDecider); - assertTrue(result_after instanceof GeometryCollection); - assertTrue(result_after.getNumGeometries() == 2); - assertTrue(result_after.getGeometryN(0) instanceof LineString - || result_after.getGeometryN(1) instanceof LineString); - } - catch(Exception e){ + Geometry resultAfter = OSHDBGeometryBuilder.getGeometry(entityAfter, timestampAfter, + areaDecider); + assertTrue(resultAfter instanceof GeometryCollection); + assertTrue(resultAfter.getNumGeometries() == 2); + assertTrue(resultAfter.getGeometryN(0) instanceof LineString + || resultAfter.getGeometryN(1) instanceof LineString); + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -473,8 +450,7 @@ public void testTagChangeOfWay() throws ParseException { assertTrue(result.isValid()); assertTrue(result.getNumGeometries() == 1); assertTrue(result.getGeometryN(0) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -487,8 +463,7 @@ public void testTagChangeOfWay() throws ParseException { assertTrue(result1.isValid()); assertTrue(result1.getNumGeometries() == 1); assertTrue(result1.getGeometryN(0) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -501,8 +476,7 @@ public void testTagChangeOfWay() throws ParseException { assertTrue(result2.isValid()); assertTrue(result2.getNumGeometries() == 1); assertTrue(result2.getGeometryN(0) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -520,10 +494,9 @@ public void testOneOfTwoPolygonDisappears() throws ParseException { assertTrue(result.getNumGeometries() == 2); assertTrue(result.getGeometryN(0) instanceof LineString); assertTrue(result.getGeometryN(1) instanceof LineString); - } - catch(Exception e){ - e.printStackTrace(); - fail("Should not have thrown any exception"); + } catch (Exception e) { + e.printStackTrace(); + fail("Should not have thrown any exception"); } // second version OSMEntity entity1 = testData.relations().get(514L).get(1); @@ -534,8 +507,7 @@ public void testOneOfTwoPolygonDisappears() throws ParseException { assertTrue(result1.isValid()); assertTrue(result1.getNumGeometries() == 1); assertTrue(result1.getGeometryN(0) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -552,11 +524,10 @@ public void testWaySplitUpInTwo() throws ParseException { assertTrue(result.isValid()); assertTrue(result.getNumGeometries() == 1); assertTrue(result.getGeometryN(0) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); - } + } // second version OSMEntity entity1 = testData.relations().get(515L).get(1); OSHDBTimestamp timestamp1 = entity1.getTimestamp(); @@ -567,8 +538,7 @@ public void testWaySplitUpInTwo() throws ParseException { assertTrue(result1.getNumGeometries() == 2); assertTrue(result1.getGeometryN(0) instanceof LineString); assertTrue(result1.getGeometryN(1) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -581,13 +551,12 @@ public void testRestrictionRoles() { OSHDBTimestamp timestamp1 = entity1.getTimestamp(); try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp1, areaDecider); - assertTrue(result instanceof GeometryCollection ); + assertTrue(result instanceof GeometryCollection); assertTrue(result.getNumGeometries() == 3); assertTrue(result.getGeometryN(0) instanceof LineString); assertTrue(result.getGeometryN(1) instanceof Point); assertTrue(result.getGeometryN(2) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -600,12 +569,11 @@ public void testRolesArePartAndOutline() { OSHDBTimestamp timestamp1 = entity1.getTimestamp(); try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp1, areaDecider); - assertTrue(result instanceof GeometryCollection ); + assertTrue(result instanceof GeometryCollection); assertTrue(result.getNumGeometries() == 2); assertTrue(result.getGeometryN(0) instanceof LineString); assertTrue(result.getGeometryN(1) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -614,13 +582,12 @@ public void testRolesArePartAndOutline() { OSHDBTimestamp timestamp2 = entity2.getTimestamp(); try { Geometry result2 = OSHDBGeometryBuilder.getGeometry(entity2, timestamp2, areaDecider); - assertTrue(result2 instanceof GeometryCollection ); + assertTrue(result2 instanceof GeometryCollection); assertTrue(result2.getNumGeometries() == 3); assertTrue(result2.getGeometryN(0) instanceof LineString); assertTrue(result2.getGeometryN(1) instanceof LineString); assertTrue(result2.getGeometryN(2) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataRelationTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataRelationTest.java index 2fe4c1e23..3861a4a71 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataRelationTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataRelationTest.java @@ -1,8 +1,12 @@ package org.heigit.bigspatialdata.oshdb.util.geometry.osmhistorytestdata; +import static junit.framework.TestCase.fail; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import org.heigit.bigspatialdata.oshdb.osm.OSMEntity; import org.heigit.bigspatialdata.oshdb.osm.OSMRelation; -import org.heigit.bigspatialdata.oshdb.osm.OSMWay; import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp; import org.heigit.bigspatialdata.oshdb.util.geometry.OSHDBGeometryBuilder; import org.heigit.bigspatialdata.oshdb.util.geometry.helpers.OSMXmlReaderTagInterpreter; @@ -18,16 +22,11 @@ import org.locationtech.jts.io.ParseException; import org.locationtech.jts.io.WKTReader; -import static junit.framework.TestCase.fail; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - public class OSHDBGeometryBuilderTestOsmHistoryTestDataRelationTest { private final OSMXmlReader testData = new OSMXmlReader(); TagInterpreter areaDecider; - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public OSHDBGeometryBuilderTestOsmHistoryTestDataRelationTest() { testData.add("./src/test/resources/different-timestamps/polygon.osm"); @@ -70,8 +69,7 @@ public void testGeometryChange() throws ParseException { Geometry result2 = OSHDBGeometryBuilder.getGeometry(entity1, timestamp2, areaDecider); assertTrue(result2 instanceof GeometryCollection || result2 instanceof Polygonal); assertTrue(result2.getNumGeometries() == 3); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -120,8 +118,7 @@ public void testWaysNotExistent() { try { OSHDBTimestamp timestamp = entity.getTimestamp(); result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -196,18 +193,19 @@ public void testGeometryChangeOfNodeRefsInWays() throws ParseException { Geometry intersection1 = result1.intersection(expectedPolygon1); assertEquals(expectedPolygon1.getArea(), intersection1.getArea(), DELTA); // version in between - OSMEntity entity_between = testData.relations().get(504L).get(0); - OSHDBTimestamp timestamp_between = TimestampParser.toOSHDBTimestamp("2012-02-01T00:00:00Z"); - Geometry result_between = OSHDBGeometryBuilder.getGeometry(entity_between, timestamp_between, areaDecider); - assertTrue(result_between instanceof Polygon); - assertTrue(result_between.isValid()); - assertEquals(10, result_between.getCoordinates().length); - Geometry expectedPolygon_between = (new WKTReader()).read( + OSMEntity entityBetween = testData.relations().get(504L).get(0); + OSHDBTimestamp timestampBetween = TimestampParser.toOSHDBTimestamp("2012-02-01T00:00:00Z"); + Geometry resultBetween = OSHDBGeometryBuilder.getGeometry(entityBetween, timestampBetween, + areaDecider); + assertTrue(resultBetween instanceof Polygon); + assertTrue(resultBetween.isValid()); + assertEquals(10, resultBetween.getCoordinates().length); + Geometry expectedPolygonBetween = (new WKTReader()).read( "MULTIPOLYGON(((7.24 1.04, 7.24 1.07, 7.31 1.07, 7.31 1.04 , 7.24 1.04)," + "(7.26 1.055, 7.265 1.06, 7.28 1.06,7.265 1.065, 7.26 1.055)))" ); - Geometry intersection_between = result_between.intersection(expectedPolygon_between); - assertEquals(expectedPolygon_between.getArea(), intersection_between.getArea(), DELTA); + Geometry intersectionBetween = resultBetween.intersection(expectedPolygonBetween); + assertEquals(expectedPolygonBetween.getArea(), intersectionBetween.getArea(), DELTA); } @Test @@ -225,17 +223,18 @@ public void testGeometryChangeOfNodeCoordinatesInWay() throws ParseException { Geometry intersection = result.intersection(expectedPolygon); assertEquals(expectedPolygon.getArea(), intersection.getArea(), DELTA); // version after - OSMEntity entity_after = testData.relations().get(505L).get(0); - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2012-02-01T00:00:00Z"); - Geometry result_after = OSHDBGeometryBuilder.getGeometry(entity_after, timestamp_after, areaDecider); - assertTrue(result_after instanceof Polygon); - assertTrue(result_after.isValid()); - assertEquals(5, result_after.getCoordinates().length); - Geometry expectedPolygon_after = (new WKTReader()).read( + OSMEntity entityAfter = testData.relations().get(505L).get(0); + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2012-02-01T00:00:00Z"); + Geometry resultAfter = OSHDBGeometryBuilder.getGeometry(entityAfter, timestampAfter, + areaDecider); + assertTrue(resultAfter instanceof Polygon); + assertTrue(resultAfter.isValid()); + assertEquals(5, resultAfter.getCoordinates().length); + Geometry expectedPolygonAfter = (new WKTReader()).read( "MULTIPOLYGON(((7.24 1.042, 7.242 1.07, 7.305 1.07, 7.295 1.039 , 7.24 1.042)))" ); - Geometry intersection_after = result_after.intersection(expectedPolygon_after); - assertEquals(expectedPolygon_after.getArea(), intersection_after.getArea(), DELTA); + Geometry intersectionAfter = resultAfter.intersection(expectedPolygonAfter); + assertEquals(expectedPolygonAfter.getArea(), intersectionAfter.getArea(), DELTA); } @Test @@ -253,17 +252,18 @@ public void testGeometryChangeOfNodeCoordinatesInRelationAndWay() throws ParseEx Geometry intersection = result.intersection(expectedPolygon); assertEquals(expectedPolygon.getArea(), intersection.getArea(), DELTA); // version after - OSMEntity entity_after = testData.relations().get(506L).get(0); - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2012-02-01T00:00:00Z"); - Geometry result_after = OSHDBGeometryBuilder.getGeometry(entity_after, timestamp_after, areaDecider); - assertTrue(result_after instanceof Polygon); - assertTrue(result_after.isValid()); - assertEquals(4, result_after.getCoordinates().length); - Geometry expectedPolygon_after = (new WKTReader()).read( + OSMEntity entityAfter = testData.relations().get(506L).get(0); + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2012-02-01T00:00:00Z"); + Geometry resultAfter = OSHDBGeometryBuilder.getGeometry(entityAfter, timestampAfter, + areaDecider); + assertTrue(resultAfter instanceof Polygon); + assertTrue(resultAfter.isValid()); + assertEquals(4, resultAfter.getCoordinates().length); + Geometry expectedPolygonAfter = (new WKTReader()).read( "MULTIPOLYGON(((7.24 1.042, 7.242 1.07, 7.295 1.039 , 7.24 1.042)))" ); - Geometry intersection_after = result_after.intersection(expectedPolygon_after); - assertEquals(expectedPolygon_after.getArea(), intersection_after.getArea(), DELTA); + Geometry intersectionAfter = resultAfter.intersection(expectedPolygonAfter); + assertEquals(expectedPolygonAfter.getArea(), intersectionAfter.getArea(), DELTA); } @Test @@ -277,8 +277,7 @@ public void testGeometryCollection() { assertTrue(result instanceof GeometryCollection); assertTrue(result.getNumGeometries() == 6); assertFalse(result instanceof MultiPolygon); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -292,8 +291,7 @@ public void testNodesOfWaysNotExistent() { try { OSHDBTimestamp timestamp = entity.getTimestamp(); result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -315,18 +313,19 @@ public void testVisibleChangeOfNodeInWay() throws ParseException { Geometry intersection = result.intersection(expectedPolygon); assertEquals(expectedPolygon.getArea(), intersection.getArea(), DELTA); // version after - OSMEntity entity_after = testData.relations().get(509L).get(0); + OSMEntity entityAfter = testData.relations().get(509L).get(0); // timestamp where node 52 visible is true - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2014-02-01T00:00:00Z"); - Geometry result_after = OSHDBGeometryBuilder.getGeometry(entity_after, timestamp_after, areaDecider); - assertTrue(result_after instanceof Polygon); - assertTrue(result_after.isValid()); - assertEquals(5, result_after.getCoordinates().length); - Geometry expectedPolygon_after = (new WKTReader()).read( + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2014-02-01T00:00:00Z"); + Geometry resultAfter = OSHDBGeometryBuilder.getGeometry(entityAfter, timestampAfter, + areaDecider); + assertTrue(resultAfter instanceof Polygon); + assertTrue(resultAfter.isValid()); + assertEquals(5, resultAfter.getCoordinates().length); + Geometry expectedPolygonAfter = (new WKTReader()).read( "MULTIPOLYGON(((7.303 1.042, 7.31 1.06, 7.32 1.07, 7.32 1.04, 7.303 1.042)))" ); - Geometry intersection_after = result_after.intersection(expectedPolygon_after); - assertEquals(expectedPolygon_after.getArea(), intersection_after.getArea(), DELTA); + Geometry intersectionAfter = resultAfter.intersection(expectedPolygonAfter); + assertEquals(expectedPolygonAfter.getArea(), intersectionAfter.getArea(), DELTA); } @Test @@ -344,17 +343,18 @@ public void testTagChangeOfNodeInWay() throws ParseException { Geometry intersection = result.intersection(expectedPolygon); assertEquals(expectedPolygon.getArea(), intersection.getArea(), DELTA); // version after - OSMEntity entity_after = testData.relations().get(510L).get(0); - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2014-02-01T00:00:00Z"); - Geometry result_after = OSHDBGeometryBuilder.getGeometry(entity_after, timestamp_after, areaDecider); - assertTrue(result_after instanceof Polygon); - assertTrue(result_after.isValid()); - assertEquals(4, result_after.getCoordinates().length); - Geometry expectedPolygon_after = (new WKTReader()).read( + OSMEntity entityAfter = testData.relations().get(510L).get(0); + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2014-02-01T00:00:00Z"); + Geometry resultAfter = OSHDBGeometryBuilder.getGeometry(entityAfter, timestampAfter, + areaDecider); + assertTrue(resultAfter instanceof Polygon); + assertTrue(resultAfter.isValid()); + assertEquals(4, resultAfter.getCoordinates().length); + Geometry expectedPolygonAfter = (new WKTReader()).read( "MULTIPOLYGON(((7.295 1.039, 1.43 1.24, 7.32 1.04, 7.295 1.039)))" ); - Geometry intersection_after = result_after.intersection(expectedPolygon_after); - assertEquals(expectedPolygon_after.getArea(), intersection_after.getArea(), DELTA); + Geometry intersectionAfter = resultAfter.intersection(expectedPolygonAfter); + assertEquals(expectedPolygonAfter.getArea(), intersectionAfter.getArea(), DELTA); } @Test @@ -372,10 +372,11 @@ public void testVisibleChangeOfWay() throws ParseException { Geometry intersection = result.intersection(expectedPolygon); assertEquals(expectedPolygon.getArea(), intersection.getArea(), DELTA); // version after, visible false - OSMEntity entity_after = testData.relations().get(511L).get(0); - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2017-02-01T00:00:00Z"); - Geometry result_after = OSHDBGeometryBuilder.getGeometry(entity_after, timestamp_after, areaDecider); - assertTrue(result_after.isEmpty()); + OSMEntity entityAfter = testData.relations().get(511L).get(0); + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2017-02-01T00:00:00Z"); + Geometry resultAfter = OSHDBGeometryBuilder.getGeometry(entityAfter, timestampAfter, + areaDecider); + assertTrue(resultAfter.isEmpty()); } @Test @@ -393,11 +394,12 @@ public void testVisibleChangeOfOneWayOfOuterRing() throws ParseException { Geometry intersection = result.intersection(expectedPolygon); assertEquals(expectedPolygon.getArea(), intersection.getArea(), DELTA); // version after: way 120 does not exit any more - OSMEntity entity_after = testData.relations().get(512L).get(0); - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2018-02-01T00:00:00Z"); - Geometry result_after = OSHDBGeometryBuilder.getGeometry(entity_after, timestamp_after, areaDecider); - assertTrue(result_after instanceof GeometryCollection); - assertTrue(result_after.getNumGeometries() == 2); + OSMEntity entityAfter = testData.relations().get(512L).get(0); + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2018-02-01T00:00:00Z"); + Geometry resultAfter = OSHDBGeometryBuilder.getGeometry(entityAfter, timestampAfter, + areaDecider); + assertTrue(resultAfter instanceof GeometryCollection); + assertTrue(resultAfter.getNumGeometries() == 2); } @Test diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataWaysTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataWaysTest.java index 4af195c89..af87e9244 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataWaysTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataWaysTest.java @@ -1,5 +1,8 @@ package org.heigit.bigspatialdata.oshdb.util.geometry.osmhistorytestdata; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import org.heigit.bigspatialdata.oshdb.osm.OSMEntity; import org.heigit.bigspatialdata.oshdb.osm.OSMWay; import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp; @@ -14,13 +17,10 @@ import org.locationtech.jts.geom.Polygon; import org.locationtech.jts.io.ParseException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public class OSHDBGeometryBuilderTestOsmHistoryTestDataWaysTest { private final OSMXmlReader testData = new OSMXmlReader(); TagInterpreter areaDecider; - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public OSHDBGeometryBuilderTestOsmHistoryTestDataWaysTest() { testData.add("./src/test/resources/different-timestamps/way.osm"); @@ -91,10 +91,11 @@ public void testGeometryChange() throws ParseException { assertEquals(1.43, (((LineString) result3).getCoordinateN(8)).x, DELTA); assertEquals(1.31, (((LineString) result3).getCoordinateN(8)).y, DELTA); // timestamp after last one - OSMEntity entity_after = testData.ways().get(100L).get(2); - OSHDBTimestamp timestamp_after = TimestampParser.toOSHDBTimestamp("2012-01-01T00:00:00Z"); - Geometry result_after = OSHDBGeometryBuilder.getGeometry(entity_after, timestamp_after, areaDecider); - assertTrue(result_after instanceof LineString); + OSMEntity entityAfter = testData.ways().get(100L).get(2); + OSHDBTimestamp timestampAfter = TimestampParser.toOSHDBTimestamp("2012-01-01T00:00:00Z"); + Geometry resultAfter = OSHDBGeometryBuilder.getGeometry(entityAfter, timestampAfter, + areaDecider); + assertTrue(resultAfter instanceof LineString); assertEquals(1.42, (((LineString) result3).getCoordinateN(0)).x, DELTA); assertEquals(1.22, (((LineString) result3).getCoordinateN(0)).y, DELTA); assertEquals(1.42, (((LineString) result3).getCoordinateN(1)).x, DELTA); @@ -141,15 +142,16 @@ public void testGeometryChangeOfNodeInWay() throws ParseException { assertEquals(1.43, (((LineString) result2).getCoordinateN(2)).x, DELTA); assertEquals(1.30, (((LineString) result2).getCoordinateN(2)).y, DELTA); // timestamp in between - OSHDBTimestamp timestamp_between = TimestampParser.toOSHDBTimestamp("2009-02-01T00:00:00Z"); - OSMEntity entity_between = testData.ways().get(101L).get(0); - Geometry result_between = OSHDBGeometryBuilder.getGeometry(entity_between, timestamp_between, areaDecider); - assertTrue(result_between instanceof LineString); - assertEquals(2,result_between.getNumPoints()); - assertEquals(1.42, (((LineString) result_between).getCoordinateN(0)).x, DELTA); - assertEquals(1.225, (((LineString) result_between).getCoordinateN(0)).y, DELTA); - assertEquals(1.445, (((LineString) result_between).getCoordinateN(1)).x, DELTA); - assertEquals(1.225, (((LineString) result_between).getCoordinateN(1)).y, DELTA); + OSHDBTimestamp timestampBetween = TimestampParser.toOSHDBTimestamp("2009-02-01T00:00:00Z"); + OSMEntity entityBetween = testData.ways().get(101L).get(0); + Geometry resultBetween = OSHDBGeometryBuilder.getGeometry(entityBetween, timestampBetween, + areaDecider); + assertTrue(resultBetween instanceof LineString); + assertEquals(2,resultBetween.getNumPoints()); + assertEquals(1.42, (((LineString) resultBetween).getCoordinateN(0)).x, DELTA); + assertEquals(1.225, (((LineString) resultBetween).getCoordinateN(0)).y, DELTA); + assertEquals(1.445, (((LineString) resultBetween).getCoordinateN(1)).x, DELTA); + assertEquals(1.225, (((LineString) resultBetween).getCoordinateN(1)).y, DELTA); } @Test @@ -239,6 +241,7 @@ public void testMultipleChangesOnNodesAndWays() throws ParseException { assertEquals(4, result4.getNumPoints()); } + // MULTIPOLYGON(((1.45 1.45,1.46 1.45,1.46 1.44,1.45 1.44))) @Test public void testPolygonAreaYesTagDisappears() throws ParseException { diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmtestdata/OSHDBGeometryBuilderTestOsmTestData1xxTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmtestdata/OSHDBGeometryBuilderTestOsmTestData1xxTest.java index c2f9f6400..8c7657884 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmtestdata/OSHDBGeometryBuilderTestOsmTestData1xxTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmtestdata/OSHDBGeometryBuilderTestOsmTestData1xxTest.java @@ -1,5 +1,11 @@ package org.heigit.bigspatialdata.oshdb.util.geometry.osmtestdata; +import static junit.framework.TestCase.fail; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + import org.heigit.bigspatialdata.oshdb.osm.OSMEntity; import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp; import org.heigit.bigspatialdata.oshdb.util.geometry.OSHDBGeometryBuilder; @@ -15,18 +21,12 @@ import org.locationtech.jts.geom.LineString; import org.locationtech.jts.geom.Point; -import static junit.framework.TestCase.fail; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - public class OSHDBGeometryBuilderTestOsmTestData1xxTest { private final OSMXmlReader testData = new OSMXmlReader(); TagInterpreter areaDecider; private final OSHDBTimestamp timestamp = TimestampParser.toOSHDBTimestamp("2014-01-01T00:00:00Z"); - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public OSHDBGeometryBuilderTestOsmTestData1xxTest() { testData.add("./src/test/resources/osm-testdata/all.osm"); @@ -86,7 +86,7 @@ public void test112() { assertTrue(result1 instanceof LineString); assertEquals(5, result1.getCoordinates().length); assertEquals( - ((LineString) result1).getCoordinateN(result1.getNumPoints()-1), + ((LineString) result1).getCoordinateN(result1.getNumPoints() - 1), ((LineString) result1).getCoordinateN(0) ); } @@ -114,7 +114,7 @@ public void test114() { assertTrue(result1 instanceof LineString); assertTrue(result2 instanceof LineString); assertEquals( - ((LineString) result1).getCoordinateN(result1.getNumPoints()-1), + ((LineString) result1).getCoordinateN(result1.getNumPoints() - 1), ((LineString) result2).getCoordinateN(0) ); } @@ -129,8 +129,8 @@ public void test115() { assertTrue(result1 instanceof LineString); assertTrue(result2 instanceof LineString); assertEquals( - ((LineString) result1).getCoordinateN(result1.getNumPoints()-1), - ((LineString) result2).getCoordinateN(result2.getNumPoints()-1) + ((LineString) result1).getCoordinateN(result1.getNumPoints() - 1), + ((LineString) result2).getCoordinateN(result2.getNumPoints() - 1) ); } @@ -150,15 +150,15 @@ public void test116() { int idx2 = result2.getNumPoints(); int idx3 = result3.getNumPoints(); assertEquals( - ((LineString) result3).getCoordinateN(idx3-1), + ((LineString) result3).getCoordinateN(idx3 - 1), ((LineString) result1).getCoordinateN(0) ); assertEquals( - ((LineString) result1).getCoordinateN(idx1-1), + ((LineString) result1).getCoordinateN(idx1 - 1), ((LineString) result2).getCoordinateN(0) ); assertEquals( - ((LineString) result2).getCoordinateN(idx2-1), + ((LineString) result2).getCoordinateN(idx2 - 1), ((LineString) result3).getCoordinateN(0) ); } @@ -169,8 +169,7 @@ public void test120() { OSMEntity entity1 = testData.ways().get(120800L).get(0); try { OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -182,8 +181,7 @@ public void test121() { OSMEntity entity1 = testData.ways().get(121800L).get(0); try { OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -195,8 +193,7 @@ public void test122() { OSMEntity entity1 = testData.ways().get(122800L).get(0); try { OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -208,8 +205,7 @@ public void test123() { OSMEntity entity1 = testData.ways().get(123800L).get(0); try { OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -221,8 +217,7 @@ public void test124() { OSMEntity entity1 = testData.ways().get(124800L).get(0); try { OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -238,8 +233,8 @@ public void test130() { assertTrue(result1 instanceof LineString); assertTrue(result2 instanceof LineString); assertTrue(result1.crosses(result2)); - for (int j = 0; j< result1.getLength();j++){ - for (int i = 0; i< result2.getLength();i++) { + for (int j = 0; j < result1.getLength();j++) { + for (int i = 0; i < result2.getLength();i++) { assertNotEquals(((LineString) result1).getCoordinateN(j), ((LineString) result2).getCoordinateN(i)); } @@ -256,13 +251,11 @@ public void test131() { assertTrue(result1 instanceof LineString); assertTrue(result2 instanceof LineString); assertTrue(result1.intersects(result2)); - for (int j = 0; j< result1.getLength();j++){ - for (int i = 0; i< result2.getLength();i++) { + for (int j = 0; j < result1.getLength();j++) { + for (int i = 0; i < result2.getLength();i++) { try { - ((LineString) result1).getCoordinateN(j).equals( - ((LineString) result2).getCoordinateN(i)); - } - catch(Exception e){ + ((LineString) result1).getCoordinateN(j).equals(((LineString) result2).getCoordinateN(i)); + } catch (Exception e) { e.printStackTrace(); fail("No common node"); } @@ -281,13 +274,12 @@ public void test132() { assertTrue(result2 instanceof LineString); assertTrue(result1.crosses(result2)); assertTrue(result1.intersects(result2)); - for (int j = 0; j< result1.getLength();j++){ - for (int i = 0; i< result2.getLength();i++) { + for (int j = 0; j < result1.getLength();j++) { + for (int i = 0; i < result2.getLength();i++) { try { ((LineString) result1).getCoordinateN(j).equals( ((LineString) result2).getCoordinateN(i)); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("No common node"); } @@ -301,9 +293,10 @@ public void test133() { OSMEntity entity1 = testData.ways().get(133800L).get(0); Geometry result1 = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); assertTrue(result1 instanceof LineString); - // If a LineString intersects like that, isSimple() will return false as self-intersection is not allowed for Simple Geometries. + // If a LineString intersects like that, isSimple() will return false as self-intersection is + // not allowed for Simple Geometries. assertFalse(result1.isSimple()); - // punkt mit punkt, linie bilden, crosses + // punkt mit punkt, linie bilden, crosses GeometryFactory geometryFactory = new GeometryFactory(); Coordinate[] xy1 = new Coordinate[]{(((LineString) result1).getCoordinateN(0)), (((LineString) result1).getCoordinateN(1))}; @@ -322,7 +315,7 @@ public void test134() { Geometry result1 = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); assertTrue(result1 instanceof LineString); assertFalse(result1.isSimple()); - // punkt mit punkt, linie bilden, crosses + // punkt mit punkt, linie bilden, crosses GeometryFactory geometryFactory = new GeometryFactory(); Coordinate[] xy1 = new Coordinate[]{(((LineString) result1).getCoordinateN(0)), (((LineString) result1).getCoordinateN(2))}; diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmtestdata/OSHDBGeometryBuilderTestOsmTestData3xxTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmtestdata/OSHDBGeometryBuilderTestOsmTestData3xxTest.java index b2caaea09..43cc59711 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmtestdata/OSHDBGeometryBuilderTestOsmTestData3xxTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmtestdata/OSHDBGeometryBuilderTestOsmTestData3xxTest.java @@ -1,5 +1,8 @@ package org.heigit.bigspatialdata.oshdb.util.geometry.osmtestdata; +import static junit.framework.TestCase.fail; +import static org.junit.Assert.assertTrue; + import org.heigit.bigspatialdata.oshdb.osm.OSMEntity; import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp; import org.heigit.bigspatialdata.oshdb.util.geometry.OSHDBGeometryBuilder; @@ -11,15 +14,12 @@ import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.Point; -import static junit.framework.TestCase.fail; -import static org.junit.Assert.assertTrue; - public class OSHDBGeometryBuilderTestOsmTestData3xxTest { private final OSMXmlReader testData = new OSMXmlReader(); TagInterpreter areaDecider; private final OSHDBTimestamp timestamp = TimestampParser.toOSHDBTimestamp("2014-01-01T00:00:00Z"); - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public OSHDBGeometryBuilderTestOsmTestData3xxTest() { testData.add("./src/test/resources/osm-testdata/all.osm"); @@ -32,68 +32,71 @@ public void test300() { OSMEntity entity = testData.nodes().get(200000L).get(0); Geometry result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, areaDecider); assertTrue(result instanceof Point); - Integer entity_uid = testData.nodes().get(200000L).get(0).getUserId(); - assertTrue(entity_uid instanceof Integer); + Integer entityUid = testData.nodes().get(200000L).get(0).getUserId(); + assertTrue(entityUid instanceof Integer); } + @Test public void test301() { // Empty username on node should not happen OSMEntity entity1 = testData.nodes().get(201000L).get(0); try { OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } } + @Test public void test302() { // No uid and no user name means user is anonymous // user name is not priority } + @Test public void test303() { // No uid and no user name means user is anonymous // user name is not priority } + @Test public void test304() { // negative user ids are not allowed (but -1 could have been meant as anonymous user) OSMEntity entity1 = testData.nodes().get(204000L).get(0); try { OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } } + @Test public void test305() { // uid < 0 and username is inconsistent and definitely wrong OSMEntity entity1 = testData.nodes().get(205000L).get(0); try { OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } } + @Test public void test306() { // 250 characters in username is okay // user name is not priority } + @Test public void test307() { // 260 characters in username is too long OSMEntity entity1 = testData.nodes().get(207000L).get(0); try { OSHDBGeometryBuilder.getGeometry(entity1, timestamp, areaDecider); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmtestdata/OSHDBGeometryBuilderTestOsmTestData7xxTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmtestdata/OSHDBGeometryBuilderTestOsmTestData7xxTest.java index d6280b47e..e53728f73 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmtestdata/OSHDBGeometryBuilderTestOsmTestData7xxTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmtestdata/OSHDBGeometryBuilderTestOsmTestData7xxTest.java @@ -27,7 +27,7 @@ public class OSHDBGeometryBuilderTestOsmTestData7xxTest { private final TagInterpreter tagInterpreter; private final OSHDBTimestamp timestamp = TimestampParser.toOSHDBTimestamp("2014-01-01T00:00:00Z"); - private final double DELTA = 1E-8; + private static final double DELTA = 1E-8; public OSHDBGeometryBuilderTestOsmTestData7xxTest() { testData.add("./src/test/resources/osm-testdata/all.osm"); @@ -89,7 +89,8 @@ public void test702() throws ParseException { // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( - "MULTIPOLYGON(((7.24 1.01,7.21 1.01,7.21 1.02,7.23 1.03,7.23 1.04,7.21 1.04,7.21 1.05,7.24 1.05,7.24 1.01)))" + "MULTIPOLYGON(((7.24 1.01,7.21 1.01,7.21 1.02,7.23 1.03,7.23 1.04,7.21 1.04,7.21 1.05," + + "7.24 1.05,7.24 1.01)))" ); Geometry intersection = result.intersection(expectedPolygon); assertEquals(1.0, expectedPolygon.getArea() / intersection.getArea(), DELTA); @@ -107,8 +108,8 @@ public void test703() throws ParseException { // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( - "MULTIPOLYGON(((7.34 1.01,7.31 1.01,7.31 1.02,7.33 1.03,7.33 1.04,7.32 1.04," - + "7.32 1.05,7.34 1.05,7.34 1.01)))" + "MULTIPOLYGON(((7.34 1.01,7.31 1.01,7.31 1.02,7.33 1.03,7.33 1.04,7.32 1.04,7.32 1.05," + + "7.34 1.05,7.34 1.01)))" ); Geometry intersection = result.intersection(expectedPolygon); assertEquals(1.0, expectedPolygon.getArea() / intersection.getArea(), DELTA); @@ -135,7 +136,8 @@ public void test704() throws ParseException { @Test public void test705() throws ParseException { - // Valid multipolygon relation with three ways making up an outer ring. Contains concave and convex parts. + // Valid multipolygon relation with three ways making up an outer ring. Contains concave and + // convex parts. OSMEntity entity = testData.relations().get(705900L).get(0); Geometry result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, tagInterpreter); assertTrue(result instanceof Polygon); @@ -154,7 +156,8 @@ public void test705() throws ParseException { @Test public void test706() throws ParseException { - // Valid multipolygon relation with three ways making up two outer rings that touch in one point. + // Valid multipolygon relation with three ways making up two outer rings that touch in one + // point. OSMEntity entity = testData.relations().get(706900L).get(0); Geometry result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, tagInterpreter); assertTrue(result instanceof MultiPolygon); @@ -212,7 +215,8 @@ public void test708() throws ParseException { @Test public void test709() throws ParseException { - // Valid multipolygon relation with four ways making up three outer rings touching in three points. + // Valid multipolygon relation with four ways making up three outer rings touching in three + // points. OSMEntity entity = testData.relations().get(709900L).get(0); Geometry result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, tagInterpreter); assertTrue(result instanceof MultiPolygon); @@ -232,14 +236,14 @@ public void test709() throws ParseException { @Test public void test710() { - // Invalid multipolygon relation: Three ways make up two outer rings, but the outer rings overlap. + // Invalid multipolygon relation: Three ways make up two outer rings, but the outer rings + // overlap. OSMEntity entity1 = testData.relations().get(710900L).get(0); try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); assertEquals(2, result.getNumGeometries()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -253,8 +257,7 @@ public void test711() { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); assertEquals(2, result.getNumGeometries()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -268,8 +271,7 @@ public void test714() { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); assertEquals(1, result.getNumGeometries()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -283,8 +285,7 @@ public void test715() { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); assertEquals(2, result.getNumGeometries()); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -294,7 +295,8 @@ public void test715() { @Test public void test720() throws ParseException { - // "Multipolygon with one outer and one inner ring. They are both oriented clockwise and have the correct role. + // "Multipolygon with one outer and one inner ring. They are both oriented clockwise and have + // the correct role. OSMEntity entity = testData.relations().get(720900L).get(0); Geometry result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, tagInterpreter); assertTrue(result instanceof Polygon); @@ -314,25 +316,29 @@ public void test720() throws ParseException { @Test public void test721() throws ParseException { - // "Multipolygon with one outer and one inner ring. They are both oriented anti-clockwise and have the correct role. + // "Multipolygon with one outer and one inner ring. They are both oriented anti-clockwise and + // have the correct role. // the same as test(720) apart from anti-clockwise } @Test public void test722() throws ParseException { - // Multipolygon with one outer and one inner ring. The outer ring is oriented clockwise, the inner anti-clockwise. They have both the correct role. + // Multipolygon with one outer and one inner ring. The outer ring is oriented clockwise, the + // inner anti-clockwise. They have both the correct role. // the same as test(720) apart from anti-clockwise } @Test public void test723() throws ParseException { - // Multipolygon with one outer and one inner ring. The outer ring is oriented anti-clockwise, the inner clockwise. They have both the correct role + // Multipolygon with one outer and one inner ring. The outer ring is oriented anti-clockwise, + // the inner clockwise. They have both the correct role. // the same as test(722) apart from anti-clockwise } @Test public void test724() throws ParseException { - // Multipolygon with one outer and one inner ring and a bit more complex geometry and nodes not in order + // Multipolygon with one outer and one inner ring and a bit more complex geometry and nodes not + // in order OSMEntity entity = testData.relations().get(724900L).get(0); Geometry result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, tagInterpreter); assertTrue(result instanceof Polygon); @@ -342,8 +348,8 @@ public void test724() throws ParseException { assertEquals(14, result.getCoordinates().length); // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( - "MULTIPOLYGON(((7.44 1.22,7.47 1.21,7.41 1.21,7.42 1.22,7.41 1.24,7.43 1.26,7.46 1.26,7.45 1.23,7.44 1.22)," - + "(7.43 1.22,7.42 1.24,7.44 1.25,7.45 1.24,7.43 1.22)))" + "MULTIPOLYGON(((7.44 1.22,7.47 1.21,7.41 1.21,7.42 1.22,7.41 1.24,7.43 1.26,7.46 1.26," + + "7.45 1.23,7.44 1.22),(7.43 1.22,7.42 1.24,7.44 1.25,7.45 1.24,7.43 1.22)))" ); Geometry intersection = result.intersection(expectedPolygon); assertEquals(1.0, expectedPolygon.getArea() / intersection.getArea(), DELTA); @@ -366,11 +372,13 @@ public void test725() throws ParseException { Geometry intersection = result.intersection(expectedPolygon); assertEquals(1.0, expectedPolygon.getArea() / intersection.getArea(), DELTA); } + @Test public void test726() throws ParseException { // Valid multipolygon with one inner and one outer // the same as test(724) apart from anti-clockwise } + @Test public void test727() throws ParseException { // Valid multipolygon with one inner and one outer @@ -389,7 +397,8 @@ public void test728() throws ParseException { assertEquals(9, result.getCoordinates().length); // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( - "MULTIPOLYGON(((7.85 1.23,7.86 1.22,7.87 1.22,7.87 1.24,7.86 1.25,7.83 1.25,7.82 1.26,7.84 1.23,7.85 1.23)))" + "MULTIPOLYGON(((7.85 1.23,7.86 1.22,7.87 1.22,7.87 1.24,7.86 1.25,7.83 1.25,7.82 1.26," + + "7.84 1.23,7.85 1.23)))" ); Geometry intersection = result.intersection(expectedPolygon); assertEquals(1.0, expectedPolygon.getArea() / intersection.getArea(), DELTA); @@ -440,7 +449,8 @@ public void test730() throws ParseException { @Test public void test731() throws ParseException { - // "Valid complex multipolygon with one outer and two inner rings made up of several ways. Roles are tagged correctly + // "Valid complex multipolygon with one outer and two inner rings made up of several ways. Roles + // are tagged correctly OSMEntity entity = testData.relations().get(731900L).get(0); Geometry result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, tagInterpreter); assertTrue(result instanceof Polygon); @@ -451,8 +461,9 @@ public void test731() throws ParseException { // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( "MULTIPOLYGON(((7.18 1.33,7.17 1.31,7.12 1.31,7.11 1.33,7.11 1.38,7.18 1.38,7.18 1.33)," - + "(7.17 1.32,7.12 1.32,7.12 1.36,7.13 1.36,7.13 1.33,7.16 1.33,7.16 1.34,7.17 1.35,7.17 1.32)," - + "(7.16 1.36,7.16 1.35,7.15 1.34,7.14 1.34,7.14 1.35,7.15 1.36,7.15 1.37,7.16 1.37,7.16 1.36)))" + + "(7.17 1.32,7.12 1.32,7.12 1.36,7.13 1.36,7.13 1.33,7.16 1.33,7.16 1.34,7.17 1.35," + + "7.17 1.32),(7.16 1.36,7.16 1.35,7.15 1.34,7.14 1.34,7.14 1.35,7.15 1.36,7.15 1.37," + + "7.16 1.37,7.16 1.36)))" ); Geometry intersection = result.intersection(expectedPolygon); assertEquals(1.0, expectedPolygon.getArea() / intersection.getArea(), DELTA); @@ -460,7 +471,8 @@ public void test731() throws ParseException { @Test public void test732() throws ParseException { - // Valid multipolygon with two outer rings, one containing an inner. One ring contains a node twice in succession in data.osm + // Valid multipolygon with two outer rings, one containing an inner. One ring contains a node + // twice in succession in data.osm OSMEntity entity = testData.relations().get(732900L).get(0); Geometry result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, tagInterpreter); assertTrue(result instanceof MultiPolygon); @@ -499,8 +511,7 @@ public void test740() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -513,8 +524,7 @@ public void test741() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -527,8 +537,7 @@ public void test742() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -548,8 +557,7 @@ public void test744() { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); assertTrue(result.getNumGeometries() == 2); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -563,8 +571,7 @@ public void test745() { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); assertTrue(result.getNumGeometries() == 1); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -578,8 +585,7 @@ public void test746() { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); assertTrue(result.getNumGeometries() == 2); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -592,8 +598,7 @@ public void test747() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -606,8 +611,7 @@ public void test748() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -620,8 +624,7 @@ public void test749() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -635,8 +638,9 @@ public void test750() throws ParseException { assertTrue(result instanceof Polygon); assertTrue(result.isValid()); assertEquals(1, ((Polygon)result).getNumInteriorRing()); - // In the result are 12 points, but it does not matter that we get 19, because the intersection is correct - // compare if coordinates of created points equals the coordinates of polygon + // In the result are 12 points, but it does not matter that we get 19, because the intersection + // is correct. + // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( "MULTIPOLYGON(((7.01 1.51,7.01 1.57,7.06 1.57,7.06 1.51,7.01 1.51)," + "(7.02 1.52,7.02 1.55,7.04 1.55,7.05 1.55,7.05 1.52,7.03 1.52,7.02 1.52)))" @@ -653,7 +657,8 @@ public void test751() throws ParseException { assertTrue(result instanceof Polygon); assertTrue(result.isValid()); assertEquals(1, ((Polygon)result).getNumInteriorRing()); - // In the result are 11 points, but it does not matter that we get 16, because the intersection is correct + // In the result are 11 points, but it does not matter that we get 16, because the intersection + // is correct. //assertEquals(16, result.getCoordinates().length); // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( @@ -671,8 +676,7 @@ public void test752() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -685,8 +689,7 @@ public void test753() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -699,8 +702,7 @@ public void test754() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -732,8 +734,7 @@ public void test756() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -746,8 +747,7 @@ public void test757() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -863,8 +863,7 @@ public void test768() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -884,8 +883,7 @@ public void test771() { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); assertTrue(result.getNumGeometries() == 2); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -918,8 +916,7 @@ public void test773() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -939,7 +936,8 @@ public void test774() throws ParseException { // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( "MULTIPOLYGON(((7.42 1.73,7.42 1.75,7.44 1.75,7.44 1.73,7.42 1.73))," - + "((7.44 1.75,7.44 1.76,7.47 1.76,7.47 1.72,7.44 1.72,7.44 1.73,7.45 1.73,7.45 1.75,7.44 1.75)))" + + "((7.44 1.75,7.44 1.76,7.47 1.76,7.47 1.72,7.44 1.72,7.44 1.73,7.45 1.73,7.45 1.75," + + "7.44 1.75)))" ); Geometry intersection = result.intersection(expectedPolygon); assertEquals(1.0, expectedPolygon.getArea() / intersection.getArea(), DELTA); @@ -980,8 +978,8 @@ public void test777() throws ParseException { // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( "MULTIPOLYGON(((7.71 1.71,7.78 1.71,7.78 1.77,7.71 1.77,7.71 1.71)," - + "(7.72 1.73,7.72 1.75,7.74 1.75,7.74 1.76,7.77 1.76,7.77 1.72,7.74 1.72,7.74 1.73,7.72 1.73))," - + "((7.74 1.73,7.75 1.73,7.75 1.75,7.74 1.75,7.74 1.73)))" + + "(7.72 1.73,7.72 1.75,7.74 1.75,7.74 1.76,7.77 1.76,7.77 1.72,7.74 1.72,7.74 1.73," + + "7.72 1.73)),((7.74 1.73,7.75 1.73,7.75 1.75,7.74 1.75,7.74 1.73)))" ); Geometry intersection = result.intersection(expectedPolygon); assertEquals(1.0, expectedPolygon.getArea() / intersection.getArea(), DELTA); @@ -1022,8 +1020,8 @@ public void test779() throws ParseException { // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( "MULTIPOLYGON(((7.91 1.71,7.98 1.71,7.98 1.77,7.91 1.77,7.91 1.71)," - + "(7.92 1.73,7.92 1.75,7.94 1.75,7.94 1.76,7.97 1.76,7.97 1.72,7.94 1.72,7.94 1.73,7.92 1.73))," - + "((7.94 1.73,7.95 1.73,7.95 1.75,7.94 1.75,7.94 1.73)))" + + "(7.92 1.73,7.92 1.75,7.94 1.75,7.94 1.76,7.97 1.76,7.97 1.72,7.94 1.72,7.94 1.73," + + "7.92 1.73)),((7.94 1.73,7.95 1.73,7.95 1.75,7.94 1.75,7.94 1.73)))" ); Geometry intersection = result.intersection(expectedPolygon); assertEquals(1.0, expectedPolygon.getArea() / intersection.getArea(), DELTA); @@ -1036,8 +1034,7 @@ public void test780() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -1045,13 +1042,13 @@ public void test780() { @Test public void test781() { - // Multipolygon with one outer ring from single way that has different end-nodes, but they have same location + // Multipolygon with one outer ring from single way that has different end-nodes, but they have + // same location OSMEntity entity1 = testData.relations().get(781900L).get(0); try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -1059,13 +1056,13 @@ public void test781() { @Test public void test782() { - // Multipolygon with correct outer ring, but inner ring made up out of two ways where locations match but not node ids + // Multipolygon with correct outer ring, but inner ring made up out of two ways where locations + // match but not node ids OSMEntity entity1 = testData.relations().get(782900L).get(0); try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -1144,8 +1141,7 @@ public void test790() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -1158,8 +1154,7 @@ public void test791() { try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); assertTrue(result instanceof GeometryCollection || result instanceof Polygonal); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -1171,8 +1166,7 @@ public void test792() { OSMEntity entity1 = testData.relations().get(792900L).get(0); try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -1184,8 +1178,7 @@ public void test793() { OSMEntity entity1 = testData.relations().get(793900L).get(0); try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -1203,8 +1196,7 @@ public void test795() { OSMEntity entity1 = testData.relations().get(795900L).get(0); try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/relations/OSHDBGeometryBuilderMultipolygonInvalidOutersTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/relations/OSHDBGeometryBuilderMultipolygonInvalidOutersTest.java index a766ee320..f3e065e10 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/relations/OSHDBGeometryBuilderMultipolygonInvalidOutersTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/relations/OSHDBGeometryBuilderMultipolygonInvalidOutersTest.java @@ -18,7 +18,7 @@ public class OSHDBGeometryBuilderMultipolygonInvalidOutersTest { private final TagInterpreter tagInterpreter; private final OSHDBTimestamp timestamp = TimestampParser.toOSHDBTimestamp("2014-01-01T00:00:00Z"); - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public OSHDBGeometryBuilderMultipolygonInvalidOutersTest() { testData.add("./src/test/resources/relations/invalid-outer-ring.osm"); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/relations/OSHDBGeometryBuilderRelationOuterDirectionsTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/relations/OSHDBGeometryBuilderRelationOuterDirectionsTest.java index 4864615b4..0625a74ee 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/relations/OSHDBGeometryBuilderRelationOuterDirectionsTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/relations/OSHDBGeometryBuilderRelationOuterDirectionsTest.java @@ -1,5 +1,8 @@ package org.heigit.bigspatialdata.oshdb.util.geometry.relations; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import org.heigit.bigspatialdata.oshdb.osm.OSMEntity; import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp; import org.heigit.bigspatialdata.oshdb.util.geometry.OSHDBGeometryBuilder; @@ -13,16 +16,13 @@ import org.locationtech.jts.io.ParseException; import org.locationtech.jts.io.WKTReader; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public class OSHDBGeometryBuilderRelationOuterDirectionsTest { private final OSMXmlReader testData = new OSMXmlReader(); private final TagInterpreter tagInterpreter; private final OSHDBTimestamp timestamp = TimestampParser.toOSHDBTimestamp("2014-01-01T00:00:00Z"); - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public OSHDBGeometryBuilderRelationOuterDirectionsTest() { testData.add("./src/test/resources/relations/outer-directions.osm"); @@ -42,7 +42,8 @@ public void testFromPointTwoWaysGoingToDiffDirections() throws ParseException { // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( - "MULTIPOLYGON(((7.16 1.36,7.16 1.35,7.15 1.34,7.14 1.34,7.14 1.35,7.14 1.36,7.15 1.36,7.15 1.37,7.16 1.37,7.16 1.36)))" + "MULTIPOLYGON(((7.16 1.36,7.16 1.35,7.15 1.34,7.14 1.34,7.14 1.35,7.14 " + + "1.36,7.15 1.36,7.15 1.37,7.16 1.37,7.16 1.36)))" ); Geometry intersection = result.intersection(expectedPolygon); assertEquals(expectedPolygon.getArea(), intersection.getArea(), DELTA); @@ -60,7 +61,8 @@ public void testToPointTwoWaysPointingFromDiffDirections() throws ParseException // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( - "MULTIPOLYGON(((7.16 1.36,7.16 1.35,7.15 1.34,7.14 1.34,7.14 1.35,7.14 1.36,7.15 1.36,7.15 1.37,7.16 1.37,7.16 1.36)))" + "MULTIPOLYGON(((7.16 1.36,7.16 1.35,7.15 1.34,7.14 1.34,7.14 1.35,7.14 " + + "1.36,7.15 1.36,7.15 1.37,7.16 1.37,7.16 1.36)))" ); Geometry intersection = result.intersection(expectedPolygon); assertEquals(expectedPolygon.getArea(), intersection.getArea(), DELTA); @@ -78,7 +80,8 @@ public void testStartMatchesEnd() throws ParseException { // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( - "MULTIPOLYGON(((7.16 1.36,7.16 1.35,7.15 1.34,7.14 1.34,7.14 1.35,7.14 1.36,7.15 1.36,7.15 1.37,7.16 1.37,7.16 1.36)))" + "MULTIPOLYGON(((7.16 1.36,7.16 1.35,7.15 1.34,7.14 1.34,7.14 1.35,7.14 " + + "1.36,7.15 1.36,7.15 1.37,7.16 1.37,7.16 1.36)))" ); Geometry intersection = result.intersection(expectedPolygon); assertEquals(expectedPolygon.getArea(), intersection.getArea(), DELTA); @@ -96,7 +99,8 @@ public void testEndMatchesStart() throws ParseException { // compare if coordinates of created points equals the coordinates of polygon Geometry expectedPolygon = (new WKTReader()).read( - "MULTIPOLYGON(((7.16 1.36,7.16 1.35,7.15 1.34,7.14 1.34,7.14 1.35,7.14 1.36,7.15 1.36,7.15 1.37,7.16 1.37,7.16 1.36)))" + "MULTIPOLYGON(((7.16 1.36,7.16 1.35,7.15 1.34,7.14 1.34,7.14 1.35,7.14 " + + "1.36,7.15 1.36,7.15 1.37,7.16 1.37,7.16 1.36)))" ); Geometry intersection = result.intersection(expectedPolygon); assertEquals(expectedPolygon.getArea(), intersection.getArea(), DELTA); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/relations/OSHDBGeometryBuilderRelationTypeNotMultipolygonTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/relations/OSHDBGeometryBuilderRelationTypeNotMultipolygonTest.java index 8b29eb8cb..e19e09482 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/relations/OSHDBGeometryBuilderRelationTypeNotMultipolygonTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/relations/OSHDBGeometryBuilderRelationTypeNotMultipolygonTest.java @@ -1,5 +1,8 @@ package org.heigit.bigspatialdata.oshdb.util.geometry.relations; +import static junit.framework.TestCase.fail; +import static org.junit.Assert.assertTrue; + import org.heigit.bigspatialdata.oshdb.osm.OSMEntity; import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp; import org.heigit.bigspatialdata.oshdb.util.geometry.OSHDBGeometryBuilder; @@ -13,15 +16,12 @@ import org.locationtech.jts.geom.LineString; import org.locationtech.jts.geom.Point; -import static junit.framework.TestCase.fail; -import static org.junit.Assert.assertTrue; - public class OSHDBGeometryBuilderRelationTypeNotMultipolygonTest { private final OSMXmlReader testData = new OSMXmlReader(); private final TagInterpreter tagInterpreter; private final OSHDBTimestamp timestamp = TimestampParser.toOSHDBTimestamp("2014-01-01T00:00:00Z"); - private final double DELTA = 1E-6; + private static final double DELTA = 1E-6; public OSHDBGeometryBuilderRelationTypeNotMultipolygonTest() { testData.add("./src/test/resources/relations/relationTypeNotMultipolygon.osm"); @@ -34,13 +34,12 @@ public void testTypeRestriction() { OSMEntity entity1 = testData.relations().get(710900L).get(0); try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); - assertTrue(result instanceof GeometryCollection ); + assertTrue(result instanceof GeometryCollection); assertTrue(result.getNumGeometries() == 3); assertTrue(result.getGeometryN(0) instanceof LineString); assertTrue(result.getGeometryN(1) instanceof Point); assertTrue(result.getGeometryN(2) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -52,13 +51,12 @@ public void testTypeAssociatedStreet() { OSMEntity entity1 = testData.relations().get(710901L).get(0); try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); - assertTrue(result instanceof GeometryCollection ); + assertTrue(result instanceof GeometryCollection); assertTrue(result.getNumGeometries() == 3); assertTrue(result.getGeometryN(0) instanceof Point); assertTrue(result.getGeometryN(1) instanceof Point); assertTrue(result.getGeometryN(2) instanceof Point); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -70,14 +68,13 @@ public void testTypePublicTransport() { OSMEntity entity1 = testData.relations().get(710902L).get(0); try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); - assertTrue(result instanceof GeometryCollection ); + assertTrue(result instanceof GeometryCollection); assertTrue(result.getNumGeometries() == 4); assertTrue(result.getGeometryN(0) instanceof LineString); assertTrue(result.getGeometryN(1) instanceof Point); assertTrue(result.getGeometryN(2) instanceof LineString); assertTrue(result.getGeometryN(3) instanceof Point); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } @@ -89,13 +86,12 @@ public void testTypeBuilding() { OSMEntity entity1 = testData.relations().get(710903L).get(0); try { Geometry result = OSHDBGeometryBuilder.getGeometry(entity1, timestamp, tagInterpreter); - assertTrue(result instanceof GeometryCollection ); + assertTrue(result instanceof GeometryCollection); assertTrue(result.getNumGeometries() == 3); assertTrue(result.getGeometryN(0) instanceof LineString); assertTrue(result.getGeometryN(1) instanceof LineString); assertTrue(result.getGeometryN(2) instanceof LineString); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); fail("Should not have thrown any exception"); } diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/tagtranslator/TagTranslatorTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/tagtranslator/TagTranslatorTest.java index d32041284..be2d03667 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/tagtranslator/TagTranslatorTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/tagtranslator/TagTranslatorTest.java @@ -1,5 +1,7 @@ package org.heigit.bigspatialdata.oshdb.util.tagtranslator; +import static org.junit.Assert.assertEquals; + import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; @@ -8,7 +10,6 @@ import org.heigit.bigspatialdata.oshdb.util.OSHDBTagKey; import org.heigit.bigspatialdata.oshdb.util.exceptions.OSHDBKeytablesNotFoundException; import org.junit.AfterClass; -import static org.junit.Assert.assertEquals; import org.junit.BeforeClass; import org.junit.Test; @@ -22,7 +23,8 @@ public static void setUpClass() throws ClassNotFoundException, SQLException { // connect to the "Big"DB TagTranslatorTest.conn = - DriverManager.getConnection("jdbc:h2:./src/test/resources/test-data;ACCESS_MODE_DATA=r", "sa", ""); + DriverManager.getConnection("jdbc:h2:./src/test/resources/test-data;ACCESS_MODE_DATA=r", + "sa", ""); } @@ -31,7 +33,8 @@ public static void breakDownClass() throws SQLException { TagTranslatorTest.conn.close(); } - public TagTranslatorTest() {} + public TagTranslatorTest() { + } @Test public void testTag2Int() throws OSHDBKeytablesNotFoundException { diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/IsoDateTimeParserTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/IsoDateTimeParserTest.java index 03200de43..444fde1c5 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/IsoDateTimeParserTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/IsoDateTimeParserTest.java @@ -1,176 +1,185 @@ package org.heigit.bigspatialdata.oshdb.util.time; -import java.time.DateTimeException; -import org.junit.Assert; -import org.junit.Test; +import static org.heigit.bigspatialdata.oshdb.util.time.IsoDateTimeParser.parseIsoDateTime; +import static org.heigit.bigspatialdata.oshdb.util.time.IsoDateTimeParser.parseIsoPeriod; +import java.time.DateTimeException; import java.time.Duration; import java.time.Period; import java.util.Map; - -import static org.heigit.bigspatialdata.oshdb.util.time.IsoDateTimeParser.parseIsoDateTime; -import static org.heigit.bigspatialdata.oshdb.util.time.IsoDateTimeParser.parseIsoPeriod; +import org.junit.Assert; +import org.junit.Test; public class IsoDateTimeParserTest { - @Test - public void testParseIsoDateTime() { - // test allowed variants - - //Basic Dates - String[] yyyy = {"2020-01-01T00:00Z", "2020"}; - String[] yyyymm = {"2020-02-01T00:00Z", "202002"}; - String[] yyyymmdd = {"2020-02-17T00:00Z", "20200217"}; - - Assert.assertEquals(yyyy[0], parseIsoDateTime(yyyy[1]).toString()); - Assert.assertEquals(yyyymm[0], parseIsoDateTime(yyyymm[1]).toString()); - Assert.assertEquals(yyyymmdd[0], parseIsoDateTime(yyyymmdd[1]).toString()); - - //Extended Dates - String[] yyyy_mm = {"2020-02-01T00:00Z", "2020-02"}; - String[] yyyy_mm_dd = {"2020-02-17T00:00Z", "2020-02-17"}; - - Assert.assertEquals(yyyy_mm[0], parseIsoDateTime(yyyy_mm[1]).toString()); - Assert.assertEquals(yyyy_mm_dd[0], parseIsoDateTime(yyyy_mm_dd[1]).toString()); - - //Extended Date-Time - String[] yyyy_mm_dd_hh = {"2020-02-17T23:00Z", "2020-02-17T23"}; - String[] yyyy_mm_dd_hhz = {"2020-02-17T23:00Z", "2020-02-17T23Z"}; - - String[] yyyy_mm_dd_hh_mm = {"2020-02-17T23:55Z", "2020-02-17T23:55"}; - String[] yyyy_mm_dd_hh_mmz = {"2020-02-17T23:55Z", "2020-02-17T23:55Z"}; - - String[] yyyy_mm_dd_hh_mm_ss = {"2020-02-17T23:55:12Z", "2020-02-17T23:55:12"}; - String[] yyyy_mm_dd_hh_mm_ssz = {"2020-02-17T23:55:12Z", "2020-02-17T23:55:12Z"}; - - String[] yyyy_mm_dd_hh_mm_ss_sss = {"2020-02-17T23:55:12.999Z", "2020-02-17T23:55:12.999"}; - String[] yyyy_mm_dd_hh_mm_ss_sssz = {"2020-02-17T23:55:12.999Z", "2020-02-17T23:55:12.999Z"}; - - Assert.assertEquals(yyyy_mm_dd_hh[0], parseIsoDateTime(yyyy_mm_dd_hh[1]).toString()); - Assert.assertEquals(yyyy_mm_dd_hhz[0], parseIsoDateTime(yyyy_mm_dd_hhz[1]).toString()); - - Assert.assertEquals(yyyy_mm_dd_hh_mm[0], parseIsoDateTime(yyyy_mm_dd_hh_mm[1]).toString()); - Assert.assertEquals(yyyy_mm_dd_hh_mmz[0], parseIsoDateTime(yyyy_mm_dd_hh_mmz[1]).toString()); - - Assert.assertEquals(yyyy_mm_dd_hh_mm_ss[0], parseIsoDateTime(yyyy_mm_dd_hh_mm_ss[1]).toString()); - Assert.assertEquals(yyyy_mm_dd_hh_mm_ssz[0], parseIsoDateTime(yyyy_mm_dd_hh_mm_ssz[1]).toString()); - - Assert.assertEquals(yyyy_mm_dd_hh_mm_ss_sss[0], parseIsoDateTime(yyyy_mm_dd_hh_mm_ss_sss[1]).toString()); - Assert.assertEquals(yyyy_mm_dd_hh_mm_ss_sssz[0], parseIsoDateTime(yyyy_mm_dd_hh_mm_ss_sssz[1]).toString()); - - } - - - @Test(expected = OSHDBTimestampException.class) - public void throwsNegativeDateParseIsoDateTime() { - //Negative Dates - String nyyyy = "-0333"; - parseIsoDateTime(nyyyy); - } - - @Test(expected = OSHDBTimestampException.class) - public void throwsShortYearParseIsoDateTime() { - //Short Year - String yy = "12"; - parseIsoDateTime(yy); - } - - @Test(expected = OSHDBTimestampException.class) - public void throwsPosTimezoneHHParseIsoDateTime() { - String posTimezone_hh = "2020-02-17T23:55+02"; - parseIsoDateTime(posTimezone_hh); - } - - @Test(expected = OSHDBTimestampException.class) - public void throwsPosTimezoneHHMMParseIsoDateTime() { - String posTimezone_hhmm = "2020-02-17T23:55+0230"; - parseIsoDateTime(posTimezone_hhmm); - } - - @Test(expected = OSHDBTimestampException.class) - public void throwsPosTimezoneHH_MMParseIsoDateTime() { - String posTimezone_hh_mm = "2020-02-17T23:55+02:30"; - parseIsoDateTime(posTimezone_hh_mm); - } - - // - @Test(expected = OSHDBTimestampException.class) - public void throwsNegTimezoneHHParseIsoDateTime() { - String negTimezone_hh = "2020-02-17T23:55-02"; - parseIsoDateTime(negTimezone_hh); - } - - @Test(expected = OSHDBTimestampException.class) - public void throwsNegTimezoneHHMMParseIsoDateTime() { - String negTimezone_hhmm = "2020-02-17T23:55-0230"; - parseIsoDateTime(negTimezone_hhmm); - } - - @Test(expected = OSHDBTimestampException.class) - public void throwsNegTimezoneHH_MMParseIsoDateTime() { - String negTimezone_hh_mm = "2020-02-17T23:55-02:30"; - parseIsoDateTime(negTimezone_hh_mm); - } - - @Test(expected = DateTimeException.class) - public void throwsWrongDateParseIsoDateTime() { - //Wrong Date - String wrongDateTime = "2020-13-01T00:00"; - parseIsoDateTime(wrongDateTime); - } - - - @Test - public void testParseIsoPeriod() { - // test allowed variants - - // Full DateTime Period: PnYnMnDTnHnMnS, e.g P1Y3M10DT1H15M25S (1 year 3months 10 days 1 hour 15 minutes and 25 seconds) - // Full Date Period: PnYnMnD, e.g. P1Y3M10D (1 year 3 months and 10 days) - // Short Date Period: e.g PnY or PnMnD or any combination of years, months and days - // Week Period: PnW, e.g. P2W 2 weeks - // Full Time Duration: PTnHnMnS, e.g. PT1H3M25S (1 hour 3 minutes and 25 seconds) - // Short Time Duration: PTnH or any combination of hours, minutes and seconds (PT1H10S 1 hour and 10 seconds) - - String[] fullDateTimePeriod = {"P1Y3M10DT1H15M25S", "P1Y3M10D", "PT1H15M25S"}; // input, output Period, output Duration - Map fullYearMonthDayTime = parseIsoPeriod(fullDateTimePeriod[0]); - Period fullYearMonthDayTimePeriod = (Period) fullYearMonthDayTime.get("period"); - Duration fullYearMonthDayTimeDuration = (Duration) fullYearMonthDayTime.get("duration"); - Assert.assertEquals(fullDateTimePeriod[1], fullYearMonthDayTimePeriod.toString()); - Assert.assertEquals(fullDateTimePeriod[2], fullYearMonthDayTimeDuration.toString()); - - String fullDatePeriod = "P1Y3M10D"; //Period output should be same as input, Duration should be ZERO; - Map fullYearMonthDay = parseIsoPeriod(fullDatePeriod); - Period fullYearMonthDayPeriod = (Period) fullYearMonthDay.get("period"); - Duration fullYearMonthDayDuration = (Duration) fullYearMonthDay.get("duration"); - Assert.assertEquals(fullDatePeriod, fullYearMonthDayPeriod.toString()); - Assert.assertTrue(fullYearMonthDayDuration.isZero()); - - String shortDatePeriod = "P3M10D"; //Period output should be same as input, Duration should be ZERO; - Map shortMonthDay = parseIsoPeriod(shortDatePeriod); - Period shortMonthDayPeriod = (Period) shortMonthDay.get("period"); - Duration shortMonthDayDuration = (Duration) shortMonthDay.get("duration"); - Assert.assertEquals(shortDatePeriod, shortMonthDayPeriod.toString()); - Assert.assertTrue(shortMonthDayDuration.isZero()); - - String weekPeriod = "P2W"; // Period should equal 14 days, Duration should be ZERO; - Map twoWeeks = parseIsoPeriod(weekPeriod); - Period twoWeeksPeriod = (Period) twoWeeks.get("period"); - Duration twoWeeksDuration = (Duration) twoWeeks.get("duration"); - Assert.assertEquals(14, twoWeeksPeriod.getDays()); - Assert.assertTrue(twoWeeksDuration.isZero()); - - } - - @Test(expected = OSHDBTimestampException.class) - public void throwsFormatParseIsoPeriod() { - // test throw exeption for unsupported formats - parseIsoPeriod("PT1Y2M"); - } - - @Test(expected = OSHDBTimestampException.class) - public void throwsZeroLengthParseIsoPeriod() { - //test for zero length ISOPeriod - parseIsoPeriod("PT0S"); - } + @Test + public void testParseIsoDateTime() { + // test allowed variants + + //Basic Dates + String[] yyyy = {"2020-01-01T00:00Z", "2020"}; + String[] yyyymm = {"2020-02-01T00:00Z", "202002"}; + String[] yyyymmdd = {"2020-02-17T00:00Z", "20200217"}; + + Assert.assertEquals(yyyy[0], parseIsoDateTime(yyyy[1]).toString()); + Assert.assertEquals(yyyymm[0], parseIsoDateTime(yyyymm[1]).toString()); + Assert.assertEquals(yyyymmdd[0], parseIsoDateTime(yyyymmdd[1]).toString()); + + //Extended Dates + String[] yyyyMm = {"2020-02-01T00:00Z", "2020-02"}; + String[] yyyyMmDd = {"2020-02-17T00:00Z", "2020-02-17"}; + + Assert.assertEquals(yyyyMm[0], parseIsoDateTime(yyyyMm[1]).toString()); + Assert.assertEquals(yyyyMmDd[0], parseIsoDateTime(yyyyMmDd[1]).toString()); + + //Extended Date-Time + String[] yyyyMmDdHh = {"2020-02-17T23:00Z", "2020-02-17T23"}; + String[] yyyyMmDdHhz = {"2020-02-17T23:00Z", "2020-02-17T23Z"}; + + String[] yyyyMmDdHhMm = {"2020-02-17T23:55Z", "2020-02-17T23:55"}; + String[] yyyyMmDdHhMmz = {"2020-02-17T23:55Z", "2020-02-17T23:55Z"}; + + String[] yyyyMmDdHhMmSs = {"2020-02-17T23:55:12Z", "2020-02-17T23:55:12"}; + String[] yyyyMmDdHhMmSsz = {"2020-02-17T23:55:12Z", "2020-02-17T23:55:12Z"}; + + String[] yyyyMmDdHhMmSsSss = {"2020-02-17T23:55:12.999Z", "2020-02-17T23:55:12.999"}; + String[] yyyyMmDdHhMmSsSssz = {"2020-02-17T23:55:12.999Z", "2020-02-17T23:55:12.999Z"}; + + Assert.assertEquals(yyyyMmDdHh[0], parseIsoDateTime(yyyyMmDdHh[1]).toString()); + Assert.assertEquals(yyyyMmDdHhz[0], parseIsoDateTime(yyyyMmDdHhz[1]).toString()); + + Assert.assertEquals(yyyyMmDdHhMm[0], parseIsoDateTime(yyyyMmDdHhMm[1]).toString()); + Assert.assertEquals(yyyyMmDdHhMmz[0], parseIsoDateTime(yyyyMmDdHhMmz[1]).toString()); + + Assert.assertEquals(yyyyMmDdHhMmSs[0], parseIsoDateTime(yyyyMmDdHhMmSs[1]).toString()); + Assert.assertEquals(yyyyMmDdHhMmSsz[0], parseIsoDateTime(yyyyMmDdHhMmSsz[1]).toString()); + + Assert.assertEquals(yyyyMmDdHhMmSsSss[0], parseIsoDateTime(yyyyMmDdHhMmSsSss[1]).toString()); + Assert.assertEquals(yyyyMmDdHhMmSsSssz[0], parseIsoDateTime(yyyyMmDdHhMmSsSssz[1]).toString()); + + } + + + @Test(expected = OSHDBTimestampException.class) + public void throwsNegativeDateParseIsoDateTime() { + //Negative Dates + String nyyyy = "-0333"; + parseIsoDateTime(nyyyy); + } + + @Test(expected = OSHDBTimestampException.class) + public void throwsShortYearParseIsoDateTime() { + //Short Year + String yy = "12"; + parseIsoDateTime(yy); + } + + @Test(expected = OSHDBTimestampException.class) + public void throwsPosTimezoneHhParseIsoDateTime() { + String posTimezoneHh = "2020-02-17T23:55+02"; + parseIsoDateTime(posTimezoneHh); + } + + @Test(expected = OSHDBTimestampException.class) + public void throwsPosTimezoneHhMmParseIsoDateTime() { + String posTimezoneHhmm = "2020-02-17T23:55+0230"; + parseIsoDateTime(posTimezoneHhmm); + } + + @Test(expected = OSHDBTimestampException.class) + public void throwsPosTimezoneHh_MmParseIsoDateTime() { + String posTimezoneHhMm = "2020-02-17T23:55+02:30"; + parseIsoDateTime(posTimezoneHhMm); + } + + // + @Test(expected = OSHDBTimestampException.class) + public void throwsNegTimezoneHhParseIsoDateTime() { + String negTimezoneHh = "2020-02-17T23:55-02"; + parseIsoDateTime(negTimezoneHh); + } + + @Test(expected = OSHDBTimestampException.class) + public void throwsNegTimezoneHhMmParseIsoDateTime() { + String negTimezoneHhMm = "2020-02-17T23:55-0230"; + parseIsoDateTime(negTimezoneHhMm); + } + + @Test(expected = OSHDBTimestampException.class) + public void throwsNegTimezoneHh_MmParseIsoDateTime() { + String negTimezoneHhMm = "2020-02-17T23:55-02:30"; + parseIsoDateTime(negTimezoneHhMm); + } + + @Test(expected = DateTimeException.class) + public void throwsWrongDateParseIsoDateTime() { + //Wrong Date + String wrongDateTime = "2020-13-01T00:00"; + parseIsoDateTime(wrongDateTime); + } + + + @Test + public void testParseIsoPeriod() { + // test allowed variants + + // Full DateTime Period: PnYnMnDTnHnMnS, + // e.g P1Y3M10DT1H15M25S (1 year 3months 10 days 1 hour 15 minutes and 25 seconds) + // Full Date Period: PnYnMnD, + // e.g. P1Y3M10D (1 year 3 months and 10 days) + // Short Date Period: + // e.g PnY or PnMnD or any combination of years, months and days + // Week Period: PnW, + // e.g. P2W (2 weeks) + // Full Time Duration: PTnHnMnS, + // e.g. PT1H3M25S (1 hour 3 minutes and 25 seconds) + // Short Time Duration: PTnH or any combination of hours, minutes and seconds + // e.g. PT1H10S (1 hour and 10 seconds) + + // input, output Period, output Duration + String[] fullDateTimePeriod = {"P1Y3M10DT1H15M25S", "P1Y3M10D", "PT1H15M25S"}; + Map fullYearMonthDayTime = parseIsoPeriod(fullDateTimePeriod[0]); + Period fullYearMonthDayTimePeriod = (Period) fullYearMonthDayTime.get("period"); + Duration fullYearMonthDayTimeDuration = (Duration) fullYearMonthDayTime.get("duration"); + Assert.assertEquals(fullDateTimePeriod[1], fullYearMonthDayTimePeriod.toString()); + Assert.assertEquals(fullDateTimePeriod[2], fullYearMonthDayTimeDuration.toString()); + + // Period output should be same as input, Duration should be ZERO + String fullDatePeriod = "P1Y3M10D"; + Map fullYearMonthDay = parseIsoPeriod(fullDatePeriod); + Period fullYearMonthDayPeriod = (Period) fullYearMonthDay.get("period"); + Duration fullYearMonthDayDuration = (Duration) fullYearMonthDay.get("duration"); + Assert.assertEquals(fullDatePeriod, fullYearMonthDayPeriod.toString()); + Assert.assertTrue(fullYearMonthDayDuration.isZero()); + + // Period output should be same as input, Duration should be ZERO + String shortDatePeriod = "P3M10D"; + Map shortMonthDay = parseIsoPeriod(shortDatePeriod); + Period shortMonthDayPeriod = (Period) shortMonthDay.get("period"); + Duration shortMonthDayDuration = (Duration) shortMonthDay.get("duration"); + Assert.assertEquals(shortDatePeriod, shortMonthDayPeriod.toString()); + Assert.assertTrue(shortMonthDayDuration.isZero()); + + // Period should equal 14 days, Duration should be ZERO + String weekPeriod = "P2W"; + Map twoWeeks = parseIsoPeriod(weekPeriod); + Period twoWeeksPeriod = (Period) twoWeeks.get("period"); + Duration twoWeeksDuration = (Duration) twoWeeks.get("duration"); + Assert.assertEquals(14, twoWeeksPeriod.getDays()); + Assert.assertTrue(twoWeeksDuration.isZero()); + + } + + @Test(expected = OSHDBTimestampException.class) + public void throwsFormatParseIsoPeriod() { + // test throw exeption for unsupported formats + parseIsoPeriod("PT1Y2M"); + } + + @Test(expected = OSHDBTimestampException.class) + public void throwsZeroLengthParseIsoPeriod() { + //test for zero length ISOPeriod + parseIsoPeriod("PT0S"); + } } diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/OSHDBTimestampsTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/OSHDBTimestampsTest.java index b29072f39..1d7e5a931 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/OSHDBTimestampsTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/OSHDBTimestampsTest.java @@ -1,14 +1,14 @@ package org.heigit.bigspatialdata.oshdb.util.time; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.Arrays; import java.util.EnumSet; -import java.util.Iterator; import java.util.List; import java.util.Set; -import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp; import org.heigit.bigspatialdata.oshdb.util.time.OSHDBTimestamps.Interval; import org.junit.Test; @@ -16,40 +16,46 @@ public class OSHDBTimestampsTest { @Test public void testTimeIntervals() { - List startList = new ArrayList<>(); - List endList = new ArrayList<>(); - List intervalList = new ArrayList<>(); - List> expectedResultList = new ArrayList<>(); + final List startList = new ArrayList<>(); + final List endList = new ArrayList<>(); + final List intervalList = new ArrayList<>(); + final List> expectedResultList = new ArrayList<>(); startList.add("2008-01-31T12:34:56"); endList.add("2010-01-31T12:34:56"); intervalList.add(Interval.YEARLY); - expectedResultList.add(Arrays.asList("2008-01-31T12:34:56", "2009-01-31T12:34:56", "2010-01-31T12:34:56")); + expectedResultList.add( + Arrays.asList("2008-01-31T12:34:56", "2009-01-31T12:34:56", "2010-01-31T12:34:56")); startList.add("2008-01-31T12:34:56"); endList.add("2008-07-31T12:34:56"); intervalList.add(Interval.QUARTERLY); - expectedResultList.add(Arrays.asList("2008-01-31T12:34:56", "2008-04-30T12:34:56", "2008-07-31T12:34:56")); + expectedResultList.add( + Arrays.asList("2008-01-31T12:34:56", "2008-04-30T12:34:56", "2008-07-31T12:34:56")); startList.add("2008-01-31T12:34:56"); endList.add("2008-03-31T12:34:56"); intervalList.add(Interval.MONTHLY); - expectedResultList.add(Arrays.asList("2008-01-31T12:34:56", "2008-02-29T12:34:56", "2008-03-31T12:34:56")); + expectedResultList.add( + Arrays.asList("2008-01-31T12:34:56", "2008-02-29T12:34:56", "2008-03-31T12:34:56")); startList.add("2008-01-31T12:34:56"); endList.add("2008-02-14T12:34:56"); intervalList.add(Interval.WEEKLY); - expectedResultList.add(Arrays.asList("2008-01-31T12:34:56", "2008-02-07T12:34:56", "2008-02-14T12:34:56")); + expectedResultList.add( + Arrays.asList("2008-01-31T12:34:56", "2008-02-07T12:34:56", "2008-02-14T12:34:56")); startList.add("2008-01-31T12:34:56"); endList.add("2008-02-02T12:34:56"); intervalList.add(Interval.DAILY); - expectedResultList.add(Arrays.asList("2008-01-31T12:34:56", "2008-02-01T12:34:56", "2008-02-02T12:34:56")); + expectedResultList.add( + Arrays.asList("2008-01-31T12:34:56", "2008-02-01T12:34:56", "2008-02-02T12:34:56")); startList.add("2008-01-31T12:34:56"); endList.add("2008-01-31T15:00:00"); intervalList.add(Interval.HOURLY); - expectedResultList.add(Arrays.asList("2008-01-31T12:34:56", "2008-01-31T13:34:56", "2008-01-31T14:34:56")); + expectedResultList.add( + Arrays.asList("2008-01-31T12:34:56", "2008-01-31T13:34:56", "2008-01-31T14:34:56")); // check if lists have the same size assertEquals(startList.size(), endList.size()); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/TimestampFormatterTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/TimestampFormatterTest.java index ae5f3e07d..b364772f0 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/TimestampFormatterTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/TimestampFormatterTest.java @@ -3,11 +3,12 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ + package org.heigit.bigspatialdata.oshdb.util.time; -import org.heigit.bigspatialdata.oshdb.util.time.TimestampFormatter; -import java.util.Date; import static org.junit.Assert.assertEquals; + +import java.util.Date; import org.junit.Test; public class TimestampFormatterTest { diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/MutableOSMEntity.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/MutableOSMEntity.java index fcdb47494..ea370cfbd 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/MutableOSMEntity.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/MutableOSMEntity.java @@ -13,7 +13,8 @@ public class MutableOSMEntity { private int userId; private int[] tags; - public void setEntity(long id, int version, boolean visible, long timestamp, long changeset, int userId, int[] tags) { + public void setEntity(long id, int version, boolean visible, long timestamp, + long changeset, int userId, int[] tags) { this.id = id; this.version = version; this.visible = visible; diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/MutableOSMNode.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/MutableOSMNode.java index f1753d1a2..b098c623e 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/MutableOSMNode.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/MutableOSMNode.java @@ -8,7 +8,7 @@ public long getLon() { return longitude; } - public void setLon(long longitude){ + public void setLon(long longitude) { this.longitude = longitude; } @@ -17,7 +17,7 @@ public long getLat() { return latitude; } - public void setLat(long latitude){ + public void setLat(long latitude) { this.latitude = latitude; } diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/OSMXmlReader.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/OSMXmlReader.java index f067bfba4..cc3e592e0 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/OSMXmlReader.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/OSMXmlReader.java @@ -1,5 +1,10 @@ package org.heigit.bigspatialdata.oshdb.util.xmlreader; +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; +import com.google.common.collect.ListMultimap; +import com.google.common.collect.MultimapBuilder; +import com.google.common.io.Files; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.IOException; @@ -34,11 +39,6 @@ import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; -import com.google.common.collect.ListMultimap; -import com.google.common.collect.MultimapBuilder; -import com.google.common.io.Files; public class OSMXmlReader { @@ -133,8 +133,9 @@ private void read(Document doc) throws IOException { osm.setExtension(longitude, latitude); - OSMNode oldOSM = new OSMNode(osm.getId(), osm.getVersion() * (osm.isVisible() ? 1 : -1), osm.getTimestamp(), - osm.getChangeset(), osm.getUserId(), osm.getTags(), osm.getLon(), osm.getLat()); + OSMNode oldOSM = new OSMNode(osm.getId(), osm.getVersion() * (osm.isVisible() ? 1 : -1), + osm.getTimestamp(), osm.getChangeset(), osm.getUserId(), osm.getTags(), osm.getLon(), + osm.getLat()); nodes.put(Long.valueOf(id), oldOSM); } lastId = id; @@ -165,8 +166,8 @@ private void read(Document doc) throws IOException { members[idx++] = new OSMMember(memId, OSMType.NODE, 0, data); } // osm.setExtension(members); - OSMWay oldOSM = new OSMWay(osm.getId(), osm.getVersion() * (osm.isVisible() ? 1 : -1), osm.getTimestamp(), - osm.getChangeset(), osm.getUserId(), osm.getTags(), members); + OSMWay oldOSM = new OSMWay(osm.getId(), osm.getVersion() * (osm.isVisible() ? 1 : -1), + osm.getTimestamp(), osm.getChangeset(), osm.getUserId(), osm.getTags(), members); ways.put(Long.valueOf(id), oldOSM); } lastId = id; @@ -199,9 +200,9 @@ private void read(Document doc) throws IOException { } OSMType t; - if ("node".equalsIgnoreCase(type)) + if ("node".equalsIgnoreCase(type)) { t = OSMType.NODE; - else if ("way".equalsIgnoreCase(type)) { + } else if ("way".equalsIgnoreCase(type)) { t = OSMType.WAY; } else if ("relation".equalsIgnoreCase(type)) { t = OSMType.RELATION; @@ -211,6 +212,8 @@ else if ("way".equalsIgnoreCase(type)) { // members[idx++] = new OSMMemberRelation(memId, t, r.intValue()); OSHEntity data = null; + // todo write default case + // todo add case for relation switch (t) { case NODE: if (this.nodes.containsKey(memId)) { @@ -235,7 +238,8 @@ else if ("way".equalsIgnoreCase(type)) { members[idx++] = new OSMMember(memId, t, r.intValue(), data); } // osm.setExtension(members); - OSMRelation oldOSM = new OSMRelation(osm.getId(), osm.getVersion() * (osm.isVisible() ? 1 : -1), + OSMRelation oldOSM = new OSMRelation(osm.getId(), + osm.getVersion() * (osm.isVisible() ? 1 : -1), osm.getTimestamp(), osm.getChangeset(), osm.getUserId(), osm.getTags(), members); relations.put(Long.valueOf(id), oldOSM); } @@ -246,10 +250,10 @@ else if ("way".equalsIgnoreCase(type)) { public void add(String... xmlFileUrl) { try { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + DocumentBuilder docBuilder = dbFactory.newDocumentBuilder(); for (String p : xmlFileUrl) { - Document doc = dBuilder.parse(p); + Document doc = docBuilder.parse(p); read(doc); } } catch (ParserConfigurationException | SAXException | IOException e) { @@ -260,7 +264,7 @@ public void add(String... xmlFileUrl) { public void add(Path... xmlFilePath) { try { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + DocumentBuilder docBuilder = dbFactory.newDocumentBuilder(); for (Path p : xmlFilePath) { String extension = Files.getFileExtension(p.toString()); @@ -271,7 +275,7 @@ public void add(Path... xmlFilePath) { is = new GZIPInputStream(fileStream); } - Document doc = dBuilder.parse(is); + Document doc = docBuilder.parse(is); read(doc); } } From 051624bcd9f96f2160e79d09692f5d95da957e40 Mon Sep 17 00:00:00 2001 From: Johannes Visintini Date: Wed, 4 Nov 2020 11:43:01 +0100 Subject: [PATCH 3/9] add missing default case in OSMXmlReader test --- .../bigspatialdata/oshdb/util/xmlreader/OSMXmlReader.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/OSMXmlReader.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/OSMXmlReader.java index cc3e592e0..2fb6c3243 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/OSMXmlReader.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/OSMXmlReader.java @@ -212,8 +212,7 @@ private void read(Document doc) throws IOException { // members[idx++] = new OSMMemberRelation(memId, t, r.intValue()); OSHEntity data = null; - // todo write default case - // todo add case for relation + // relation-relation-members do not get data, because they are unsupported switch (t) { case NODE: if (this.nodes.containsKey(memId)) { @@ -234,6 +233,8 @@ private void read(Document doc) throws IOException { ); } break; + default: + break; } members[idx++] = new OSMMember(memId, t, r.intValue(), data); } From abae407fbf6ef70524137f0997cc7df2806e58af Mon Sep 17 00:00:00 2001 From: Johannes Visintini Date: Wed, 4 Nov 2020 19:58:06 +0100 Subject: [PATCH 4/9] update to ohsome-parent 2.6 allows to use @SuppressWarnings in checkstyle --- .idea/checkstyle-idea.xml | 4 ++-- pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml index a1cc8b480..a9b0564de 100644 --- a/.idea/checkstyle-idea.xml +++ b/.idea/checkstyle-idea.xml @@ -3,12 +3,12 @@

geometry type + */ public

FastBboxInPolygon(P geom) { super(geom); @@ -44,7 +50,7 @@ public

FastBboxInPolygon(P geom) { } /** - * Tests if the given bounding box is fully inside of the polygon + * Tests if the given bounding box is fully inside of the polygon. */ @Override public boolean test(OSHDBBoundingBox boundingBox) { @@ -67,7 +73,8 @@ public boolean test(OSHDBBoundingBox boundingBox) { && boundingBox.getMaxLat() >= innerBBox.getMaxY() && boundingBox.getMinLon() <= innerBBox.getMinX() && boundingBox.getMaxLon() >= innerBBox.getMaxX()) { - return false; // the bounding box fully covers at least one of the polygon's inner rings + // the bounding box fully covers at least one of the (multi)polygon's inner rings + return false; } } return true; diff --git a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxOutsidePolygon.java b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxOutsidePolygon.java index 97d903b4a..19fa0cadf 100644 --- a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxOutsidePolygon.java +++ b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxOutsidePolygon.java @@ -24,6 +24,13 @@ public class FastBboxOutsidePolygon extends FastInPolygon implements Predicate outerBboxes = new ArrayList<>(); + + /** + * Constructor using a given geometry {@code geom} and geometry type {@code P}. + * + * @param geom geometry object + * @param

geometry type + */ public

FastBboxOutsidePolygon(P geom) { super(geom); @@ -42,7 +49,7 @@ public

FastBboxOutsidePolygon(P geom) { } /** - * Tests if the given bounding box is fully inside of the polygon + * Tests if the given bounding box is fully outside of the polygon. */ @Override public boolean test(OSHDBBoundingBox boundingBox) { diff --git a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastInPolygon.java b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastInPolygon.java index 25bbb7f23..bc461da69 100644 --- a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastInPolygon.java +++ b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastInPolygon.java @@ -110,7 +110,7 @@ protected

FastInPolygon(P geom) { * ported from http://geomalgorithms.com/a03-_inclusion.html * which is derived from https://wrf.ecse.rpi.edu//Research/Short_Notes/pnpoly.html * - * @param point + * @param point {@link Point} to be processed * @param dir boolean: true -> horizontal test, false -> vertical test * @return crossing number of this point in the chosen direction, * if the value is even the point is outside of the polygon, otherwise it is inside diff --git a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPointInPolygon.java b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPointInPolygon.java index f5da664ac..f5f9f9efc 100644 --- a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPointInPolygon.java +++ b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPointInPolygon.java @@ -15,7 +15,7 @@ public

FastPointInPolygon(P geom) { } /** - * Tests if the given bounding box is fully inside of the polygon + * Tests if the given bounding box is fully inside of the polygon. */ @Override public boolean test(Point point) { diff --git a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPolygonOperations.java b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPolygonOperations.java index 757f6c7db..c1d248fd9 100644 --- a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPolygonOperations.java +++ b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPolygonOperations.java @@ -23,6 +23,12 @@ public class FastPolygonOperations implements Serializable { private double envWidth; private double envHeight; + /** + * Constructor using a given geometry {@code geom} and geometry type {@code P}. + * + * @param geom geometry object + * @param

geometry type + */ public

FastPolygonOperations(P geom) { double optNumBands = Math.max(1.0, Math.sqrt(1.0 * geom.getNumPoints() / AVERAGE_VERTICES_PER_BLOCK)); @@ -133,6 +139,12 @@ private void traverseQuads( } } + /** + * Calculate intersection with another {@link Geometry}. + * + * @param other {@link Geometry} to intersect with + * @return intersected {@link Geometry} + */ public Geometry intersection(Geometry other) { if (other == null || other.isEmpty()) { return other; diff --git a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/taginterpreter/DefaultTagInterpreter.java b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/taginterpreter/DefaultTagInterpreter.java index 92ae7e617..648eab2f9 100644 --- a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/taginterpreter/DefaultTagInterpreter.java +++ b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/taginterpreter/DefaultTagInterpreter.java @@ -20,7 +20,7 @@ import org.slf4j.LoggerFactory; /** - * Default TagInterpreter + * Default {@link TagInterpreter} implementation. */ public class DefaultTagInterpreter extends BaseTagInterpreter { private static final Logger LOG = LoggerFactory.getLogger(DefaultTagInterpreter.class); @@ -35,10 +35,13 @@ public class DefaultTagInterpreter extends BaseTagInterpreter { = "json/uninterestingTags.json"; /** + * Constructor using given {@link TagTranslator} and default values as areaTagsDefinitonFile and + * uninterestingTagsDefinitionFile. * - * @param tagTranslator - * @throws IOException - * @throws ParseException + *

+ * Details see + * {@link DefaultTagInterpreter#DefaultTagInterpreter(TagTranslator, String, String)}. + *

*/ public DefaultTagInterpreter(TagTranslator tagTranslator) throws IOException, ParseException { this( @@ -49,12 +52,15 @@ public DefaultTagInterpreter(TagTranslator tagTranslator) throws IOException, Pa } /** + * Constructor using given {@link TagTranslator}, areaTagsDefinitonFile, and + * uninterestingTagsDefinitionFile. * - * @param tagTranslator - * @param areaTagsDefinitionFile - * @param uninterestingTagsDefinitionFile - * @throws IOException - * @throws ParseException + * @param tagTranslator {@link TagTranslator} used by {@link TagInterpreter} + * @param areaTagsDefinitionFile filename of a JSON file containing tags that are supposed to be + * areas + * @param uninterestingTagsDefinitionFile filename of a JSON file containing tags to be ignored + * @throws IOException thrown for all IO read/write errors + * @throws ParseException for parsing errors */ public DefaultTagInterpreter( TagTranslator tagTranslator, diff --git a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/time/OSHDBTimestampInterval.java b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/time/OSHDBTimestampInterval.java index 50971cb33..d8466752c 100644 --- a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/time/OSHDBTimestampInterval.java +++ b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/time/OSHDBTimestampInterval.java @@ -32,6 +32,7 @@ public boolean includes(OSHDBTimestamp timestamp) { && timestamp.getRawUnixTimestamp() < this.toTimestamp.getRawUnixTimestamp(); } + @SuppressWarnings("MissingJavadocMethod") public int compareTo(@Nonnull OSHDBTimestamp timestamp) { if (this.includes(timestamp)) { return 0; diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateAllTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateAllTest.java index 316357f57..f5a57ab7c 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateAllTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateAllTest.java @@ -27,6 +27,9 @@ public class IterateAllTest { private static Connection conn; + /** + * Set up of test framework, loading H2 driver and connection via jdbc. + */ @BeforeClass public static void setUpClass() throws ClassNotFoundException, SQLException { // load H2-support diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionNodesTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionNodesTest.java index 38b0fcf4d..aae712f3a 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionNodesTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionNodesTest.java @@ -29,6 +29,10 @@ public class IterateByContributionNodesTest { private final OSMXmlReader osmXmlTestData = new OSMXmlReader(); TagInterpreter areaDecider; + /** + * Initialize test framework by loading osm XML file and initializing {@link TagInterpreter} and + * {@link GridOSHNodes}. + */ public IterateByContributionNodesTest() throws IOException { osmXmlTestData.add("./src/test/resources/different-timestamps/node.osm"); areaDecider = new OSMXmlReaderTagInterpreter(osmXmlTestData); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionNotOsmTypeSpecificTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionNotOsmTypeSpecificTest.java index 9c837295f..d19caa04a 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionNotOsmTypeSpecificTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionNotOsmTypeSpecificTest.java @@ -7,6 +7,7 @@ import java.util.Collections; import java.util.List; import java.util.stream.Collectors; +import org.heigit.bigspatialdata.oshdb.grid.GridOSHNodes; import org.heigit.bigspatialdata.oshdb.grid.GridOSHRelations; import org.heigit.bigspatialdata.oshdb.osh.OSHRelation; import org.heigit.bigspatialdata.oshdb.util.celliterator.CellIterator.IterateAllEntry; @@ -27,6 +28,10 @@ public class IterateByContributionNotOsmTypeSpecificTest { private final List oshRelations; private static final double DELTA = 1E-6; + /** + * Initialize test framework by loading osm XML file and initializing {@link TagInterpreter} and + * a list of {@link OSHRelation OSHRelations}. + */ public IterateByContributionNotOsmTypeSpecificTest() throws IOException { osmXmlTestData.add("./src/test/resources/different-timestamps/polygon.osm"); areaDecider = new OSMXmlReaderTagInterpreter(osmXmlTestData); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionRelationsTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionRelationsTest.java index d76c4466f..8e7ad4fef 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionRelationsTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionRelationsTest.java @@ -9,6 +9,7 @@ import java.util.EnumSet; import java.util.List; import java.util.stream.Collectors; +import org.heigit.bigspatialdata.oshdb.grid.GridOSHNodes; import org.heigit.bigspatialdata.oshdb.grid.GridOSHRelations; import org.heigit.bigspatialdata.oshdb.util.OSHDBBoundingBox; import org.heigit.bigspatialdata.oshdb.util.celliterator.CellIterator.IterateAllEntry; @@ -31,6 +32,10 @@ public class IterateByContributionRelationsTest { TagInterpreter areaDecider; private static final double DELTA = 1E-6; + /** + * Initialize test framework by loading osm XML file and initializing {@link TagInterpreter} and + * {@link GridOSHRelations}. + */ public IterateByContributionRelationsTest() throws IOException { osmXmlTestData.add("./src/test/resources/different-timestamps/polygon.osm");// read osm xml data areaDecider = new OSMXmlReaderTagInterpreter(osmXmlTestData);// Used to provided information diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionTypeNotMultipolygonTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionTypeNotMultipolygonTest.java index f5719bd5b..0119d90b2 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionTypeNotMultipolygonTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionTypeNotMultipolygonTest.java @@ -29,6 +29,10 @@ public class IterateByContributionTypeNotMultipolygonTest { private final OSMXmlReader osmXmlTestData = new OSMXmlReader(); TagInterpreter areaDecider; + /** + * Initialize test framework by loading osm XML file and initializing {@link TagInterpreter} and + * {@link GridOSHRelations}. + */ public IterateByContributionTypeNotMultipolygonTest() throws IOException { osmXmlTestData.add("./src/test/resources/different-timestamps/type-not-multipolygon.osm"); areaDecider = new OSMXmlReaderTagInterpreter(osmXmlTestData); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionWaysTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionWaysTest.java index f0e42297f..295ad24c2 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionWaysTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionWaysTest.java @@ -8,6 +8,7 @@ import java.util.EnumSet; import java.util.List; import java.util.stream.Collectors; +import org.heigit.bigspatialdata.oshdb.grid.GridOSHRelations; import org.heigit.bigspatialdata.oshdb.grid.GridOSHWays; import org.heigit.bigspatialdata.oshdb.util.OSHDBBoundingBox; import org.heigit.bigspatialdata.oshdb.util.celliterator.CellIterator.IterateAllEntry; @@ -26,6 +27,10 @@ public class IterateByContributionWaysTest { private final OSMXmlReader osmXmlTestData = new OSMXmlReader(); TagInterpreter areaDecider; + /** + * Initialize test framework by loading osm XML file and initializing {@link TagInterpreter} and + * {@link GridOSHWays}. + */ public IterateByContributionWaysTest() throws IOException { osmXmlTestData.add("./src/test/resources/different-timestamps/way.osm"); areaDecider = new OSMXmlReaderTagInterpreter(osmXmlTestData); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampNotOsmTypeSpecificTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampNotOsmTypeSpecificTest.java index b2037e217..6623b4600 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampNotOsmTypeSpecificTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampNotOsmTypeSpecificTest.java @@ -37,6 +37,10 @@ public class IterateByTimestampNotOsmTypeSpecificTest { TagInterpreter areaDecider; private final List oshRelations = new ArrayList<>(); + /** + * Initialize test framework by loading osm XML file and initializing {@link TagInterpreter} and + * a list of {@link OSHRelation OSHRelations}. + */ public IterateByTimestampNotOsmTypeSpecificTest() throws IOException { osmXmlTestData.add("./src/test/resources/different-timestamps/not-osm-type-specific.osm"); areaDecider = new OSMXmlReaderTagInterpreter(osmXmlTestData); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsNodesTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsNodesTest.java index 9c67c24a3..e18c7b3a3 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsNodesTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsNodesTest.java @@ -9,6 +9,7 @@ import java.util.List; import java.util.stream.Collectors; import org.heigit.bigspatialdata.oshdb.grid.GridOSHNodes; +import org.heigit.bigspatialdata.oshdb.grid.GridOSHRelations; import org.heigit.bigspatialdata.oshdb.index.XYGrid; import org.heigit.bigspatialdata.oshdb.util.OSHDBBoundingBox; import org.heigit.bigspatialdata.oshdb.util.celliterator.CellIterator.IterateByTimestampEntry; @@ -27,6 +28,10 @@ public class IterateByTimestampsNodesTest { private final OSMXmlReader osmXmlTestData = new OSMXmlReader(); TagInterpreter areaDecider; + /** + * Initialize test framework by loading osm XML file and initializing {@link TagInterpreter} and + * {@link GridOSHNodes}. + */ public IterateByTimestampsNodesTest() throws IOException { osmXmlTestData.add("./src/test/resources/different-timestamps/node.osm"); areaDecider = new OSMXmlReaderTagInterpreter(osmXmlTestData); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsRelationsTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsRelationsTest.java index 34318c119..08056a180 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsRelationsTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsRelationsTest.java @@ -29,6 +29,10 @@ public class IterateByTimestampsRelationsTest { private final OSMXmlReader osmXmlTestData = new OSMXmlReader(); TagInterpreter areaDecider; + /** + * Initialize test framework by loading osm XML file and initializing {@link TagInterpreter} and + * {@link GridOSHRelations}. + */ public IterateByTimestampsRelationsTest() throws IOException { osmXmlTestData.add("./src/test/resources/different-timestamps/polygon.osm"); areaDecider = new OSMXmlReaderTagInterpreter(osmXmlTestData); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsWaysTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsWaysTest.java index 541c91c13..3f25c235e 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsWaysTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByTimestampsWaysTest.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.stream.Collectors; import org.heigit.bigspatialdata.oshdb.grid.GridOSHNodes; +import org.heigit.bigspatialdata.oshdb.grid.GridOSHRelations; import org.heigit.bigspatialdata.oshdb.grid.GridOSHWays; import org.heigit.bigspatialdata.oshdb.util.OSHDBBoundingBox; import org.heigit.bigspatialdata.oshdb.util.celliterator.CellIterator.IterateByTimestampEntry; @@ -28,6 +29,10 @@ public class IterateByTimestampsWaysTest { private final OSMXmlReader osmXmlTestData = new OSMXmlReader(); TagInterpreter areaDecider; + /** + * Initialize test framework by loading osm XML file and initializing {@link TagInterpreter} and + * {@link GridOSHWays}. + */ public IterateByTimestampsWaysTest() throws IOException { osmXmlTestData.add("./src/test/resources/different-timestamps/way.osm"); areaDecider = new OSMXmlReaderTagInterpreter(osmXmlTestData); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/helpers/GridOSHFactory.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/helpers/GridOSHFactory.java index 9bff7263d..bb89d4cef 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/helpers/GridOSHFactory.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/helpers/GridOSHFactory.java @@ -27,16 +27,28 @@ /** - * Helper class to get GridOSH's (Holds the basic information, every OSM-Object has at a - * specific level) out of osm-xml file + * Helper class to get GridOSHs (Holds the basic information, every OSM-Object has at a + * specific level) out of osm-xml file. */ public class GridOSHFactory { + /** + * See {@link GridOSHFactory#getGridOSHNodes(OSMXmlReader, int, long)} for details. + */ public static GridOSHNodes getGridOSHNodes(OSMXmlReader osmXmlReader) throws IOException { return getGridOSHNodes(osmXmlReader, -1, -1); } + /** + * Get GridOSHs nodes from a OSM XML with a given zoom level and cell id. + * + * @param osmXmlReader {@link OSMXmlReader} with the input data + * @param cellZoom zoom level to use + * @param cellId cell id to use + * @return {@link GridOSHNodes} object + * @throws IOException thrown for XML file read errors + */ public static GridOSHNodes getGridOSHNodes(OSMXmlReader osmXmlReader, int cellZoom, long cellId) throws IOException { GridOSHNodes oshdbDataGridCellNodes; @@ -50,10 +62,22 @@ public static GridOSHNodes getGridOSHNodes(OSMXmlReader osmXmlReader, int cellZo return oshdbDataGridCellNodes; } + /** + * See {@link GridOSHFactory#getGridOSHWays(OSMXmlReader, int, long)} for details. + */ public static GridOSHWays getGridOSHWays(OSMXmlReader osmXmlReader) throws IOException { return getGridOSHWays(osmXmlReader, -1, -1); } + /** + * Get GridOSHs ways from a OSM XML with a given zoom level and cell id. + * + * @param osmXmlReader {@link OSMXmlReader} with the input data + * @param cellZoom zoom level to use + * @param cellId cell id to use + * @return {@link GridOSHWays} object + * @throws IOException thrown for XML file read errors + */ public static GridOSHWays getGridOSHWays(OSMXmlReader osmXmlReader, int cellZoom, long cellId) throws IOException { GridOSHWays oshdbDataGridCellWays; @@ -71,10 +95,22 @@ public static GridOSHWays getGridOSHWays(OSMXmlReader osmXmlReader, int cellZoom return oshdbDataGridCellWays; } + /** + * See {@link GridOSHFactory#getGridOSHRelations(OSMXmlReader, int, long)} for details. + */ public static GridOSHRelations getGridOSHRelations(OSMXmlReader osmXmlReader) throws IOException { return getGridOSHRelations(osmXmlReader, -1, -1); } + /** + * Get GridOSHs relations from a OSM XML with a given zoom level and cell id. + * + * @param osmXmlReader {@link OSMXmlReader} with the input data + * @param cellZoom zoom level to use + * @param cellId cell id to use + * @return {@link GridOSHRelations} object + * @throws IOException thrown for XML file read errors + */ public static GridOSHRelations getGridOSHRelations(OSMXmlReader osmXmlReader, int cellZoom, long cellId) throws IOException { Map oshNodes = getOSHNodes(osmXmlReader); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxInPolygonTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxInPolygonTest.java index ad04664c0..d6b4379b3 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxInPolygonTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastBboxInPolygonTest.java @@ -12,7 +12,7 @@ public class FastBboxInPolygonTest { /** - * @return a multipolygon of four small squares arranged in a square + * Returns a {@link MultiPolygon} of four small squares arranged in a square. */ public static MultiPolygon createSquareSquareMultiPolygon() { GeometryFactory gf = new GeometryFactory(); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPointInPolygonTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPointInPolygonTest.java index ca42108ea..b296fb92f 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPointInPolygonTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/fip/FastPointInPolygonTest.java @@ -12,7 +12,7 @@ public class FastPointInPolygonTest { /** - * @return a reversed "Σ"-shaped concave polygon + * Returns a reversed "Σ"-shaped concave polygon. */ public static Polygon createPolygon() { final GeometryFactory gf = new GeometryFactory(); @@ -31,7 +31,7 @@ public static Polygon createPolygon() { } /** - * @return a square with a central square hole + * Returns a square with a central square hole. */ public static Polygon createPolygonWithHole() { final GeometryFactory gf = new GeometryFactory(); @@ -53,7 +53,7 @@ public static Polygon createPolygonWithHole() { } /** - * @return a reversed "Σ"-shaped concave polygon next to a square with a central square hole + * Returns a reversed "Σ"-shaped concave polygon next to a square with a central square hole. */ public static MultiPolygon createMultiPolygon() { GeometryFactory gf = new GeometryFactory(); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/helpers/OSMXmlReaderTagInterpreter.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/helpers/OSMXmlReaderTagInterpreter.java index 1bc8a90c7..22308d504 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/helpers/OSMXmlReaderTagInterpreter.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/helpers/OSMXmlReaderTagInterpreter.java @@ -17,6 +17,9 @@ public class OSMXmlReaderTagInterpreter extends FakeTagInterpreter { private int outer; private int inner; + /** + * Constructor reading all required values from a given {@link OSMXmlReader}. + */ public OSMXmlReaderTagInterpreter(OSMXmlReader osmXmlReader) { area = osmXmlReader.keys().getOrDefault("area", -1); areaYes = area == -1 ? -1 : osmXmlReader.keyValues().get(area).getOrDefault("yes", -1); diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/helpers/TimestampParser.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/helpers/TimestampParser.java index 713a6a6b8..27c20b492 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/helpers/TimestampParser.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/helpers/TimestampParser.java @@ -4,6 +4,11 @@ import org.heigit.bigspatialdata.oshdb.util.time.IsoDateTimeParser; public class TimestampParser { + + /** + * Returns an {@link OSHDBTimestamp} converted with + * {@link IsoDateTimeParser#parseIsoDateTime(String)} using a given {@link String timeString}. + */ public static OSHDBTimestamp toOSHDBTimestamp(String timeString) { try { return new OSHDBTimestamp( diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/tagtranslator/TagTranslatorTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/tagtranslator/TagTranslatorTest.java index be2d03667..73d88b6ef 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/tagtranslator/TagTranslatorTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/tagtranslator/TagTranslatorTest.java @@ -16,6 +16,12 @@ public class TagTranslatorTest { private static Connection conn; + /** + * Initialize tests by loading the H2 driver and open a connection via jdbc. + * + * @throws ClassNotFoundException gets thrown if H2 driver class cannot be found + * @throws SQLException is thrown if the connection fails + */ @BeforeClass public static void setUpClass() throws ClassNotFoundException, SQLException { // load H2-support diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/MutableOSMEntity.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/MutableOSMEntity.java index ea370cfbd..905c399b4 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/MutableOSMEntity.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/MutableOSMEntity.java @@ -12,7 +12,10 @@ public class MutableOSMEntity { private long changeset; private int userId; private int[] tags; - + + /** + * Set properties of {@link MutableOSMEntity} with given parameters. + */ public void setEntity(long id, int version, boolean visible, long timestamp, long changeset, int userId, int[] tags) { this.id = id; diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/OSMXmlReader.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/OSMXmlReader.java index 2fb6c3243..b9eaf0312 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/OSMXmlReader.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/xmlreader/OSMXmlReader.java @@ -248,6 +248,11 @@ private void read(Document doc) throws IOException { } } + /** + * Add and read XML files to the database using their URLs. + * + * @param xmlFileUrl URL(s) to use + */ public void add(String... xmlFileUrl) { try { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); @@ -262,6 +267,11 @@ public void add(String... xmlFileUrl) { } } + /** + * Add and read XML files to the database using their file paths. + * + * @param xmlFilePath file path(s) to use + */ public void add(Path... xmlFilePath) { try { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); @@ -353,6 +363,9 @@ private int[] tags(Element e) { return tags; } + /** + * Get attribute {@code name} from {@link Element} {@code e} as {@code long}. + */ public static long attrAsLong(Element e, String name) { Attr attr = e.getAttributeNode(name); if (attr != null) { @@ -361,6 +374,9 @@ public static long attrAsLong(Element e, String name) { throw new NoSuchElementException(e.getLocalName() + " doesn't have a attribute " + name); } + /** + * Get attribute {@code name} from {@link Element} {@code e} as {@code double}. + */ public static double attrAsDouble(Element e, String name) { Attr attr = e.getAttributeNode(name); if (attr != null) { @@ -369,6 +385,9 @@ public static double attrAsDouble(Element e, String name) { throw new NoSuchElementException(e.getTextContent() + " doesn't have a attribute " + name); } + /** + * Get attribute {@code name} from {@link Element} {@code e} as {@code int}. + */ public static int attrAsInt(Element e, String name) { Attr attr = e.getAttributeNode(name); if (attr != null) { @@ -377,6 +396,10 @@ public static int attrAsInt(Element e, String name) { throw new NoSuchElementException(e.getLocalName() + " doesn't have a attribute " + name); } + /** + * Get attribute {@code name} from {@link Element} {@code e} as {@code int} with a default value + * instead of a {@link NoSuchElementException}. + */ public static int attrAsInt(Element e, String name, int defaultValue) { Attr attr = e.getAttributeNode(name); if (attr != null) { @@ -385,6 +408,9 @@ public static int attrAsInt(Element e, String name, int defaultValue) { return defaultValue; } + /** + * Get attribute {@code name} from {@link Element} {@code e} as {@code boolean}. + */ public static boolean attrAsBoolean(Element e, String name) { Attr attr = e.getAttributeNode(name); if (attr != null) { @@ -393,6 +419,10 @@ public static boolean attrAsBoolean(Element e, String name) { throw new NoSuchElementException(e.getLocalName() + " doesn't have a attribute " + name); } + /** + * Get attribute {@code name} from {@link Element} {@code e} as {@code boolean} with a default + * value instead of a {@link NoSuchElementException}. + */ public static boolean attrAsBoolean(Element e, String name, boolean defaultValue) { Attr attr = e.getAttributeNode(name); if (attr != null) { @@ -401,6 +431,9 @@ public static boolean attrAsBoolean(Element e, String name, boolean defaultValue return defaultValue; } + /** + * Get attribute {@code name} from {@link Element} {@code e} as parsed timestamp ({@code long}). + */ public static long attrAsTimestampInSeconds(Element e, String name) { Attr attr = e.getAttributeNode(name); if (attr != null) { @@ -409,6 +442,9 @@ public static long attrAsTimestampInSeconds(Element e, String name) { throw new NoSuchElementException(e.getLocalName() + " doesn't have a attribute " + name); } + /** + * Get attribute {@code name} from {@link Element} {@code e} as {@link String}. + */ public static String attrAsString(Element e, String name) { Attr attr = e.getAttributeNode(name); if (attr != null) { From 4d817d50035e230c033982baa2fa7be38561411a Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Thu, 5 Nov 2020 11:50:21 +0100 Subject: [PATCH 6/9] add missing javadoc to class and main constructor --- .../celliterator/LazyEvaluatedObject.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/celliterator/LazyEvaluatedObject.java b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/celliterator/LazyEvaluatedObject.java index ff06eb959..39a2ae5b0 100644 --- a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/celliterator/LazyEvaluatedObject.java +++ b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/celliterator/LazyEvaluatedObject.java @@ -2,18 +2,38 @@ import java.util.function.Supplier; +/** + * A lazily evaluated object. + * + *

Useful as a wrapper to hold values which are potentially expensive to + * calculate, but might sometimes not be requested.

+ * + * @param the (arbitrary) type of data to hold + */ public class LazyEvaluatedObject implements Supplier { private T value = null; private boolean evaluated = false; private Supplier evaluator; + /** + * Constructs a {@link LazyEvaluatedObject} using a {@code evaluator} (supplier function) which + * returns a value of generic type {@code T}, when requested from this object. + * + * @param evaluator a {@link Supplier} function which returns the value of interest when executed + */ public LazyEvaluatedObject(Supplier evaluator) { this.evaluator = evaluator; } /** - * Generic constructor for a {@link LazyEvaluatedObject} using a {@code value} of generic type - * {@code T}. + * Constructs a {@link LazyEvaluatedObject} using an already known {@code value} of generic + * type {@code T}. + * + *

This simply wraps the value with a supplier method, but can be useful in situations where + * sometimes an expensive to calculate value is already know, but one wants to use the lazy + * evaluated interface for the remaining cases.

+ * + * @param value the value to store */ public LazyEvaluatedObject(T value) { this.value = value; From 5e321d221121365d63f1112821879fb2f5e06c26 Mon Sep 17 00:00:00 2001 From: Johannes Visintini Date: Thu, 5 Nov 2020 11:50:24 +0100 Subject: [PATCH 7/9] fix indent styling of CellIterator --- .../oshdb/util/celliterator/CellIterator.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/celliterator/CellIterator.java b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/celliterator/CellIterator.java index 27dbac6d4..b61a715fd 100644 --- a/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/celliterator/CellIterator.java +++ b/oshdb-util/src/main/java/org/heigit/bigspatialdata/oshdb/util/celliterator/CellIterator.java @@ -321,10 +321,9 @@ public Stream iterateByTimestamps(GridOSHEntity cell) { // skip because this entity is deleted at this timestamp continue; } - if (osmEntity instanceof OSMWay && ( - (OSMWay)osmEntity).getRefs().length == 0 + if (osmEntity instanceof OSMWay && ((OSMWay)osmEntity).getRefs().length == 0 || osmEntity instanceof OSMRelation - && ((OSMRelation)osmEntity).getMembers().length == 0) { + && ((OSMRelation)osmEntity).getMembers().length == 0) { // skip way/relation with zero nodes/members continue; } @@ -363,10 +362,8 @@ public Stream iterateByTimestamps(GridOSHEntity cell) { geom = constructClippedGeometry(osmEntity, timestamp, fullyInside); } else { // old style multipolygons: return only the inner holes of the geometry -> this is then - // used to "fix" the - // results obtained from calculating the geometry on the object's outer way which - // doesn't know about the - // inner members of the multipolygon relation + // used to "fix" the results obtained from calculating the geometry on the object's + // outer way which doesn't know about the inner members of the multipolygon relation // todo: check if this is all valid? GeometryFactory gf = new GeometryFactory(); geom = new LazyEvaluatedObject<>(() -> { @@ -557,7 +554,7 @@ public Stream iterateByContribution(GridOSHEntity cell) { if (!oshEntityPreFilter.test(oshEntity) || !allFullyInside && ( !oshEntity.getBoundingBox().intersects(boundingBox) - || (isBoundByPolygon && bboxOutsidePolygon.test(oshEntity.getBoundingBox())) + || (isBoundByPolygon && bboxOutsidePolygon.test(oshEntity.getBoundingBox())) )) { // this osh entity doesn't match the prefilter or is fully outside the requested // area of interest -> skip it @@ -570,7 +567,7 @@ public Stream iterateByContribution(GridOSHEntity cell) { boolean fullyInside = allFullyInside || ( oshEntity.getBoundingBox().isInside(boundingBox) - && (!isBoundByPolygon || bboxInPolygon.test(oshEntity.getBoundingBox())) + && (!isBoundByPolygon || bboxInPolygon.test(oshEntity.getBoundingBox())) ); Map changesetTs = OSHEntities.getChangesetTimestamps(oshEntity); From 33b9af4a846bb7c9ff68285f77dbd1a4209d5d6f Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Thu, 5 Nov 2020 12:08:18 +0100 Subject: [PATCH 8/9] fix another typo --- .../util/celliterator/IterateByContributionRelationsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionRelationsTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionRelationsTest.java index 8e7ad4fef..41bfb948a 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionRelationsTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/celliterator/IterateByContributionRelationsTest.java @@ -65,7 +65,7 @@ public void testGeometryChange() { )).iterateByContribution( oshdbDataGridCell ).collect(Collectors.toList()); - // one creation and two geomotry changes should give a result with 3 elements + // one creation and two geometry changes should give a result with 3 elements assertEquals(3, result.size()); // check if the contribution types are correct assertEquals( From 19770a5a33f4fd009af7fd8ae8a4df5dae746aff Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Thu, 5 Nov 2020 12:20:01 +0100 Subject: [PATCH 9/9] drop empty comment --- .../bigspatialdata/oshdb/util/time/IsoDateTimeParserTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/IsoDateTimeParserTest.java b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/IsoDateTimeParserTest.java index 444fde1c5..e1144c776 100644 --- a/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/IsoDateTimeParserTest.java +++ b/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/time/IsoDateTimeParserTest.java @@ -92,7 +92,6 @@ public void throwsPosTimezoneHh_MmParseIsoDateTime() { parseIsoDateTime(posTimezoneHhMm); } - // @Test(expected = OSHDBTimestampException.class) public void throwsNegTimezoneHhParseIsoDateTime() { String negTimezoneHh = "2020-02-17T23:55-02";