private static String computeKey(final long identifier, final ItemType type, final ChangeAction action) { return identifier + type.toShortString() + action; }
/** * Generates a unique identifier given an {@link AtlasObject}. OSM/Atlas objects with different * types can share the identifier (way 12345 - node 12345). This method makes sure we generate a * truly unique identifier, based on the OSM identifier, among different types for an * {@link AtlasObject}. If the AtlasObject is an instanceof AtlasEntity then it will simply use * the type for the first part of the identifier, otherwise it will use the simple class name. * * @param object * {@link AtlasObject} to generate unique identifier for * @return unique object identifier among different types */ protected String getUniqueOSMIdentifier(final AtlasObject object) { if (object instanceof AtlasEntity) { return String.format("%s%s", ((AtlasEntity) object).getType().toShortString(), object.getOsmIdentifier()); } else { return String.format("%s%s", object.getClass().getSimpleName(), object.getIdentifier()); } }
/** * 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()); } }
@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")); } }
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); }