/** * @return The absolute valence, considering all {@link Edge}s, irrespective of * bi-directionality. */ public long absoluteValence() { return this.connectedEdges().size(); }
/** * @return The valence considering only the master {@link Edge}s */ public long valence() { return this.connectedEdges().stream().filter(Edge::isMasterEdge).count(); }
/** * Get all of the Edges which are connected to this Node and are car-navigable, as per * {@link HighwayTag#isCarNavigableHighway(Taggable)}. * * @param node * The Node from which to gather connected Edges. * @return The Edges that are connected to this Node and are car-navigable. */ private Collection<Edge> getCarNavigableEdges(final Node node) { return node.connectedEdges().stream().filter(HighwayTag::isCarNavigableHighway) .collect(Collectors.toSet()); }
/** * @return All the {@link Edge}s linked to this {@link BigNode} */ public Set<Edge> edges() { if (this.edges == null) { this.edges = this.nodes.stream().flatMap(node -> { return node.connectedEdges().stream().filter(HighwayTag::isCarNavigableHighway); }).collect(Collectors.toSet()); } return this.edges; }
private static boolean aConnectedNodeHasValenceLessThan(final Edge edge, final int valence) { return edge // go through each connected node of given edge .connectedNodes().stream() // check if any of them has less than given valence value .anyMatch(node -> node.connectedEdges().stream() // counting only master edge connections .filter(Edge::isMasterEdge).count() < valence); }
/** * @return All the {@link Edge}s connected to the end {@link Node}s of this {@link Edge}, except * self. If this {@link Edge} is a two-way road, then the reversed {@link Edge} will be * included in the set. */ public Set<Edge> connectedEdges() { final Set<Edge> result = new HashSet<>(); for (final Edge edge : this.end().connectedEdges()) { if (!this.equals(edge)) { result.add(edge); } } for (final Edge edge : this.start().connectedEdges()) { if (!this.equals(edge)) { result.add(edge); } } return result; }
/** * @return All the {@link Edge}s connected to the start/end {@link Node}s of this {@link Route}, * excluding {@link Edge}s in {@link Route}. If this {@link Edge} is a {@link Route} * with two-way road, then the reversed {@link Edge}s will be included in the set. This * does not include {@link Edge} connected to the interior {@link Node}s of the * {@link Route}. */ public Set<Edge> connectedEdges() { final Set<Edge> result = new HashSet<>(); for (final Edge edge : this.end().end().connectedEdges()) { if (!this.includes(edge)) { result.add(edge); } } for (final Edge edge : this.start().start().connectedEdges()) { if (!this.includes(edge)) { result.add(edge); } } return result; }
if (!this.bigNodeIdentifiers.contains(candidateNode.getIdentifier())) if (candidateNode.connectedEdges().stream() .anyMatch(HighwayTag::isCarNavigableHighway))
for (final Node node : roundaboutNodes) final int nodeValence = node.connectedEdges().stream() .filter(currentEdge -> HighwayTag.isCarNavigableHighway(currentEdge) && currentEdge.isMasterEdge() && !JunctionTag.isRoundabout(currentEdge)
private Optional<Route> buildHighwayAreaBoundary(final Route boundary) { for (final Edge edge : boundary.end().end().connectedEdges()) { if (canAddEdgeToBoundary(edge, boundary)) { final Route extendedBoundary = boundary.append(edge); if (extendedBoundary.end().end().getLocation() .equals(extendedBoundary.start().start().getLocation())) { return Optional.of(extendedBoundary); } else { return buildHighwayAreaBoundary(extendedBoundary); } } } return Optional.empty(); }
@Test public void testLineWithLoopInMiddle() { // Loosely based on https://www.openstreetmap.org/way/460419987 - with a new added node final Atlas slicedRawAtlas = this.setup.getLineWithLoopInMiddleAtlas(); final Atlas finalAtlas = new WaySectionProcessor(slicedRawAtlas, AtlasLoadingOption.createOptionWithAllEnabled(COUNTRY_BOUNDARY_MAP)).run(); Assert.assertEquals("Four edges, each having a reverse counterpart", 8, finalAtlas.numberOfEdges()); Assert.assertEquals("Four nodes", 4, finalAtlas.numberOfNodes()); Assert.assertEquals(2, finalAtlas.node(4560902695000000L).connectedEdges().size()); Assert.assertEquals(4, finalAtlas.node(4560902693000000L).connectedEdges().size()); Assert.assertEquals(2, finalAtlas.node(4560902612000000L).connectedEdges().size()); Assert.assertEquals(6, finalAtlas.node(4560902689000000L).connectedEdges().size()); // Explicit check for expected identifiers Assert.assertTrue(finalAtlas.edge(460419987000001L) != null); Assert.assertTrue(finalAtlas.edge(-460419987000001L) != null); Assert.assertTrue(finalAtlas.edge(460419987000002L) != null); Assert.assertTrue(finalAtlas.edge(-460419987000003L) != null); Assert.assertTrue(finalAtlas.edge(460419987000003L) != null); Assert.assertTrue(finalAtlas.edge(-460419987000003L) != null); Assert.assertTrue(finalAtlas.edge(460419987000004L) != null); Assert.assertTrue(finalAtlas.edge(-460419987000004L) != null); }
@Test public void testLineWithLoopAtStart() { // Based on https://www.openstreetmap.org/way/460419987 final Atlas slicedRawAtlas = this.setup.getLineWithLoopAtStartAtlas(); final Atlas finalAtlas = new WaySectionProcessor(slicedRawAtlas, AtlasLoadingOption.createOptionWithAllEnabled(COUNTRY_BOUNDARY_MAP)).run(); Assert.assertEquals("Three edges, each having a reverse counterpart", 6, finalAtlas.numberOfEdges()); Assert.assertEquals("Three nodes", 3, finalAtlas.numberOfNodes()); Assert.assertEquals(4, finalAtlas.node(4560902689000000L).connectedEdges().size()); Assert.assertEquals(2, finalAtlas.node(4560902695000000L).connectedEdges().size()); Assert.assertEquals(4, finalAtlas.node(4560902693000000L).connectedEdges().size()); // Explicit check for expected identifiers Assert.assertTrue(finalAtlas.edge(460419987000001L) != null); Assert.assertTrue(finalAtlas.edge(-460419987000001L) != null); Assert.assertTrue(finalAtlas.edge(460419987000002L) != null); Assert.assertTrue(finalAtlas.edge(-460419987000002L) != null); Assert.assertTrue(finalAtlas.edge(460419987000003L) != null); Assert.assertTrue(finalAtlas.edge(-460419987000003L) != null); }
Assert.assertFalse( getField(deserialized, PackedAtlas.FIELD_NODE_OUT_EDGES_INDICES) != null); final Set<Edge> connectedEdges = node.connectedEdges(); Assert.assertTrue(getField(deserialized, PackedAtlas.FIELD_EDGE_IDENTIFIERS) != null); Assert.assertTrue(getField(deserialized, PackedAtlas.FIELD_NODE_IN_EDGES_INDICES) != null);
@Test public void testLineWithLoopAtEnd() { // Based on https://www.openstreetmap.org/way/461101743 final Atlas slicedRawAtlas = this.setup.getLineWithLoopAtEndAtlas(); final Atlas finalAtlas = new WaySectionProcessor(slicedRawAtlas, AtlasLoadingOption.createOptionWithAllEnabled(COUNTRY_BOUNDARY_MAP)).run(); Assert.assertEquals("Two edges, each having a reverse counterpart", 4, finalAtlas.numberOfEdges()); Assert.assertEquals("Two nodes", 2, finalAtlas.numberOfNodes()); Assert.assertEquals(4, finalAtlas.node(4566499618000000L).connectedEdges().size()); Assert.assertEquals(2, finalAtlas.node(4566499619000000L).connectedEdges().size()); // Explicit check for expected identifiers Assert.assertTrue(finalAtlas.edge(461101743000001L) != null); Assert.assertTrue(finalAtlas.edge(-461101743000001L) != null); Assert.assertTrue(finalAtlas.edge(461101743000002L) != null); Assert.assertTrue(finalAtlas.edge(-461101743000002L) != null); }
if (node.connectedEdges().stream().anyMatch(connectedEdge -> matchedEdgeIdentifiers .contains(connectedEdge.getIdentifier())))