@Override public long getIdentifier() { return this.source.getIdentifier(); }
@Override public int indexOf(final Edge edge) { return this.edge.getIdentifier() == edge.getIdentifier() ? 0 : -1; }
/** * @param candidate * candidate for reverseEdge * @return {@code true} if candidate is the reverse of this {@link Edge} */ public boolean isReversedEdge(final Edge candidate) { return this.getIdentifier() == -candidate.getIdentifier(); }
public long getMasterEdgeIdentifier() { return Math.abs(this.getIdentifier()); }
@Override public int compare(final Edge left, final Edge right) { return Long.compare( this.reverseIdentifierFactory.getWaySectionIndex(left.getIdentifier()), this.reverseIdentifierFactory.getWaySectionIndex(right.getIdentifier())); } }
/** * Checks if edge is a master edge, by verifying that its identifier is a master edge * identifier. * * @return True if the edge's identifier is a master edge identifier */ public boolean isMasterEdge() { return isMasterEdgeIdentifier(this.getIdentifier()); }
private SortedSet<Long> connectedEdgesIdentifiers( final Supplier<SortedSet<Edge>> getConnectedEdges) { final SortedSet<Long> result = new TreeSet<>(); getConnectedEdges.get().forEach(edge -> result.add(edge.getIdentifier())); return result; } }
/** * @return An {@link Edge} that is reversed to this one if it exists, empty otherwise. */ public Optional<Edge> reversed() { final Edge edge = this.getAtlas().edge(-this.getIdentifier()); if (edge != null) { return Optional.of(edge); } return Optional.empty(); }
/** * @return {@code true} if there is a reverse edge to this one */ public boolean hasReverseEdge() { return this.getAtlas().edge(-this.getIdentifier()) != null; }
/** * @return the master for this {@link Edge}, which may or may not be the master. */ public Edge getMasterEdge() { return this.isMasterEdge() ? this : this.reversed() .orElseThrow(() -> new CoreException( "Reverse edge should be available for edge {}", this.getIdentifier())); }
@Override public SortedSet<Edge> inEdges() { return subNode().inEdges().stream() .map(edge -> new DynamicEdge(dynamicAtlas(), edge.getIdentifier())) .collect(Collectors.toCollection(TreeSet::new)); }
@Override public SortedSet<Edge> outEdges() { return subNode().outEdges().stream() .map(edge -> new DynamicEdge(dynamicAtlas(), edge.getIdentifier())) .collect(Collectors.toCollection(TreeSet::new)); }
public static CompleteEdge from(final Edge edge) { return new CompleteEdge(edge.getIdentifier(), edge.asPolyLine(), edge.getTags(), edge.start().getIdentifier(), edge.end().getIdentifier(), edge.relations().stream().map(Relation::getIdentifier).collect(Collectors.toSet())); }
public static CompleteEdge shallowFrom(final Edge edge) { return new CompleteEdge(edge.getIdentifier()).withInitialBounds(edge.asPolyLine().bounds()); }
private boolean canAddEdgeToBoundary(final Edge edge, final Route boundary) { return edge.getIdentifier() != -boundary.end().getIdentifier() && edge.getOsmIdentifier() == boundary.end().getOsmIdentifier() && boundary.end().end().getLocation().equals(edge.start().getLocation()) && !boundary.includes(edge); } }
private String convertEdge(final Edge item) { final StringList list = new StringList(); list.add(item.getIdentifier()); list.add(item.asPolyLine().toCompactString()); list.add(convertTags(item)); return list.join(SEPARATOR); }
@Override public String toDiffViewFriendlyString() { final String relationsString = this.parentRelationsAsDiffViewFriendlyString(); return "[Edge" + ": id=" + this.getIdentifier() + ", startNode=" + start().getIdentifier() + ", endNode=" + end().getIdentifier() + ", polyLine=" + this.asPolyLine().toWkt() + ", relations=(" + relationsString + "), " + tagString() + "]"; }
@Test public void spatialIndexTest() { final Rectangle ac2Box = Location.TEST_1.boxAround(Distance.ONE_METER); Assert.assertEquals(1, Iterables.size(this.multi.nodesWithin(ac2Box))); Assert.assertEquals(4L, this.multi.nodesWithin(ac2Box).iterator().next().getIdentifier()); Assert.assertEquals(2, Iterables.size(this.multi.edgesIntersecting(ac2Box))); final Iterator<Edge> edgeIterator = this.multi.edgesIntersecting(ac2Box).iterator(); Assert.assertEquals(6, edgeIterator.next().getIdentifier()); Assert.assertEquals(5, edgeIterator.next().getIdentifier()); Assert.assertFalse(edgeIterator.hasNext()); }
@Test(expected = CoreException.class) public void testGetIndex() { Assert.assertEquals(98, this.route.get(0).getIdentifier()); Assert.assertEquals(987, this.route.get(1).getIdentifier()); this.route.get(-7); Assert.fail("Should complain about wrong index"); this.route.get(7); Assert.fail("Should complain about wrong index"); }
@Test public void connectivityTest() { this.multi.forEach(atlasItem -> logger.trace(atlasItem.toString())); // Out edges of CC2: 987 Assert.assertEquals(1, this.multi.edge(6).end().outEdges().size()); Assert.assertEquals(987, this.multi.edge(6).end().outEdges().iterator().next().getIdentifier()); Assert.assertEquals(2, this.multi.edge(-9).end().outEdges().size()); Assert.assertEquals(2, this.multi.edge(-9).end().inEdges().size()); Assert.assertEquals(2, this.multi.edge(987).start().inEdges().size()); }