/** * This function will validate if the supplied atlas object is valid for the check. * * @param object * the atlas object supplied by the Atlas-Checks framework for evaluation * @return {@code true} if this object should be checked */ @Override public boolean validCheckForObject(final AtlasObject object) { // We only need to check for Point's because by definition a Node will be connected to an // Edge. return object instanceof Point && object.getOsmTags().size() == 0 && ((Point) object).relations().size() == 0; }
/** * Check if the {@link Point} with the given identifier is a {@link Relation} member in the * given {@link Atlas}. * * @param atlas * The {@link Atlas} to check * @param pointIdentifier * The {@link Point} identifier to use * @return {@code true} if the given {@link Point} identifier is a {@link Relation} member in * the given {@link Atlas} */ private boolean isRelationMember(final Atlas atlas, final long pointIdentifier) { return !atlas.point(pointIdentifier).relations().isEmpty(); }
public static CompletePoint from(final Point point) { return new CompletePoint(point.getIdentifier(), point.getLocation(), point.getTags(), point .relations().stream().map(Relation::getIdentifier).collect(Collectors.toSet())); }
@Override public Set<Relation> relations() { return subPoint().relations().stream() .map(relation -> new DynamicRelation(dynamicAtlas(), relation.getIdentifier())) .collect(Collectors.toSet()); }
/** * This check determines whether an entity is part of an associated street relation. * * @param object * An Atlas entity * @return True if the point is part of an associated street relation, false otherwise. */ private boolean hasAssociatedStreetRelation(final AtlasObject object) { final Point point = (Point) object; return point.relations().stream() .filter(relation -> Validators.isOfType(relation, RelationTypeTag.class, RelationTypeTag.ASSOCIATEDSTREET)) .anyMatch(relation -> relation.members().stream() .anyMatch(member -> member.getRole().equals(STREET_RELATION_ROLE) && member.getEntity().getType().equals(ItemType.EDGE))); } }
final boolean isRelationMember = !point.relations().isEmpty();
@Test public void testFull() { final Atlas atlas = this.rule.getAtlas(); final Point source = atlas.point(33); final CompletePoint result = CompletePoint.from(source); Assert.assertEquals(source.getIdentifier(), result.getIdentifier()); Assert.assertEquals(source.bounds(), result.bounds()); Assert.assertEquals(source.getLocation(), result.getLocation()); 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())); }
result.withTags(tags); Assert.assertEquals(tags, result.getTags()); 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)
@Test public void testPointsForMissingRelation() { final PackedAtlasBuilder builderWithRelation = new PackedAtlasBuilder(); builderWithRelation.addPoint(1L, Location.forString("1,1"), Maps.hashMap("somePoint", "inTwoAtlases")); final RelationBean bean = new RelationBean(); bean.addItem(1L, "Point appears in multiple atlases, but parent relation is only in one atlas", ItemType.POINT); builderWithRelation.addRelation(2, 2, bean, Maps.hashMap()); final PackedAtlasBuilder builderNoRelation = new PackedAtlasBuilder(); builderNoRelation.addPoint(1L, Location.forString("1,1"), Maps.hashMap("somePoiont", "inTwoAtlases")); final PackedAtlas atlasWithRelation = (PackedAtlas) builderWithRelation.get(); final PackedAtlas atlasNoRelation = (PackedAtlas) builderNoRelation.get(); // 1 MiB resources final ByteArrayResource resourceWithRelation = new ByteArrayResource(1024 * 1024 * 1); final ByteArrayResource resourceNoRelation = new ByteArrayResource(1024 * 1024 * 1); atlasWithRelation.save(resourceWithRelation); atlasNoRelation.save(resourceNoRelation); /* * Add the Atlas that is missing the relation second so that it overwrites the first one. * See the MultiAtlas.populateReferences() function to see this overwrite happen. */ final Atlas multiAtlas = new AtlasResourceLoader().load(resourceWithRelation, resourceNoRelation); Assert.assertTrue(!multiAtlas.point(1L).relations().isEmpty()); }