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 00f254c816..330a21c156 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java @@ -203,8 +203,7 @@ public class MapPoiTypes { public Map getAllTranslatedNames(boolean skipNonEditable) { Map translation = new HashMap(); - for (int i = 0; i < categories.size(); i++) { - PoiCategory pc = categories.get(i); + for (PoiCategory pc : categories) { if (skipNonEditable && pc.isNotEditableOsm()) { continue; } @@ -298,12 +297,18 @@ public class MapPoiTypes { if (!lastCategory.getKeyName().equals("Other")) { lastCategory.setTopVisible(true); } - categories.add(lastCategory); + addCategory(lastCategory); return lastCategory; } return otherCategory; } + private void addCategory(PoiCategory category) { + List copy = new ArrayList<>(categories); + copy.add(category); + categories = copy; + } + public PoiTranslator getPoiTranslator() { return poiTranslator; } @@ -348,7 +353,7 @@ public class MapPoiTypes { final Map allTypes = new LinkedHashMap(); final Map> categoryPoiAdditionalMap = new LinkedHashMap>(); final Map> abstractTypeAdditionalCategories = new LinkedHashMap>(); - this.categories.clear(); + List categoriesList = new ArrayList<>(); try { XmlPullParser parser = PlatformUtil.newXMLPullParser(); int tok; @@ -364,7 +369,7 @@ public class MapPoiTypes { if (tok == XmlPullParser.START_TAG) { String name = parser.getName(); if (name.equals("poi_category")) { - lastCategory = new PoiCategory(this, parser.getAttributeValue("", "name"), categories.size()); + lastCategory = new PoiCategory(this, parser.getAttributeValue("", "name"), categoriesList.size()); lastCategory.setTopVisible(Boolean.parseBoolean(parser.getAttributeValue("", "top"))); lastCategory.setNotEditableOsm("true".equals(parser.getAttributeValue("", "no_edit"))); lastCategory.setDefaultTag(parser.getAttributeValue("", "default_tag")); @@ -375,7 +380,7 @@ public class MapPoiTypes { lastCategory.addExcludedPoiAdditionalCategories(parser.getAttributeValue("", "excluded_poi_additional_category").split(",")); lastCategoryPoiAdditionalsCategories.removeAll(lastCategory.getExcludedPoiAdditionalCategories()); } - categories.add(lastCategory); + categoriesList.add(lastCategory); } else if (name.equals("poi_filter")) { PoiFilter tp = new PoiFilter(this, lastCategory, parser.getAttributeValue("", "name")); tp.setTopVisible(Boolean.parseBoolean(parser.getAttributeValue("", "top"))); @@ -477,6 +482,7 @@ public class MapPoiTypes { } } } + categories = categoriesList; is.close(); } catch (IOException e) { log.error("Unexpected error", e); //$NON-NLS-1$