Refactor loadEntity

This commit is contained in:
Chumva 2018-09-06 11:26:42 +03:00
parent fed4db96e5
commit 8e9044652d

View file

@ -79,24 +79,25 @@ public class OpenstreetmapLocalUtil implements OpenstreetmapUtil {
} }
return newEntity; return newEntity;
} }
@Override @Override
public Entity loadEntity(MapObject mapObject) { public Entity loadEntity(MapObject mapObject) {
boolean amenity = mapObject instanceof Amenity; Amenity amenity = null;
PoiType poiType = null;
if (amenity) {
poiType = ((Amenity) mapObject).getType().getPoiTypeByKeyName(((Amenity) mapObject).getSubType());
}
boolean isWay = mapObject.getId() % 2 == 1; // check if amenity is a way
if (poiType == null && amenity) {
return null;
}
long entityId; long entityId;
boolean isWay = mapObject.getId() % 2 == 1; // check if mapObject is a way
if (mapObject instanceof Amenity) { if (mapObject instanceof Amenity) {
amenity = (Amenity) mapObject;
entityId = mapObject.getId() >> 1; entityId = mapObject.getId() >> 1;
} else { } else {
entityId = mapObject.getId() >> 7; entityId = mapObject.getId() >> 7;
} }
PoiType poiType = null;
if (amenity != null) {
poiType = amenity.getType().getPoiTypeByKeyName(amenity.getSubType());
}
if (poiType == null && mapObject instanceof Amenity) {
return null;
}
Entity entity; Entity entity;
LatLon loc = mapObject.getLocation(); LatLon loc = mapObject.getLocation();
@ -124,11 +125,11 @@ public class OpenstreetmapLocalUtil implements OpenstreetmapUtil {
if (!Algorithms.isEmpty(mapObject.getName())) { if (!Algorithms.isEmpty(mapObject.getName())) {
entity.putTagNoLC(OSMTagKey.NAME.getValue(), mapObject.getName()); entity.putTagNoLC(OSMTagKey.NAME.getValue(), mapObject.getName());
} }
if (amenity) { if (amenity != null) {
if (!Algorithms.isEmpty(((Amenity) mapObject).getOpeningHours())) { if (!Algorithms.isEmpty(amenity.getOpeningHours())) {
entity.putTagNoLC(OSMTagKey.OPENING_HOURS.getValue(), ((Amenity) mapObject).getOpeningHours()); entity.putTagNoLC(OSMTagKey.OPENING_HOURS.getValue(), amenity.getOpeningHours());
} }
for (Map.Entry<String, String> entry : ((Amenity) mapObject).getAdditionalInfo().entrySet()) { for (Map.Entry<String, String> entry : amenity.getAdditionalInfo().entrySet()) {
AbstractPoiType abstractPoi = MapPoiTypes.getDefault().getAnyPoiAdditionalTypeByKey(entry.getKey()); AbstractPoiType abstractPoi = MapPoiTypes.getDefault().getAnyPoiAdditionalTypeByKey(entry.getKey());
if (abstractPoi != null && abstractPoi instanceof PoiType) { if (abstractPoi != null && abstractPoi instanceof PoiType) {
PoiType p = (PoiType) abstractPoi; PoiType p = (PoiType) abstractPoi;
@ -140,7 +141,7 @@ public class OpenstreetmapLocalUtil implements OpenstreetmapUtil {
} }
// check whether this is node (because id of node could be the same as relation) // check whether this is node (because id of node could be the same as relation)
if (entity instanceof Node && MapUtils.getDistance(entity.getLatLon(), mapObject.getLocation()) < 50) { if (entity instanceof Node && MapUtils.getDistance(entity.getLatLon(), loc) < 50) {
return entity; return entity;
} else if (entity instanceof Way) { } else if (entity instanceof Way) {
return entity; return entity;