@Override protected Optional<CheckFlag> flag(final AtlasObject object) { final Optional<CheckFlag> result; final Relation relation = (Relation) object; if (!TurnRestriction.from(relation).isPresent()) { final Set<AtlasObject> members = relation.members().stream() .map(RelationMember::getEntity).collect(Collectors.toSet()); result = Optional.of(createFlag(members, this.getLocalizedInstruction(0, relation.getOsmIdentifier()))); } else { result = Optional.empty(); } return result; }
protected ComplexTurnRestriction(final AtlasEntity source, final Predicate<Edge> validEdge) { super(source); try { this.turnRestriction = TurnRestriction.from((Relation) source) .orElseThrow(() -> new CoreException( "{} is not a turn restriction according to Atlas", source.getIdentifier())); final Route route = this.turnRestriction.route(); final int routeLength = route.size(); if (routeLength < 2) { throw new CoreException("Must have at least two edges in the route"); } final long filteredLength = StreamSupport.stream(route.spliterator(), false) .filter(validEdge).count(); if (filteredLength < routeLength) { throw new CoreException("{} invalid edges", routeLength - filteredLength); } } catch (final Exception oops) { logger.trace("Unable to create ComplexTurnRestriction from {}", source, oops); setInvalidReason("Couldn't create ComplexTurnRestriction", oops); } }
@Test public void testTurnRestrictionWithTwoViaNodesInRelation() { final Atlas testAtlas = this.rule.getRelationWithTwoViaNodes(); logger.trace("Atlas relation with 2 via nodes: {}", testAtlas); // For more than 1 via nodes in relation for restriction, TurnRestriction will always // return an empty optional final Optional<TurnRestriction> possibleTurnRestriction = TurnRestriction .from(testAtlas.relation(1L)); Assert.assertEquals(Optional.empty(), possibleTurnRestriction); }
@Test public void testTurnRestrictionNoUTurn() { // Test edge as via member final Atlas testAtlas = this.rule.getAtlasNoUTurn(); final Optional<TurnRestriction> possibleTurnRestriction = TurnRestriction .from(testAtlas.relation(1L)); Assert.assertTrue(possibleTurnRestriction.isPresent()); } }
.from(relation); if (turnRestrictionOption.isPresent())