From ae79a97c0f29489a7d0eb745503be49c991cffe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Racha=C5=84ski?= Date: Sun, 3 Jan 2021 21:54:13 +0100 Subject: [PATCH] Spotless java. --- .../BoundaryIntersectionCheck.java | 230 +++++++++--------- .../intersections/BoundaryPart.java | 1 - .../intersections/RelationBoundary.java | 20 +- .../BoundaryIntersectionCheckTestRule.java | 6 +- 4 files changed, 124 insertions(+), 133 deletions(-) diff --git a/src/main/java/org/openstreetmap/atlas/checks/validation/intersections/BoundaryIntersectionCheck.java b/src/main/java/org/openstreetmap/atlas/checks/validation/intersections/BoundaryIntersectionCheck.java index 032205d8f..38f2e1108 100644 --- a/src/main/java/org/openstreetmap/atlas/checks/validation/intersections/BoundaryIntersectionCheck.java +++ b/src/main/java/org/openstreetmap/atlas/checks/validation/intersections/BoundaryIntersectionCheck.java @@ -81,26 +81,19 @@ protected List getFallbackInstructions() return FALLBACK_INSTRUCTIONS; } - private void addInstruction(final Set instructions, - final BoundaryPart lineItem, - final long osmIdentifier, - final Coordinate[] intersectingPoints, - final String firstBoundaries, - final String secondBoundaries) + private void addInstruction(final Set instructions, final BoundaryPart lineItem, + final long osmIdentifier, final Coordinate[] intersectingPoints, + final String firstBoundaries, final String secondBoundaries) { - final String instruction = this.getLocalizedInstruction(INDEX, - firstBoundaries, - Long.toString(lineItem.getOsmIdentifier()), - secondBoundaries, - Long.toString(osmIdentifier), - this.coordinatesToList(intersectingPoints)); + final String instruction = this.getLocalizedInstruction(INDEX, firstBoundaries, + Long.toString(lineItem.getOsmIdentifier()), secondBoundaries, + Long.toString(osmIdentifier), this.coordinatesToList(intersectingPoints)); instructions.add(instruction); } private boolean checkAreaAsBoundary(final Area area, final Set boundaryTags) { - return area - .relations().stream() + return area.relations().stream() .anyMatch(relationToCheck -> BoundaryIntersectionCheck .isRelationTypeBoundaryWithBoundaryTag(relationToCheck) && boundaryTags.contains(relationToCheck.getTag(BOUNDARY).get())) @@ -109,8 +102,7 @@ private boolean checkAreaAsBoundary(final Area area, final Set boundaryT private boolean checkLineItemAsBoundary(final LineItem lineItem, final Set boundaryTags) { - return lineItem - .relations().stream() + return lineItem.relations().stream() .anyMatch(relationToCheck -> BoundaryIntersectionCheck .isRelationTypeBoundaryWithBoundaryTag(relationToCheck) && boundaryTags.contains(relationToCheck.getTag(BOUNDARY).get())) @@ -127,45 +119,41 @@ private String coordinatesToList(final Coordinate[] locations) private Set getBoundaries(final LineItem currentLineItem) { final Set relations = currentLineItem.relations().stream() - .filter(relation -> relation instanceof MultiRelation) - .map(AtlasEntity::relations) - .flatMap(Collection::stream) - .collect(Collectors.toSet()); + .filter(relation -> relation instanceof MultiRelation).map(AtlasEntity::relations) + .flatMap(Collection::stream).collect(Collectors.toSet()); relations.addAll(currentLineItem.relations()); - return relations.stream().filter(BoundaryIntersectionCheck::isRelationTypeBoundaryWithBoundaryTag) + return relations.stream() + .filter(BoundaryIntersectionCheck::isRelationTypeBoundaryWithBoundaryTag) .collect(Collectors.toSet()); } private Set getBoundaries(final Area area) { final Set relations = area.relations().stream() - .filter(relation -> relation instanceof MultiRelation) - .map(AtlasEntity::relations) - .flatMap(Collection::stream) - .collect(Collectors.toSet()); + .filter(relation -> relation instanceof MultiRelation).map(AtlasEntity::relations) + .flatMap(Collection::stream).collect(Collectors.toSet()); relations.addAll(area.relations()); - return relations.stream().filter(BoundaryIntersectionCheck::isRelationTypeBoundaryWithBoundaryTag) + return relations.stream() + .filter(BoundaryIntersectionCheck::isRelationTypeBoundaryWithBoundaryTag) .collect(Collectors.toSet()); } private Set getBoundaryParts(final Relation relation) { - final RelationMemberList relationMemberLineItems = relation.membersOfType(ItemType.EDGE, ItemType.LINE, ItemType.AREA); - return relationMemberLineItems - .stream().map(RelationMember::getEntity) - .map(entity -> - { - final String tag = entity.getTags().get(BOUNDARY); - final Set boundaryTags = entity.relations() - .stream() - .filter(currentRelation -> BOUNDARY.equals(currentRelation.getTag(TYPE).get())) - .map(currentRelation -> currentRelation.getTag(BOUNDARY).orElse(StringUtils.EMPTY)) - .collect(Collectors.toSet()); - boundaryTags.add(tag); - boundaryTags.remove(StringUtils.EMPTY); - return new BoundaryPart(entity, boundaryTags); - }) - .collect(Collectors.toSet()); + final RelationMemberList relationMemberLineItems = relation.membersOfType(ItemType.EDGE, + ItemType.LINE, ItemType.AREA); + return relationMemberLineItems.stream().map(RelationMember::getEntity).map(entity -> + { + final String tag = entity.getTags().get(BOUNDARY); + final Set boundaryTags = entity.relations().stream() + .filter(currentRelation -> BOUNDARY.equals(currentRelation.getTag(TYPE).get())) + .map(currentRelation -> currentRelation.getTag(BOUNDARY) + .orElse(StringUtils.EMPTY)) + .collect(Collectors.toSet()); + boundaryTags.add(tag); + boundaryTags.remove(StringUtils.EMPTY); + return new BoundaryPart(entity, boundaryTags); + }).collect(Collectors.toSet()); } private Geometry getGeometryForIntersection(final String wktFirst) throws ParseException @@ -180,8 +168,7 @@ private Geometry getGeometryForIntersection(final String wktFirst) throws ParseE return geometry1; } - private Coordinate[] getIntersectionPoints(final String wktFirst, - final String wktSecond) + private Coordinate[] getIntersectionPoints(final String wktFirst, final String wktSecond) { try { @@ -197,35 +184,38 @@ private Coordinate[] getIntersectionPoints(final String wktFirst, private List getLineItems(final LineItem lineItem) { - if(lineItem instanceof MultiLine) + if (lineItem instanceof MultiLine) { final List lines = new ArrayList<>(); - ((MultiLine) lineItem).getSubLines() - .forEach(lines::add); + ((MultiLine) lineItem).getSubLines().forEach(lines::add); return lines; } return Collections.singletonList(lineItem); } - private Predicate getPredicateForAreaSelection(final BoundaryPart boundaryPart, final Set boundaryTags) + private Predicate getPredicateForAreaSelection(final BoundaryPart boundaryPart, + final Set boundaryTags) { return areaToCheck -> { if (this.checkAreaAsBoundary(areaToCheck, boundaryTags)) { - return this.isCrossingNotTouching(boundaryPart.getWktGeometry(), areaToCheck.toWkt()); + return this.isCrossingNotTouching(boundaryPart.getWktGeometry(), + areaToCheck.toWkt()); } return false; }; } - private Predicate getPredicateForLineItemsSelection(final BoundaryPart boundaryPart, final Set boundaryTags) + private Predicate getPredicateForLineItemsSelection(final BoundaryPart boundaryPart, + final Set boundaryTags) { return lineItemToCheck -> { if (this.checkLineItemAsBoundary(lineItemToCheck, boundaryTags)) { - return this.isCrossingNotTouching(boundaryPart.getWktGeometry(), lineItemToCheck.toWkt()); + return this.isCrossingNotTouching(boundaryPart.getWktGeometry(), + lineItemToCheck.toWkt()); } return false; }; @@ -234,12 +224,12 @@ private Predicate getPredicateForLineItemsSelection(final BoundaryPart private Map getRelationMap(final AtlasObject object) { final Map tagToRelation = new HashMap<>(); - if(object instanceof MultiRelation) + if (object instanceof MultiRelation) { - ((MultiRelation) object).relations() - .stream() + ((MultiRelation) object).relations().stream() .filter(BoundaryIntersectionCheck::isRelationTypeBoundaryWithBoundaryTag) - .forEach(relation -> tagToRelation.put(relation.getTag(BOUNDARY).get(), relation)); + .forEach(relation -> tagToRelation.put(relation.getTag(BOUNDARY).get(), + relation)); } tagToRelation.put(object.getTag(BOUNDARY).get(), (Relation) object); return tagToRelation; @@ -247,7 +237,8 @@ private Map getRelationMap(final AtlasObject object) private boolean isAnyGeometryInvalid(final Geometry geometry1, final Geometry geometry2) { - return !geometry1.isValid() || !geometry1.isSimple() || !geometry2.isValid() || !geometry2.isSimple(); + return !geometry1.isValid() || !geometry1.isSimple() || !geometry2.isValid() + || !geometry2.isSimple(); } private boolean isCrossingNotTouching(final String wktFirst, final String wktSecond) @@ -257,11 +248,11 @@ private boolean isCrossingNotTouching(final String wktFirst, final String wktSec { final Geometry geometry1 = wktReader.read(wktFirst); final Geometry geometry2 = wktReader.read(wktSecond); - if(geometry1.equals(geometry2)) + if (geometry1.equals(geometry2)) { return false; } - if(this.isAnyGeometryInvalid(geometry1, geometry2)) + if (this.isAnyGeometryInvalid(geometry1, geometry2)) { return false; } @@ -275,54 +266,52 @@ private boolean isCrossingNotTouching(final String wktFirst, final String wktSec private boolean isGeometryPairOfLineType(final Geometry lineString, final Geometry lineString2) { - return lineString.getGeometryType().equals(Geometry.TYPENAME_LINESTRING) && lineString2.getGeometryType().equals(Geometry.TYPENAME_LINESTRING); + return lineString.getGeometryType().equals(Geometry.TYPENAME_LINESTRING) + && lineString2.getGeometryType().equals(Geometry.TYPENAME_LINESTRING); } private boolean isIntersectingNotTouching(final Geometry geometry1, final Geometry geometry2) { - return geometry1.intersects(geometry2) && - (geometry1.crosses(geometry2) || (geometry1.overlaps(geometry2) && !this.isGeometryPairOfLineType(geometry1, geometry2))); + return geometry1.intersects(geometry2) + && (geometry1.crosses(geometry2) || (geometry1.overlaps(geometry2) + && !this.isGeometryPairOfLineType(geometry1, geometry2))); } private String objectsToString(final Set objects) { - return objects - .stream() - .map(object -> Long.toString(object.getOsmIdentifier())) + return objects.stream().map(object -> Long.toString(object.getOsmIdentifier())) .collect(Collectors.joining(DELIMITER)); } private void processAreas(final RelationBoundary relationBoundary, - final Set instructions, - final Set objectsToFlag, - final Set matchedTags, - final BoundaryPart currentBoundaryPart, - final Iterable areasIntersecting, - final Set currentMatchedTags) + final Set instructions, final Set objectsToFlag, + final Set matchedTags, final BoundaryPart currentBoundaryPart, + final Iterable areasIntersecting, final Set currentMatchedTags) { areasIntersecting.forEach(area -> { - final Set matchingBoundaries = this.getBoundaries(area) - .stream() - .filter(boundary -> relationBoundary.getTagToRelation().containsKey(boundary.getTag(BOUNDARY).orElse(StringUtils.EMPTY))) - .filter(boundary -> !relationBoundary.containsRelationId(boundary.getOsmIdentifier())) + final Set matchingBoundaries = this.getBoundaries(area).stream() + .filter(boundary -> relationBoundary.getTagToRelation() + .containsKey(boundary.getTag(BOUNDARY).orElse(StringUtils.EMPTY))) + .filter(boundary -> !relationBoundary + .containsRelationId(boundary.getOsmIdentifier())) .collect(Collectors.toSet()); - if(!matchingBoundaries.isEmpty()) + if (!matchingBoundaries.isEmpty()) { - currentMatchedTags.addAll(matchingBoundaries - .stream() - .map(relation -> relation.getTag(BOUNDARY)) - .filter(Optional::isPresent) - .map(Optional::get) - .collect(Collectors.toSet())); + currentMatchedTags.addAll(matchingBoundaries.stream() + .map(relation -> relation.getTag(BOUNDARY)).filter(Optional::isPresent) + .map(Optional::get).collect(Collectors.toSet())); objectsToFlag.addAll(matchingBoundaries); - final Coordinate[] intersectingPoints = this.getIntersectionPoints(currentBoundaryPart.getWktGeometry(), - area.toWkt()); - final String firstBoundaries = this.objectsToString(relationBoundary.getRelationsByBoundaryTags(currentMatchedTags)); + final Coordinate[] intersectingPoints = this + .getIntersectionPoints(currentBoundaryPart.getWktGeometry(), area.toWkt()); + final String firstBoundaries = this.objectsToString( + relationBoundary.getRelationsByBoundaryTags(currentMatchedTags)); final String secondBoundaries = this.objectsToString(matchingBoundaries); - if(intersectingPoints.length != 0 && firstBoundaries.hashCode() < secondBoundaries.hashCode()) + if (intersectingPoints.length != 0 + && firstBoundaries.hashCode() < secondBoundaries.hashCode()) { - this.addInstruction(instructions, currentBoundaryPart, area.getOsmIdentifier(), intersectingPoints, firstBoundaries, secondBoundaries); + this.addInstruction(instructions, currentBoundaryPart, area.getOsmIdentifier(), + intersectingPoints, firstBoundaries, secondBoundaries); } } matchedTags.addAll(currentMatchedTags); @@ -330,41 +319,40 @@ private void processAreas(final RelationBoundary relationBoundary, } private void processLineItems(final RelationBoundary relationBoundary, - final Set instructions, - final Set objectsToFlag, - final Set matchedTags, - final BoundaryPart currentBoundaryPart, - final Iterable lineItemsIntersecting, - final Set currentMatchedTags) + final Set instructions, final Set objectsToFlag, + final Set matchedTags, final BoundaryPart currentBoundaryPart, + final Iterable lineItemsIntersecting, final Set currentMatchedTags) { lineItemsIntersecting.forEach(lineItem -> { - final Set matchingBoundaries = this.getBoundaries(lineItem) - .stream() - .filter(boundary -> relationBoundary.getTagToRelation().containsKey(boundary.getTag(BOUNDARY).get())) - .filter(boundary -> !relationBoundary.containsRelationId(boundary.getOsmIdentifier())) + final Set matchingBoundaries = this.getBoundaries(lineItem).stream() + .filter(boundary -> relationBoundary.getTagToRelation() + .containsKey(boundary.getTag(BOUNDARY).get())) + .filter(boundary -> !relationBoundary + .containsRelationId(boundary.getOsmIdentifier())) .collect(Collectors.toSet()); - if(!matchingBoundaries.isEmpty()) + if (!matchingBoundaries.isEmpty()) { - currentMatchedTags.addAll(matchingBoundaries - .stream() - .map(relation -> relation.getTag(BOUNDARY)) - .filter(Optional::isPresent) - .map(Optional::get) - .collect(Collectors.toSet())); + currentMatchedTags.addAll(matchingBoundaries.stream() + .map(relation -> relation.getTag(BOUNDARY)).filter(Optional::isPresent) + .map(Optional::get).collect(Collectors.toSet())); objectsToFlag.addAll(matchingBoundaries); final List lineItems = this.getLineItems(lineItem); lineItems.forEach(line -> { objectsToFlag.add(line); - final Coordinate[] intersectingPoints = this.getIntersectionPoints(currentBoundaryPart.getWktGeometry(), - line.toWkt()); - final String firstBoundaries = this.objectsToString(relationBoundary.getRelationsByBoundaryTags(currentMatchedTags)); + final Coordinate[] intersectingPoints = this.getIntersectionPoints( + currentBoundaryPart.getWktGeometry(), line.toWkt()); + final String firstBoundaries = this.objectsToString( + relationBoundary.getRelationsByBoundaryTags(currentMatchedTags)); final String secondBoundaries = this.objectsToString(matchingBoundaries); - if(intersectingPoints.length != 0 && firstBoundaries.hashCode() < secondBoundaries.hashCode()) + if (intersectingPoints.length != 0 + && firstBoundaries.hashCode() < secondBoundaries.hashCode()) { - this.addInstruction(instructions, currentBoundaryPart, line.getOsmIdentifier(), intersectingPoints, firstBoundaries, secondBoundaries); + this.addInstruction(instructions, currentBoundaryPart, + line.getOsmIdentifier(), intersectingPoints, firstBoundaries, + secondBoundaries); } }); } @@ -375,29 +363,35 @@ private void processLineItems(final RelationBoundary relationBoundary, private Optional processRelation(final AtlasObject object) { final Map tagToRelation = this.getRelationMap(object); - final RelationBoundary relationBoundary = new RelationBoundary(tagToRelation, this.getBoundaryParts((Relation) object)); + final RelationBoundary relationBoundary = new RelationBoundary(tagToRelation, + this.getBoundaryParts((Relation) object)); final Set instructions = new HashSet<>(); final Set objectsToFlag = new HashSet<>(); final Set matchedTags = new HashSet<>(); - for(final BoundaryPart currentBoundaryPart : relationBoundary.getBoundaryParts()) + for (final BoundaryPart currentBoundaryPart : relationBoundary.getBoundaryParts()) { - final Iterable lineItemsIntersecting = object.getAtlas().lineItemsIntersecting(currentBoundaryPart.getBounds(), - this.getPredicateForLineItemsSelection(currentBoundaryPart, relationBoundary.getTagToRelation().keySet())); - final Iterable areasIntersecting = object.getAtlas().areasIntersecting(currentBoundaryPart.getBounds(), - this.getPredicateForAreaSelection(currentBoundaryPart, relationBoundary.getTagToRelation().keySet())); + final Iterable lineItemsIntersecting = object.getAtlas() + .lineItemsIntersecting(currentBoundaryPart.getBounds(), + this.getPredicateForLineItemsSelection(currentBoundaryPart, + relationBoundary.getTagToRelation().keySet())); + final Iterable areasIntersecting = object.getAtlas().areasIntersecting( + currentBoundaryPart.getBounds(), this.getPredicateForAreaSelection( + currentBoundaryPart, relationBoundary.getTagToRelation().keySet())); final Set currentMatchedTags = new HashSet<>(); - this.processLineItems(relationBoundary, instructions, objectsToFlag, matchedTags, currentBoundaryPart, lineItemsIntersecting, currentMatchedTags); - this.processAreas(relationBoundary, instructions, objectsToFlag, matchedTags, currentBoundaryPart, areasIntersecting, currentMatchedTags); + this.processLineItems(relationBoundary, instructions, objectsToFlag, matchedTags, + currentBoundaryPart, lineItemsIntersecting, currentMatchedTags); + this.processAreas(relationBoundary, instructions, objectsToFlag, matchedTags, + currentBoundaryPart, areasIntersecting, currentMatchedTags); objectsToFlag.addAll(relationBoundary.getRelationsByBoundaryTags(matchedTags)); objectsToFlag.add(currentBoundaryPart.getAtlasEntity()); } - if(instructions.isEmpty()) + if (instructions.isEmpty()) { return Optional.empty(); } else - { + { final CheckFlag checkFlag = new CheckFlag(this.getTaskIdentifier(object)); instructions.forEach(checkFlag::addInstruction); checkFlag.addObjects(objectsToFlag); diff --git a/src/main/java/org/openstreetmap/atlas/checks/validation/intersections/BoundaryPart.java b/src/main/java/org/openstreetmap/atlas/checks/validation/intersections/BoundaryPart.java index b5f1ed115..56dacf83a 100644 --- a/src/main/java/org/openstreetmap/atlas/checks/validation/intersections/BoundaryPart.java +++ b/src/main/java/org/openstreetmap/atlas/checks/validation/intersections/BoundaryPart.java @@ -5,7 +5,6 @@ import org.openstreetmap.atlas.geography.Rectangle; import org.openstreetmap.atlas.geography.atlas.items.AtlasEntity; - /** * @author srachanski */ diff --git a/src/main/java/org/openstreetmap/atlas/checks/validation/intersections/RelationBoundary.java b/src/main/java/org/openstreetmap/atlas/checks/validation/intersections/RelationBoundary.java index cb878802a..6d938c290 100644 --- a/src/main/java/org/openstreetmap/atlas/checks/validation/intersections/RelationBoundary.java +++ b/src/main/java/org/openstreetmap/atlas/checks/validation/intersections/RelationBoundary.java @@ -11,11 +11,12 @@ */ public class RelationBoundary { - + private final Map tagToRelation; private final Set boundaryParts; - - public RelationBoundary(final Map tagToRelation, final Set boundaryParts) + + public RelationBoundary(final Map tagToRelation, + final Set boundaryParts) { this.tagToRelation = tagToRelation; this.boundaryParts = boundaryParts; @@ -23,9 +24,7 @@ public RelationBoundary(final Map tagToRelation, final Set id == osmIdentifier); } @@ -33,14 +32,11 @@ public Set getBoundaryParts() { return this.boundaryParts; } - + public Set getRelationsByBoundaryTags(final Set tags) { - return this.tagToRelation.keySet() - .stream() - .filter(tags::contains) - .map(this.tagToRelation::get) - .collect(Collectors.toSet()); + return this.tagToRelation.keySet().stream().filter(tags::contains) + .map(this.tagToRelation::get).collect(Collectors.toSet()); } public Map getTagToRelation() diff --git a/src/test/java/org/openstreetmap/atlas/checks/validation/intersections/BoundaryIntersectionCheckTestRule.java b/src/test/java/org/openstreetmap/atlas/checks/validation/intersections/BoundaryIntersectionCheckTestRule.java index 2e2638bf9..feebebdf5 100644 --- a/src/test/java/org/openstreetmap/atlas/checks/validation/intersections/BoundaryIntersectionCheckTestRule.java +++ b/src/test/java/org/openstreetmap/atlas/checks/validation/intersections/BoundaryIntersectionCheckTestRule.java @@ -114,7 +114,8 @@ public class BoundaryIntersectionCheckTestRule extends CoreTestRule @TestAtlas(nodes = { @Node(coordinates = @Loc(value = COORD_1)), @Node(coordinates = @Loc(value = COORD_2)), @Node(coordinates = @Loc(value = COORD_3)), @Node(coordinates = @Loc(value = COORD_4)), @Node(coordinates = @Loc(value = COORD_5)), - @Node(coordinates = @Loc(value = COORD_6)), @Node(coordinates = @Loc(value = COORD_20)) }, lines = { + @Node(coordinates = @Loc(value = COORD_6)), + @Node(coordinates = @Loc(value = COORD_20)) }, lines = { @Line(coordinates = { @Loc(value = COORD_1), @Loc(value = COORD_2), @Loc(value = COORD_3), @Loc(value = COORD_4), @Loc(value = COORD_1) }, id = LINE_ONE, tags = { "type=boundary", @@ -131,7 +132,8 @@ public class BoundaryIntersectionCheckTestRule extends CoreTestRule @TestAtlas(nodes = { @Node(coordinates = @Loc(value = COORD_1)), @Node(coordinates = @Loc(value = COORD_2)), @Node(coordinates = @Loc(value = COORD_3)), @Node(coordinates = @Loc(value = COORD_4)), @Node(coordinates = @Loc(value = COORD_5)), - @Node(coordinates = @Loc(value = COORD_6)), @Node(coordinates = @Loc(value = COORD_20)) }, edges = { + @Node(coordinates = @Loc(value = COORD_6)), + @Node(coordinates = @Loc(value = COORD_20)) }, edges = { @Edge(coordinates = { @Loc(value = COORD_1), @Loc(value = COORD_2), @Loc(value = COORD_3), @Loc(value = COORD_4), @Loc(value = COORD_1) }, id = EDGE_ONE),