@Override public Set<Relation> relations() { return this.source.relations(); }
/** * Collects relations from given edges * * @param edges * Edges to use for relation extraction * @return Relations per relation identifier collected from given edges */ private Set<TemporaryRelation> collectRelations(final List<Edge> edges) { final Set<TemporaryRelation> relations = new HashSet<>(); edges.forEach(edge -> edge.relations() .forEach(relation -> relations.add(new TemporaryRelation(relation)))); return relations; }
/** * Check if identical edges in the new {@link MultiAtlas} have consistent parent relations. It * is possible the the same {@link Edge} may have a different set of parent relations depending * on which subatlas is was pulled from. In this case, we want to detect this so we can unify * the sets. * * @param identifierToEdgeList * A mapping from edge identifiers to list of edges with that identifier * @return Indicator whether relations are consistent across identical edges */ private boolean hasInconsistentRelations(final MultiMap<Long, Edge> identifierToEdgeList) { for (final Long edgeListForSameIdentifier : identifierToEdgeList.keySet()) { final List<Edge> valuesForCurrentKey = identifierToEdgeList .get(edgeListForSameIdentifier); final Edge firstEdge = valuesForCurrentKey.get(0); final Set<Relation> masterRelations = firstEdge.relations(); for (int index = 1; index < valuesForCurrentKey.size(); index++) { final Edge comparisonEdge = valuesForCurrentKey.get(index); final Set<Relation> candidateRelations = comparisonEdge.relations(); if (!Objects.equals(masterRelations, candidateRelations)) { return true; } } } return false; }
@Override public Set<Relation> relations() { return subEdge().relations().stream() .map(relation -> new DynamicRelation(dynamicAtlas(), relation.getIdentifier())) .collect(Collectors.toSet()); }
@Override protected boolean isCounted(final Edge edge) { if (edge.containsKey(EXACT_MATCHES)) { return true; } if (edge.containsKeyStartsWith(START_WITH_MATCHES)) { return true; } for (final Relation relation : edge.relations()) { final Map<String, String> tags = relation.getTags(); if (tags.containsKey("type") && "route".equals(tags.get("type")) && tags.containsKey("route") && "road".equals(tags.get("route"))) { if (relation.containsKey(RELATION_EXACT_MATCHES)) { return true; } if (relation.containsKeyStartsWith(RELATION_START_WITH_MATCHES)) { return true; } } } return false; }
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())); }
this.nodeIdentifiersToRemovedOutEdges.add(edge.start().getIdentifier(), edgeIdentifier); edge.relations().forEach(relation -> this.relationIdentifiersToRemovedEdgeMembers .add(relation.getIdentifier(), edgeIdentifier)); this.nodeIdentifiersToRemovedOutEdges.add(edge.end().getIdentifier(), reversedEdgeIdentifier); edge.relations() .forEach(relation -> this.relationIdentifiersToRemovedEdgeMembers .add(relation.getIdentifier(), reversedEdgeIdentifier));
@Test public void splitRoundaboutEdges() { resetAndChange("splitRoundaboutEdges", new AtlasChangeGeneratorSplitRoundabout()); Assert.assertEquals(6, Iterables.size(this.atlas.edges(JunctionTag::isRoundabout))); Assert.assertEquals(12, Iterables.size(this.changeAtlas.edges(JunctionTag::isRoundabout))); final Set<Long> extectedParentRelations = this.atlas.edge(221434104000005L).relations() .stream().map(Relation::getIdentifier).collect(Collectors.toSet()); Assert.assertEquals(extectedParentRelations, this.changeAtlas.edge(14L).relations().stream() .map(Relation::getIdentifier).collect(Collectors.toSet())); Assert.assertEquals(extectedParentRelations, this.changeAtlas.edge(15L).relations().stream() .map(Relation::getIdentifier).collect(Collectors.toSet())); Assert.assertTrue(this.changeAtlas.relation(3001321000000L).members().asBean() .getItemFor(14L, ItemType.EDGE).isPresent()); Assert.assertTrue(this.changeAtlas.relation(3001321000000L).members().asBean() .getItemFor(15L, ItemType.EDGE).isPresent()); Assert.assertTrue(this.atlas.relation(3001321000000L).members().asBean() .getItemFor(221434104000005L, ItemType.EDGE).isPresent()); // Make sure the removed edge was not added back by a mishap in the relation bean merging // somewhere Assert.assertFalse(this.changeAtlas.relation(3001321000000L).members().asBean() .getItemFor(221434104000005L, ItemType.EDGE).isPresent()); }
final Set<Relation> relations = edge.relations(); for (final Relation relation : relations)
@Test public void testShallow() { final Atlas atlas = this.rule.getAtlas(); final Edge source = atlas.edge(3); final CompleteEdge result = CompleteEdge.shallowFrom(source); Assert.assertEquals(source.getIdentifier(), result.getIdentifier()); Assert.assertEquals(source.bounds(), result.bounds()); result.withPolyLine(PolyLine.TEST_POLYLINE); Assert.assertEquals(PolyLine.TEST_POLYLINE.bounds(), result.bounds()); final Map<String, String> tags = Maps.hashMap("key", "value"); result.withTags(tags); Assert.assertEquals(tags, result.getTags()); final long startNodeIdentifier = 5; result.withStartNodeIdentifier(startNodeIdentifier); Assert.assertEquals(startNodeIdentifier, result.start().getIdentifier()); final long endNodeIdentifier = 6; result.withEndNodeIdentifier(endNodeIdentifier); Assert.assertEquals(endNodeIdentifier, result.end().getIdentifier()); result.withRelationIdentifiers(source.relations().stream().map(Relation::getIdentifier) .collect(Collectors.toSet())); Assert.assertEquals( source.relations().stream().map(Relation::getIdentifier) .collect(Collectors.toSet()), result.relations().stream().map(Relation::getIdentifier) .collect(Collectors.toSet())); } }
@Test public void testFull() { final Atlas atlas = this.rule.getAtlas(); final Edge source = atlas.edge(3); final CompleteEdge result = CompleteEdge.from(source); Assert.assertEquals(source.getIdentifier(), result.getIdentifier()); Assert.assertEquals(source.bounds(), result.bounds()); Assert.assertEquals(source.asPolyLine(), result.asPolyLine()); Assert.assertEquals(source.start().getIdentifier(), result.start().getIdentifier()); Assert.assertEquals(source.end().getIdentifier(), result.end().getIdentifier()); Assert.assertEquals(source.getTags(), result.getTags()); Assert.assertEquals( source.relations().stream().map(Relation::getIdentifier) .collect(Collectors.toSet()), result.relations().stream().map(Relation::getIdentifier) .collect(Collectors.toSet())); }
@Test public void testOneWaySubAtlasWithRelations() { final Atlas subAtlas1 = this.setup.oneWaySubAtlas1From1To3WithRelations(); final Atlas subAtlas2 = this.setup.oneWaySubAtlas2From1To3WithRelations(); final MultiAtlas multiAtlas = new MultiAtlas(subAtlas1, subAtlas2); // Verify first edge verifyEdge(multiAtlas.edge(123456789120001L), MultiAtlasBorderFixerTestRule.POINT_1_LOCATION, MultiAtlasBorderFixerTestRule.POINT_2_LOCATION); // Verify second edge verifyEdge(multiAtlas.edge(123456789120002L), MultiAtlasBorderFixerTestRule.POINT_2_LOCATION, MultiAtlasBorderFixerTestRule.POINT_3_LOCATION); // Verify relations Assert.assertEquals(multiAtlas.edge(123456789120001L).relations().size(), 2); Assert.assertEquals(multiAtlas.edge(123456789120002L).relations().size(), 2); // Verify that relation has members Assert.assertEquals(multiAtlas.relation(987654321L).members().size(), 2); Assert.assertEquals(multiAtlas.relation(887654321L).members().size(), 2); }
result.add(FeatureChange .add(CompleteEdge.shallowFrom(inEdge).withRelationIdentifiers( mergeRelationMembers(inEdge.relations(), relationIdentifier)))); if (inEdge.hasReverseEdge()) FeatureChange.add(CompleteEdge.shallowFrom(inEdge.reversed().get()) .withRelationIdentifiers(mergeRelationMembers( inEdge.relations(), relationIdentifier)))); mergeRelationMembers(node.relations(), relationIdentifier)))); result.add(FeatureChange.add(CompleteEdge.shallowFrom(outEdge) .withRelationIdentifiers(mergeRelationMembers(outEdge.relations(), relationIdentifier)))); if (outEdge.hasReverseEdge()) FeatureChange.add(CompleteEdge.shallowFrom(outEdge.reversed().get()) .withRelationIdentifiers(mergeRelationMembers( outEdge.relations(), relationIdentifier))));
edge.relations().stream().map(relation ->
resourceNoRelation); Assert.assertTrue(!multiAtlas.edge(1L).relations().isEmpty());