private static String computeKey(final long identifier, final ItemType type, final ChangeAction action) { return identifier + type.toShortString() + action; }
/** * @return The entity this {@link Diff} represents in the newer Atlas. null if this Diff is of * type "REMOVED" */ public AtlasEntity getAfterEntity() { return this.itemType.entityForIdentifier(this.after, this.identifier); }
@Test public void testToShotsString() { Assert.assertEquals("N", ItemType.NODE.toShortString()); Assert.assertEquals("E", ItemType.EDGE.toShortString()); Assert.assertEquals("A", ItemType.AREA.toShortString()); Assert.assertEquals("L", ItemType.LINE.toShortString()); Assert.assertEquals("P", ItemType.POINT.toShortString()); Assert.assertEquals("R", ItemType.RELATION.toShortString()); Assert.assertEquals(ItemType.NODE, ItemType.shortValueOf("N")); Assert.assertEquals(ItemType.EDGE, ItemType.shortValueOf("E")); Assert.assertEquals(ItemType.AREA, ItemType.shortValueOf("A")); Assert.assertEquals(ItemType.LINE, ItemType.shortValueOf("L")); Assert.assertEquals(ItemType.POINT, ItemType.shortValueOf("P")); Assert.assertEquals(ItemType.RELATION, ItemType.shortValueOf("R")); } }
/** * Converts a RelationMember to a polygon if that member is an area. * * @param member * any RelationMember object * @return an polygon containing the geometry of member if it is an area, otherwise an empty * optional. */ private Optional<Polygon> toPolygon(final RelationMember member) { if (member.getEntity().getType().equals(ItemType.AREA)) { return Optional.of(((Area) member.getEntity()).asPolygon()); } return Optional.empty(); }
private String convertRelationBean(final Relation relation) { final StringList bean = new StringList(); for (final RelationMember member : relation.members()) { final StringList list = new StringList(); list.add(member.getEntity().getIdentifier()); list.add(member.getRole()); final ItemType type = ItemType.forEntity(member.getEntity()); list.add(type.toShortString()); bean.add(list.join(TERTIARY_SEPARATOR)); } return bean.join(SECONDARY_SEPARATOR); }
@Test public void testGetMemberClass() { Assert.assertEquals(Node.class, ItemType.NODE.getMemberClass()); Assert.assertEquals(Edge.class, ItemType.EDGE.getMemberClass()); Assert.assertEquals(Area.class, ItemType.AREA.getMemberClass()); Assert.assertEquals(Line.class, ItemType.LINE.getMemberClass()); Assert.assertEquals(Point.class, ItemType.POINT.getMemberClass()); Assert.assertEquals(Relation.class, ItemType.RELATION.getMemberClass()); }
public ItemType getItemType() { return ItemType.forEntity(getReference()); }
private RelationBean parseRelationBean(final String value) { final RelationBean bean = new RelationBean(); final StringList split = StringList.split(value, SECONDARY_SEPARATOR); for (final String beanValue : split) { final StringList valueSplit = StringList.split(beanValue, TERTIARY_SEPARATOR); final long identifier = Long.parseLong(valueSplit.get(0)); final String role = valueSplit.get(1); final ItemType itemType = ItemType.shortValueOf(valueSplit.get(2)); bean.addItem(identifier, role, itemType); } return bean; }
private void writeRelationsToBuilder(final Atlas atlas, final ProtoAtlas.Builder protoAtlasBuilder) { long numberOfRelations = 0; for (final Relation relation : atlas.relations()) { final ProtoRelation.Builder protoRelationBuilder = ProtoRelation.newBuilder(); protoRelationBuilder.setId(relation.getIdentifier()); for (final RelationMember member : relation.members()) { final ProtoRelation.RelationBean.Builder beanBuilder = ProtoRelation.RelationBean .newBuilder(); beanBuilder.setMemberId(member.getEntity().getIdentifier()); beanBuilder.setMemberRole(member.getRole()); final ItemType type = ItemType.forEntity(member.getEntity()); beanBuilder.setMemberType(ProtoRelation.ProtoItemType.valueOf(type.getValue())); protoRelationBuilder.addBeans(beanBuilder.build()); } final Map<String, String> tags = relation.getTags(); protoRelationBuilder .addAllTags(ProtoAtlasBuilder.PROTOTAG_LIST_CONVERTER.backwardConvert(tags)); numberOfRelations++; protoAtlasBuilder.addRelations(protoRelationBuilder.build()); } protoAtlasBuilder.setNumberOfRelations(numberOfRelations); } }
private RelationBean parseRelationBean(final ProtoRelation protoRelation) { final RelationBean bean = new RelationBean(); protoRelation.getBeansList().forEach(protoRelationBean -> { final long memberId = protoRelationBean.getMemberId(); final String memberRole = protoRelationBean.getMemberRole(); final ItemType memberType = ItemType .forValue(protoRelationBean.getMemberType().getNumber()); bean.addItem(memberId, memberRole, memberType); }); return bean; }
@Override public int compareTo(final Diff other) { if (this.getDiffType() != other.getDiffType()) { return this.getDiffType().compareTo(other.getDiffType()); } if (this.getItemType() != other.getItemType()) { return this.itemType.compareTo(other.getItemType()); } final long deltaIdentifier = this.getIdentifier() - other.getIdentifier(); return deltaIdentifier > 0 ? 1 : deltaIdentifier == 0 ? 0 : -1; }
@Override public boolean equals(final Object other) { if (other instanceof TemporaryRelationMember) { final TemporaryRelationMember that = (TemporaryRelationMember) other; return this.getIdentifier() == that.getIdentifier() && this.getRole().equals(that.role) && this.getType().equals(that.getType()); } return false; }
Iterables.stream(this.entities(type, type.getMemberClass())) .map(entity -> (M) entity).forEach(temporaryIndex::add); globalIndexConsumer.accept(temporaryIndex);
ItemType.forEntity(member.getEntity()));
for (final byte typeValue : this.relationMemberTypes().get(index)) final ItemType type = ItemType.forValue(typeValue); final long memberIndex = this.relationMemberIndices().get(index)[arrayIndex]; final String role = this.dictionary()
/** * Similar to {@link BaseCheck#getUniqueOSMIdentifier(AtlasObject)} except instead of using the * OSM identifier we use the Atlas identifier * * @param object * {@link AtlasObject} to generate unique identifier for * @return unique object identifier among different types */ protected String getUniqueObjectIdentifier(final AtlasObject object) { if (object instanceof AtlasEntity) { return String.format("%s%s", ((AtlasEntity) object).getType().toShortString(), object.getIdentifier()); } else { return String.format("%s%s", object.getClass().getSimpleName(), object.getIdentifier()); } }
/** * @return The entity this {@link Diff} represents in the older Atlas. null if this Diff is of * type "ADDED" */ public AtlasEntity getBeforeEntity() { return this.itemType.entityForIdentifier(this.before, this.identifier); }
/** * 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))); } }