Refactor & hide internal method about additional info
This commit is contained in:
parent
bcea2e4e0e
commit
3fc2dd89b9
5 changed files with 46 additions and 18 deletions
|
@ -11,8 +11,6 @@ import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
import net.osmand.Collator;
|
import net.osmand.Collator;
|
||||||
import net.osmand.CollatorStringMatcher;
|
import net.osmand.CollatorStringMatcher;
|
||||||
|
@ -576,13 +574,12 @@ public class BinaryMapPoiReaderAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!matches) {
|
if (!matches) {
|
||||||
Map<String, String> lt = am.getAdditionalInfo();
|
for (String key : am.getAdditionalInfoKeys()) {
|
||||||
for (Entry<String, String> e : lt.entrySet()) {
|
if(!key.contains("_name") &&
|
||||||
if(!e.getKey().contains("_name") &&
|
!key.equals("brand")) {
|
||||||
!e.getKey().equals("brand")) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
matches = matcher.matches(e.getValue());
|
matches = matcher.matches(am.getAdditionalInfo(key));
|
||||||
if (matches) {
|
if (matches) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -812,7 +809,6 @@ public class BinaryMapPoiReaderAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkCategories(SearchRequest<Amenity> req, PoiRegion region) throws IOException {
|
private boolean checkCategories(SearchRequest<Amenity> req, PoiRegion region) throws IOException {
|
||||||
StringBuilder subType = new StringBuilder();
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int t = codedIS.readTag();
|
int t = codedIS.readTag();
|
||||||
int tag = WireFormat.getTagFieldNumber(t);
|
int tag = WireFormat.getTagFieldNumber(t);
|
||||||
|
|
|
@ -91,13 +91,40 @@ public class Amenity extends MapObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Map<String, String> getAdditionalInfo() {
|
// this method should be used carefully
|
||||||
|
public Map<String, String> getInternalAdditionalInfoMap() {
|
||||||
if (additionalInfo == null) {
|
if (additionalInfo == null) {
|
||||||
return Collections.emptyMap();
|
return Collections.emptyMap();
|
||||||
}
|
}
|
||||||
return additionalInfo;
|
return additionalInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<String> 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<String> 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<String> getAdditionalInfoKeys() {
|
public Collection<String> getAdditionalInfoKeys() {
|
||||||
if (additionalInfo == null) {
|
if (additionalInfo == null) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
|
@ -184,7 +211,7 @@ public class Amenity extends MapObject {
|
||||||
}
|
}
|
||||||
int maxLen = 0;
|
int maxLen = 0;
|
||||||
String lng = defLang;
|
String lng = defLang;
|
||||||
for (String nm : getAdditionalInfo().keySet()) {
|
for (String nm : getAdditionalInfoKeys()) {
|
||||||
if (nm.startsWith(tag + ":")) {
|
if (nm.startsWith(tag + ":")) {
|
||||||
String key = nm.substring(tag.length() + 1);
|
String key = nm.substring(tag.length() + 1);
|
||||||
String cnt = getAdditionalInfo(tag + ":" + key);
|
String cnt = getAdditionalInfo(tag + ":" + key);
|
||||||
|
@ -206,7 +233,7 @@ public class Amenity extends MapObject {
|
||||||
|
|
||||||
public List<String> getNames(String tag, String defTag) {
|
public List<String> getNames(String tag, String defTag) {
|
||||||
List<String> l = new ArrayList<String>();
|
List<String> l = new ArrayList<String>();
|
||||||
for (String nm : getAdditionalInfo().keySet()) {
|
for (String nm : getAdditionalInfoKeys()) {
|
||||||
if (nm.startsWith(tag + ":")) {
|
if (nm.startsWith(tag + ":")) {
|
||||||
l.add(nm.substring(tag.length() + 1));
|
l.add(nm.substring(tag.length() + 1));
|
||||||
} else if (nm.equals(tag)) {
|
} else if (nm.equals(tag)) {
|
||||||
|
@ -231,7 +258,7 @@ public class Amenity extends MapObject {
|
||||||
if (!Algorithms.isEmpty(enName)) {
|
if (!Algorithms.isEmpty(enName)) {
|
||||||
return enName;
|
return enName;
|
||||||
}
|
}
|
||||||
for (String nm : getAdditionalInfo().keySet()) {
|
for (String nm : getAdditionalInfoKeys()) {
|
||||||
if (nm.startsWith(tag + ":")) {
|
if (nm.startsWith(tag + ":")) {
|
||||||
return getAdditionalInfo(nm);
|
return getAdditionalInfo(nm);
|
||||||
}
|
}
|
||||||
|
@ -347,4 +374,6 @@ public class Amenity extends MapObject {
|
||||||
}
|
}
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -351,8 +350,8 @@ public abstract class MapObject implements Comparable<MapObject> {
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String unzipContent(String str) {
|
String unzipContent(String str) {
|
||||||
if (str != null && str.startsWith(" gz ")) {
|
if (isContentZipped(str)) {
|
||||||
try {
|
try {
|
||||||
int ind = 4;
|
int ind = 4;
|
||||||
byte[] bytes = new byte[str.length() - ind];
|
byte[] bytes = new byte[str.length() - ind];
|
||||||
|
@ -376,6 +375,10 @@ public abstract class MapObject implements Comparable<MapObject> {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isContentZipped(String str) {
|
||||||
|
return str != null && str.startsWith(" gz ");
|
||||||
|
}
|
||||||
|
|
||||||
protected static void parseJSON(JSONObject json, MapObject o) {
|
protected static void parseJSON(JSONObject json, MapObject o) {
|
||||||
if (json.has("name")) {
|
if (json.has("name")) {
|
||||||
o.name = json.getString("name");
|
o.name = json.getString("name");
|
||||||
|
|
|
@ -741,7 +741,7 @@ public class SearchUICore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Algorithms.isEmpty(object.alternateName) && object.object instanceof Amenity) {
|
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)) {
|
if (phrase.getFirstUnknownNameStringMatcher().matches(value)) {
|
||||||
object.alternateName = value;
|
object.alternateName = value;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -602,7 +602,7 @@ public class SearchCoreFactory {
|
||||||
sr.localeName = object.getName(phrase.getSettings().getLang(),
|
sr.localeName = object.getName(phrase.getSettings().getLang(),
|
||||||
phrase.getSettings().isTransliterate());
|
phrase.getSettings().isTransliterate());
|
||||||
if (!nm.matches(sr.localeName) && !nm.matches(sr.otherNames)
|
if (!nm.matches(sr.localeName) && !nm.matches(sr.otherNames)
|
||||||
&& !nm.matches(object.getAdditionalInfo().values())) {
|
&& !nm.matches(object.getAdditionalInfoValues(false))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
sr.object = object;
|
sr.object = object;
|
||||||
|
@ -1059,7 +1059,7 @@ public class SearchCoreFactory {
|
||||||
if (!poiAdditionals.isEmpty()) {
|
if (!poiAdditionals.isEmpty()) {
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (String add : poiAdditionals) {
|
for (String add : poiAdditionals) {
|
||||||
if(object.getAdditionalInfo().containsKey(add)) {
|
if (object.getAdditionalInfoKeys().contains(add)) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue