From 88a6d620803e19538e39cf24023c3c941a8dc307 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 22 May 2020 14:57:55 +0200 Subject: [PATCH] Fix map poi types --- .../main/java/net/osmand/osm/MapPoiTypes.java | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java index 330a21c156..4199abee89 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java @@ -29,6 +29,7 @@ import java.util.TreeSet; public class MapPoiTypes { + private static final String OTHER_MAP_CATEGORY = "Other"; private static MapPoiTypes DEFAULT_INSTANCE = null; private static final Log log = PlatformUtil.getLog(MapRenderingTypes.class); private String resourceName; @@ -96,7 +97,7 @@ public class MapPoiTypes { public PoiCategory getOtherMapCategory() { if (otherMapCategory == null) { - otherMapCategory = getPoiCategoryByName("Other", true); + otherMapCategory = getPoiCategoryByName(OTHER_MAP_CATEGORY, true); } return otherMapCategory; } @@ -111,7 +112,8 @@ public class MapPoiTypes { public List getTopVisibleFilters() { List lf = new ArrayList(); - for (PoiCategory pc : categories) { + for (int i = 0; i < categories.size(); i++) { + PoiCategory pc = categories.get(i); if (pc.isTopVisible()) { lf.add(pc); } @@ -131,7 +133,8 @@ public class MapPoiTypes { } public PoiCategory getOsmwiki() { - for (PoiCategory category : categories) { + for (int i = 0; i < categories.size(); i++) { + PoiCategory category = categories.get(i); if (category.isWiki()) { return category; } @@ -167,7 +170,8 @@ public class MapPoiTypes { } public PoiType getPoiTypeByKey(String name) { - for (PoiCategory pc : categories) { + for (int i = 0; i < categories.size(); i++) { + PoiCategory pc = categories.get(i); PoiType pt = pc.getPoiTypeByKeyName(name); if (pt != null && !pt.isReference()) { return pt; @@ -184,7 +188,8 @@ public class MapPoiTypes { } public AbstractPoiType getAnyPoiTypeByKey(String name) { - for (PoiCategory pc : categories) { + for (int i = 0; i < categories.size(); i++) { + PoiCategory pc = categories.get(i); if (pc.getKeyName().equals(name)) { return pc; } @@ -203,7 +208,8 @@ public class MapPoiTypes { public Map getAllTranslatedNames(boolean skipNonEditable) { Map translation = new HashMap(); - for (PoiCategory pc : categories) { + for (int i = 0; i < categories.size(); i++) { + PoiCategory pc = categories.get(i); if (skipNonEditable && pc.isNotEditableOsm()) { continue; } @@ -231,7 +237,8 @@ public class MapPoiTypes { public List getAllTypesTranslatedNames(StringMatcher matcher) { List tm = new ArrayList(); - for (PoiCategory pc : categories) { + for (int i = 0; i < categories.size(); i++) { + PoiCategory pc = categories.get(i); if (pc == otherMapCategory) { continue; } @@ -294,7 +301,7 @@ public class MapPoiTypes { } if (create) { PoiCategory lastCategory = new PoiCategory(this, name, categories.size()); - if (!lastCategory.getKeyName().equals("Other")) { + if (!lastCategory.getKeyName().equals(OTHER_MAP_CATEGORY)) { lastCategory.setTopVisible(true); } addCategory(lastCategory); @@ -365,6 +372,8 @@ public class MapPoiTypes { PoiType lastType = null; Set lastTypePoiAdditionalsCategories = new TreeSet(); String lastPoiAdditionalCategory = null; + PoiCategory localOtherMapCategory = new PoiCategory(this, OTHER_MAP_CATEGORY, categoriesList.size()); + categoriesList.add(localOtherMapCategory); while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) { if (tok == XmlPullParser.START_TAG) { String name = parser.getName(); @@ -404,7 +413,7 @@ public class MapPoiTypes { lastCategory.addPoiType(tp); } else if (name.equals("poi_additional")) { if (lastCategory == null) { - lastCategory = getOtherMapCategory(); + lastCategory = localOtherMapCategory; } PoiType baseType = parsePoiAdditional(parser, lastCategory, lastFilter, lastType, null, null, lastPoiAdditionalCategory); if ("true".equals(parser.getAttributeValue("", "lang"))) { @@ -433,7 +442,7 @@ public class MapPoiTypes { } else if (name.equals("poi_type")) { if (lastCategory == null) { - lastCategory = getOtherMapCategory(); + lastCategory = localOtherMapCategory; } if(!Algorithms.isEmpty(parser.getAttributeValue("", "deprecated_of"))){ String vl = parser.getAttributeValue("", "name"); @@ -705,7 +714,8 @@ public class MapPoiTypes { public AbstractPoiType getAnyPoiAdditionalTypeByKey(String name) { PoiType add = null; - for (PoiCategory pc : categories) { + for (int i = 0; i < categories.size(); i++) { + PoiCategory pc = categories.get(i); add = getPoiAdditionalByKey(pc, name); if (add != null) { return add; @@ -811,7 +821,8 @@ public class MapPoiTypes { if (!poiTypesByTag.isEmpty()) { return; } - for (PoiCategory poic : categories) { + for (int i = 0; i < categories.size(); i++) { + PoiCategory poic = categories.get(i); for (PoiType p : poic.getPoiTypes()) { initPoiType(p); for (PoiType pts : p.getPoiAdditionals()) {