@Override protected Optional<CheckFlag> flag(final AtlasObject object) { final List<Tuple<Angle, Location>> allSpikyAngles = this.getPolygons(object) .map(this::getSpikyAngleLocations) .filter(angleLocations -> !angleLocations.isEmpty()).flatMap(Collection::stream) .collect(Collectors.toList()); if (!allSpikyAngles.isEmpty()) { final String instruction = this .getLocalizedInstruction(0, allSpikyAngles.stream().map(Tuple::getFirst).map(Angle::toString) .collect(Collectors.joining(", ")), headingThreshold.toString()); final List<Location> markers = allSpikyAngles.stream().map(Tuple::getSecond) .collect(Collectors.toList()); final CheckFlag flag; if (object instanceof Area) { flag = this.createFlag(object, instruction, markers); } else { flag = this.createFlag(((Relation) object).flatten(), instruction, markers); } return Optional.of(flag); } return Optional.empty(); }
@Test public void testNestedRelation() { final Relation nestedRelation = this.rule.getAtlas().relation(10); logger.info("Nested Relation: {}", nestedRelation); final Set<AtlasObject> flattened = nestedRelation.flatten(); logger.info("Flattened: {}", flattened); assertEquals(6, flattened.size()); }
@Test public void testLoopingRelation() { final Relation loopingRelation = this.rule.getAtlas().relation(8); logger.info("Looping (self-containing) Relation: {}", loopingRelation); final Set<AtlasObject> flattened = loopingRelation.flatten(); logger.info("Flattened: {}", flattened); assertEquals(2, flattened.size()); }
@Test public void testNodesAndRelationsWithSameId() { final Relation relation = this.rule.getAtlas().relation(1); logger.info("Relation containing nodes and relations with the same numeric id: {}", relation); final Set<AtlasObject> flattened = relation.flatten(); logger.info("Flattened: {}", flattened); assertEquals(5, flattened.size()); }
@Test public void testShallowRelation() { final Relation shallowRelation = this.rule.getAtlas().relation(6); logger.info("Shallow (1-node) relation: {}", shallowRelation); final Set<AtlasObject> flattened = shallowRelation.flatten(); logger.info("Flattened: {}", flattened); assertEquals(1, flattened.size()); final AtlasObject memberNode = flattened.stream().findFirst().get(); if (memberNode instanceof Node) { assertEquals(1, ((Node) memberNode).getIdentifier()); } else { Assert.fail("Member was not the expected type of 'Node'!"); } } }