refactoring

This commit is contained in:
Dima-1 2021-01-29 13:40:01 +02:00
parent 30c5fda90a
commit 74ffdbeba5
3 changed files with 39 additions and 41 deletions

View file

@ -179,26 +179,6 @@ public class Amenity extends MapObject {
}
}
public void addProfileTag(Entry<String, String> e) {
if (getAdditionalInfo("profile") == null) {
if (e.getKey().startsWith("tag_")) {
switch (e.getValue().trim()) {
case "bicycle":
case "cycling":
case "mtb":
setAdditionalInfo("profile", "bicycle");
break;
case "hiking":
case "hike":
case "walking":
case "walk":
setAdditionalInfo("profile", "pedestrian");
break;
}
}
}
}
@Override
public String toStringEn() {
return super.toStringEn() + ": " + type.getKeyName() + ":" + subType;

View file

@ -922,11 +922,7 @@ public class MapPoiTypes {
}
}
pat = poiTypesByTag.get(otag);
if (pat == null && otag.startsWith("tag_")) {
a.addProfileTag(e);
}
}
if (pat != null && pat.isAdditional()) {
a.setAdditionalInfo(pat.getKeyName(), e.getValue());
}

View file

@ -21,7 +21,7 @@ import net.osmand.osm.edit.Relation.RelationMember;
import net.osmand.util.Algorithms;
public class EntityParser {
public static void parseMapObject(MapObject mo, Entity e, Map<String, String> tags) {
mo.setId(e.getId());
if(mo instanceof Amenity) {
@ -123,7 +123,7 @@ public class EntityParser {
mo.setName(ref);
}
}
private static void setNameFromBrand(MapObject mo, Map<String, String> tags) {
String ref = tags.get(OSMTagKey.BRAND.getValue());
if(ref != null){
@ -140,7 +140,7 @@ public class EntityParser {
op += " [" + ref + "]";
mo.setName(op);
}
private static String getWebSiteURL(Map<String, String> tagValues, boolean checkWikipedia) {
String siteUrl = null;
@ -170,14 +170,14 @@ public class EntityParser {
}
return siteUrl;
}
public static List<Amenity> parseAmenities(MapPoiTypes poiTypes, Entity entity, Map<String, String> tags,
List<Amenity> amenitiesList) {
amenitiesList.clear();
// it could be collection of amenities
boolean relation = entity instanceof Relation;
boolean purerelation = relation &&
boolean purerelation = relation &&
!("multipolygon".equals(tags.get("type")) || "boundary".equals(tags.get("type")));
Collection<Map<String, String>> it = MapRenderingTypes.splitTagsIntoDifferentObjects(tags);
for (Map<String, String> ts : it) {
@ -193,6 +193,10 @@ public class EntityParser {
if (wbs != null) {
am.setAdditionalInfo("wikipedia", wbs);
}
String tagCategory = getTagCategory(entity);
if (tagCategory != null) {
am.setAdditionalInfo("profile", tagCategory);
}
if (checkAmenitiesToAdd(am, amenitiesList) && !"no".equals(am.getSubType())) {
amenitiesList.add(am);
}
@ -201,9 +205,27 @@ public class EntityParser {
}
return amenitiesList;
}
private static String getTagCategory(Entity e) {
Map<String, String> tags = e.getTags();
for (String key : tags.keySet()) {
if (key.startsWith("tag_")) {
switch (tags.get(key).trim()) {
case "bicycle":
case "cycling":
case "mtb":
return "bicycle";
case "hiking":
case "hike":
case "walking":
case "walk":
return "pedestrian";
}
}
}
return null;
}
private static boolean checkAmenitiesToAdd(Amenity a, List<Amenity> amenitiesList){
// check amenity for duplication
for(Amenity b : amenitiesList){
@ -212,9 +234,9 @@ public class EntityParser {
}
}
return true;
}
public static Building parseBuilding(Entity e){
Building b = new Building();
parseMapObject(b, e, e.getTags());
@ -228,7 +250,7 @@ public class EntityParser {
List<Node> nodes = ((Way) e).getNodes();
for(int i = 0; i < nodes.size(); i++) {
Node node = nodes.get(i);
if(node != null && "yes".equals(node.getTag(OSMTagKey.ENTRANCE)) &&
if(node != null && "yes".equals(node.getTag(OSMTagKey.ENTRANCE)) &&
!Algorithms.isEmpty(node.getTag(OSMTagKey.REF))) {
b.addEntrance(node.getTag(OSMTagKey.REF), node.getLatLon());
}
@ -236,11 +258,11 @@ public class EntityParser {
}
return b;
}
public static City parseCity(Node el) {
return parseCity(el, CityType.valueFromString(el.getTag(OSMTagKey.PLACE.getValue())));
}
public static City parseCity(Entity el, CityType t) {
if(t == null) {
return null;
@ -252,15 +274,15 @@ public class EntityParser {
c.setIsin(isin);
return c;
}
public static TransportRoute parserRoute(Relation r, String ref){
TransportRoute rt = new TransportRoute();
parseMapObject(rt, r, r.getTags());
rt.setRef(ref);
return rt;
}
public static TransportStop parseTransportStop(Entity e){
TransportStop st = new TransportStop();
parseMapObject(st, e, e.getTags());