Fix concurrent modification exception on start

This commit is contained in:
Victor Shcherb 2020-05-23 10:47:05 +02:00
parent 7d072592cf
commit 61fe550b52
2 changed files with 29 additions and 15 deletions

View file

@ -360,6 +360,11 @@ public class MapPoiTypes {
final Map<String, PoiType> allTypes = new LinkedHashMap<String, PoiType>(); final Map<String, PoiType> allTypes = new LinkedHashMap<String, PoiType>();
final Map<String, List<PoiType>> categoryPoiAdditionalMap = new LinkedHashMap<String, List<PoiType>>(); final Map<String, List<PoiType>> categoryPoiAdditionalMap = new LinkedHashMap<String, List<PoiType>>();
final Map<AbstractPoiType, Set<String>> abstractTypeAdditionalCategories = new LinkedHashMap<AbstractPoiType, Set<String>>(); final Map<AbstractPoiType, Set<String>> abstractTypeAdditionalCategories = new LinkedHashMap<AbstractPoiType, Set<String>>();
final Map<String, PoiType> poiTypesByTag = new LinkedHashMap<String, PoiType>();
final Map<String, String> deprecatedTags = new LinkedHashMap<String, String>();
final Map<String, String> poiAdditionalCategoryIconNames = new LinkedHashMap<String, String>();
final List<PoiType> textPoiAdditionals = new ArrayList<PoiType>();
List<PoiCategory> categoriesList = new ArrayList<>(); List<PoiCategory> categoriesList = new ArrayList<>();
try { try {
XmlPullParser parser = PlatformUtil.newXMLPullParser(); XmlPullParser parser = PlatformUtil.newXMLPullParser();
@ -415,12 +420,15 @@ public class MapPoiTypes {
if (lastCategory == null) { if (lastCategory == null) {
lastCategory = localOtherMapCategory; lastCategory = localOtherMapCategory;
} }
PoiType baseType = parsePoiAdditional(parser, lastCategory, lastFilter, lastType, null, null, lastPoiAdditionalCategory); PoiType baseType = parsePoiAdditional(parser, lastCategory, lastFilter, lastType, null, null,
lastPoiAdditionalCategory, textPoiAdditionals);
if ("true".equals(parser.getAttributeValue("", "lang"))) { if ("true".equals(parser.getAttributeValue("", "lang"))) {
for (String lng : MapRenderingTypes.langs) { for (String lng : MapRenderingTypes.langs) {
parsePoiAdditional(parser, lastCategory, lastFilter, lastType, lng, baseType, lastPoiAdditionalCategory); parsePoiAdditional(parser, lastCategory, lastFilter, lastType, lng, baseType,
lastPoiAdditionalCategory, textPoiAdditionals);
} }
parsePoiAdditional(parser, lastCategory, lastFilter, lastType, "en", baseType, lastPoiAdditionalCategory); parsePoiAdditional(parser, lastCategory, lastFilter, lastType, "en", baseType,
lastPoiAdditionalCategory, textPoiAdditionals);
} }
if (lastPoiAdditionalCategory != null) { if (lastPoiAdditionalCategory != null) {
List<PoiType> categoryAdditionals = categoryPoiAdditionalMap.get(lastPoiAdditionalCategory); List<PoiType> categoryAdditionals = categoryPoiAdditionalMap.get(lastPoiAdditionalCategory);
@ -491,7 +499,7 @@ public class MapPoiTypes {
} }
} }
} }
categories = categoriesList;
is.close(); is.close();
} catch (IOException e) { } catch (IOException e) {
log.error("Unexpected error", e); //$NON-NLS-1$ log.error("Unexpected error", e); //$NON-NLS-1$
@ -519,17 +527,25 @@ public class MapPoiTypes {
List<PoiType> poiAdditionals = categoryPoiAdditionalMap.get(category); List<PoiType> poiAdditionals = categoryPoiAdditionalMap.get(category);
if (poiAdditionals != null) { if (poiAdditionals != null) {
for (PoiType poiType : poiAdditionals) { for (PoiType poiType : poiAdditionals) {
buildPoiAdditionalReference(poiType, entry.getKey()); buildPoiAdditionalReference(poiType, entry.getKey(), textPoiAdditionals);
} }
} }
} }
} }
findDefaultOtherCategory(); this.categories = categoriesList;
this.poiTypesByTag = poiTypesByTag;
this.deprecatedTags = deprecatedTags;
this.poiAdditionalCategoryIconNames = poiAdditionalCategoryIconNames;
this.textPoiAdditionals = textPoiAdditionals;
otherCategory = getPoiCategoryByName("user_defined_other");
if (otherCategory == null) {
throw new IllegalArgumentException("No poi category other");
}
init = true; init = true;
log.info("Time to init poi types " + (System.currentTimeMillis() - time)); //$NON-NLS-1$ log.info("Time to init poi types " + (System.currentTimeMillis() - time)); //$NON-NLS-1$
} }
private PoiType buildPoiAdditionalReference(PoiType poiAdditional, AbstractPoiType parent) { private PoiType buildPoiAdditionalReference(PoiType poiAdditional, AbstractPoiType parent, List<PoiType> textPoiAdditionals) {
PoiCategory lastCategory = null; PoiCategory lastCategory = null;
PoiFilter lastFilter = null; PoiFilter lastFilter = null;
PoiType lastType = null; PoiType lastType = null;
@ -580,7 +596,8 @@ public class MapPoiTypes {
} }
private PoiType parsePoiAdditional(XmlPullParser parser, PoiCategory lastCategory, PoiFilter lastFilter, private PoiType parsePoiAdditional(XmlPullParser parser, PoiCategory lastCategory, PoiFilter lastFilter,
PoiType lastType, String lang, PoiType langBaseType, String poiAdditionalCategory) { PoiType lastType, String lang, PoiType langBaseType,
String poiAdditionalCategory, List<PoiType> textPoiAdditionals) {
String oname = parser.getAttributeValue("", "name"); String oname = parser.getAttributeValue("", "name");
if (lang != null) { if (lang != null) {
oname += ":" + lang; oname += ":" + lang;
@ -662,13 +679,6 @@ public class MapPoiTypes {
return tp; return tp;
} }
private void findDefaultOtherCategory() {
PoiCategory pc = getPoiCategoryByName("user_defined_other");
if (pc == null) {
throw new IllegalArgumentException("No poi category other");
}
otherCategory = pc;
}
public List<PoiCategory> getCategories(boolean includeMapCategory) { public List<PoiCategory> getCategories(boolean includeMapCategory) {
ArrayList<PoiCategory> lst = new ArrayList<PoiCategory>(categories); ArrayList<PoiCategory> lst = new ArrayList<PoiCategory>(categories);

View file

@ -617,6 +617,10 @@ public class PoiFiltersHelper {
} }
public void loadSelectedPoiFilters() { public void loadSelectedPoiFilters() {
// don't deal with not loaded poi types
if(!application.getPoiTypes().isInit()) {
return;
}
selectedPoiFilters.clear(); selectedPoiFilters.clear();
OsmandSettings settings = application.getSettings(); OsmandSettings settings = application.getSettings();
Set<String> filters = settings.getSelectedPoiFilters(); Set<String> filters = settings.getSelectedPoiFilters();