private boolean isValid() { return this.from != null && this.too != null && route() != null; } }
final Route path = turnRestriction.route(); switch (turnRestriction.getTurnRestrictionType())
/** * Proxy for TurnRestriction.route() * * @return The Route represented by this {@link ComplexTurnRestriction} */ public Route route() { if (this.turnRestriction != null) { return this.turnRestriction.route(); } else { return null; } }
@Override public Rectangle bounds() { if (!isValid()) { throw new CoreException("An invalid TurnRestriction cannot be Located."); } return route().bounds(); }
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); } }
@SuppressWarnings("deprecation") public LocationIterableProperties asGeoJson() { final Map<String, String> tagsNo = Maps.hashMap("highway", "primary", "oneway", "yes", "type", "NO"); final Map<String, String> tagsOnly = Maps.hashMap("highway", "primary", "oneway", "yes", "type", "ONLY"); return new LocationIterableProperties(this.route().asPolyLine(), this.getTurnRestrictionType() == TurnRestrictionType.NO ? tagsNo : tagsOnly); }