diff --git a/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapPoiReaderAdapter.java b/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapPoiReaderAdapter.java index 857eb4f4d3..cb348cf9b4 100644 --- a/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapPoiReaderAdapter.java +++ b/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapPoiReaderAdapter.java @@ -11,8 +11,6 @@ import java.util.Arrays; import java.util.Comparator; import java.util.LinkedList; import java.util.List; -import java.util.Map; -import java.util.Map.Entry; import net.osmand.Collator; import net.osmand.CollatorStringMatcher; @@ -576,13 +574,12 @@ public class BinaryMapPoiReaderAdapter { } } if (!matches) { - Map lt = am.getAdditionalInfo(); - for (Entry e : lt.entrySet()) { - if(!e.getKey().contains("_name") && - !e.getKey().equals("brand")) { + for (String key : am.getAdditionalInfoKeys()) { + if(!key.contains("_name") && + !key.equals("brand")) { continue; } - matches = matcher.matches(e.getValue()); + matches = matcher.matches(am.getAdditionalInfo(key)); if (matches) { break; } @@ -812,7 +809,6 @@ public class BinaryMapPoiReaderAdapter { } private boolean checkCategories(SearchRequest req, PoiRegion region) throws IOException { - StringBuilder subType = new StringBuilder(); while (true) { int t = codedIS.readTag(); int tag = WireFormat.getTagFieldNumber(t); diff --git a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java index 13749ce706..4af1596c2c 100644 --- a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java +++ b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java @@ -91,13 +91,40 @@ public class Amenity extends MapObject { } - public Map getAdditionalInfo() { + // this method should be used carefully + public Map getInternalAdditionalInfoMap() { if (additionalInfo == null) { return Collections.emptyMap(); } return additionalInfo; } + public Collection getAdditionalInfoValues(boolean excludeZipped) { + if (additionalInfo == null) { + return Collections.emptyList(); + } + boolean zipped = false; + for(String v : additionalInfo.values()) { + if(isContentZipped(v)) { + zipped = true; + break; + } + } + if(zipped) { + List r = new ArrayList<>(additionalInfo.size()); + for(String str : additionalInfo.values()) { + if(excludeZipped && isContentZipped(str)) { + + } else { + r.add(unzipContent(str)); + } + } + return r; + } else { + return additionalInfo.values(); + } + } + public Collection getAdditionalInfoKeys() { if (additionalInfo == null) { return Collections.emptyList(); @@ -184,7 +211,7 @@ public class Amenity extends MapObject { } int maxLen = 0; String lng = defLang; - for (String nm : getAdditionalInfo().keySet()) { + for (String nm : getAdditionalInfoKeys()) { if (nm.startsWith(tag + ":")) { String key = nm.substring(tag.length() + 1); String cnt = getAdditionalInfo(tag + ":" + key); @@ -206,7 +233,7 @@ public class Amenity extends MapObject { public List getNames(String tag, String defTag) { List l = new ArrayList(); - for (String nm : getAdditionalInfo().keySet()) { + for (String nm : getAdditionalInfoKeys()) { if (nm.startsWith(tag + ":")) { l.add(nm.substring(tag.length() + 1)); } else if (nm.equals(tag)) { @@ -231,7 +258,7 @@ public class Amenity extends MapObject { if (!Algorithms.isEmpty(enName)) { return enName; } - for (String nm : getAdditionalInfo().keySet()) { + for (String nm : getAdditionalInfoKeys()) { if (nm.startsWith(tag + ":")) { return getAdditionalInfo(nm); } @@ -347,4 +374,6 @@ public class Amenity extends MapObject { } return a; } + + } diff --git a/OsmAnd-java/src/main/java/net/osmand/data/MapObject.java b/OsmAnd-java/src/main/java/net/osmand/data/MapObject.java index cb121cedfc..f9f9187223 100644 --- a/OsmAnd-java/src/main/java/net/osmand/data/MapObject.java +++ b/OsmAnd-java/src/main/java/net/osmand/data/MapObject.java @@ -13,7 +13,6 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; @@ -351,8 +350,8 @@ public abstract class MapObject implements Comparable { return json; } - public String unzipContent(String str) { - if (str != null && str.startsWith(" gz ")) { + String unzipContent(String str) { + if (isContentZipped(str)) { try { int ind = 4; byte[] bytes = new byte[str.length() - ind]; @@ -376,6 +375,10 @@ public abstract class MapObject implements Comparable { return str; } + boolean isContentZipped(String str) { + return str != null && str.startsWith(" gz "); + } + protected static void parseJSON(JSONObject json, MapObject o) { if (json.has("name")) { o.name = json.getString("name"); diff --git a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java index becacd2775..e63870b1a7 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java @@ -741,7 +741,7 @@ public class SearchUICore { } } if (Algorithms.isEmpty(object.alternateName) && object.object instanceof Amenity) { - for (String value : ((Amenity) object.object).getAdditionalInfo().values()) { + for (String value : ((Amenity) object.object).getAdditionalInfoValues(true)) { if (phrase.getFirstUnknownNameStringMatcher().matches(value)) { object.alternateName = value; break; diff --git a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java index e5c791a780..c221d2ca77 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java @@ -602,7 +602,7 @@ public class SearchCoreFactory { sr.localeName = object.getName(phrase.getSettings().getLang(), phrase.getSettings().isTransliterate()); if (!nm.matches(sr.localeName) && !nm.matches(sr.otherNames) - && !nm.matches(object.getAdditionalInfo().values())) { + && !nm.matches(object.getAdditionalInfoValues(false))) { return false; } sr.object = object; @@ -1059,7 +1059,7 @@ public class SearchCoreFactory { if (!poiAdditionals.isEmpty()) { boolean found = false; for (String add : poiAdditionals) { - if(object.getAdditionalInfo().containsKey(add)) { + if (object.getAdditionalInfoKeys().contains(add)) { found = true; break; }