Fixes according to review

This commit is contained in:
PaulStets 2017-09-16 14:34:53 +03:00
parent da07e7cf2d
commit 8f2ab2d077
2 changed files with 611 additions and 614 deletions

View file

@ -46,7 +46,6 @@ public class SearchPhrase {
private Collator clt;
private static Set<String> conjunctions = new TreeSet<>();
static {
// the
conjunctions.add("the");
@ -136,8 +135,8 @@ public class SearchPhrase {
sp.words = new ArrayList<>(this.words);
leftWords = leftWords.subList(leftWords.size(), leftWords.size());
}
for (SearchWord w : leftWords) {
if (restText.startsWith(w.getWord() + DELIMITER)) {
for(SearchWord w : leftWords) {
if(restText.startsWith(w.getWord() + DELIMITER)) {
sp.words.add(w);
restText = restText.substring(w.getWord().length() + DELIMITER.length()).trim();
} else {
@ -154,7 +153,7 @@ public class SearchPhrase {
sp.unknownSearchWordTrim = "";
String[] ws = restText.split(ALLDELIMITERS);
boolean first = true;
for (int i = 0; i < ws.length; i++) {
for (int i = 0; i < ws.length ; i++) {
String wd = ws[i].trim();
if (wd.length() > 0 && !conjunctions.contains(wd.toLowerCase())) {
if (first) {
@ -167,7 +166,7 @@ public class SearchPhrase {
}
}
sp.lastUnknownSearchWordComplete = false;
if (text.length() > 0) {
if (text.length() > 0 ) {
char ch = text.charAt(text.length() - 1);
sp.lastUnknownSearchWordComplete = ch == ' ' || ch == ',' || ch == '\r' || ch == '\n'
|| ch == ';';
@ -196,12 +195,12 @@ public class SearchPhrase {
}
public List<String> getUnknownSearchWords(Collection<String> exclude) {
if (exclude == null || unknownWords.size() == 0 || exclude.size() == 0) {
if(exclude == null || unknownWords.size() == 0 || exclude.size() == 0) {
return unknownWords;
}
List<String> l = new ArrayList<>();
for (String uw : unknownWords) {
if (exclude == null || !exclude.contains(uw)) {
for(String uw : unknownWords) {
if(exclude == null || !exclude.contains(uw)) {
l.add(uw);
}
}
@ -222,14 +221,14 @@ public class SearchPhrase {
}
public int getUnknownSearchWordLength() {
return unknownSearchWordTrim.length();
return unknownSearchWordTrim.length() ;
}
public QuadRect getRadiusBBoxToSearch(int radius) {
int radiusInMeters = getRadiusSearch(radius);
QuadRect cache1kmRect = get1km31Rect();
if (cache1kmRect == null) {
if(cache1kmRect == null) {
return null;
}
int max = (1 << 31) - 1;
@ -243,7 +242,7 @@ public class SearchPhrase {
}
public QuadRect get1km31Rect() {
if (cache1kmRect != null) {
if(cache1kmRect != null) {
return cache1kmRect;
}
LatLon l = getLastTokenLocation();
@ -275,28 +274,27 @@ public class SearchPhrase {
final Iterator<BinaryMapIndexReader> lit = list.iterator();
return new Iterator<BinaryMapIndexReader>() {
BinaryMapIndexReader next = null;
@Override
public boolean hasNext() {
while (lit.hasNext()) {
next = lit.next();
if (rect != null) {
if (dt == SearchPhraseDataType.POI) {
if (next.containsPoiData((int) rect.left, (int) rect.top, (int) rect.right, (int) rect.bottom)) {
if(rect != null) {
if(dt == SearchPhraseDataType.POI) {
if(next.containsPoiData((int)rect.left, (int)rect.top, (int)rect.right, (int)rect.bottom)) {
return true;
}
} else if (dt == SearchPhraseDataType.ADDRESS) {
} else if(dt == SearchPhraseDataType.ADDRESS) {
// containsAddressData not all maps supported
if (next.containsPoiData((int) rect.left, (int) rect.top, (int) rect.right, (int) rect.bottom) &&
if(next.containsPoiData((int)rect.left, (int)rect.top, (int)rect.right, (int)rect.bottom) &&
next.containsAddressData()) {
return true;
}
} else if (dt == SearchPhraseDataType.ROUTING) {
if (next.containsRouteData((int) rect.left, (int) rect.top, (int) rect.right, (int) rect.bottom, 15)) {
} else if(dt == SearchPhraseDataType.ROUTING) {
if(next.containsRouteData((int)rect.left, (int)rect.top, (int)rect.right, (int)rect.bottom, 15)) {
return true;
}
} else {
if (next.containsMapData((int) rect.left, (int) rect.top, (int) rect.right, (int) rect.bottom, 15)) {
if(next.containsMapData((int)rect.left, (int)rect.top, (int)rect.right, (int)rect.bottom, 15)) {
return true;
}
}
@ -319,7 +317,7 @@ public class SearchPhrase {
}
public List<BinaryMapIndexReader> getOfflineIndexes() {
if (indexes != null) {
if(indexes != null) {
return indexes;
}
return settings.getOfflineIndexes();
@ -375,12 +373,12 @@ public class SearchPhrase {
SearchPhrase sp = new SearchPhrase(this.settings, this.clt);
addResult(res, sp);
SearchResult prnt = res.parentSearchResult;
while (prnt != null) {
while(prnt != null) {
addResult(prnt, sp);
prnt = prnt.parentSearchResult;
}
sp.words.addAll(0, this.words);
if (unknownWords != null) {
if(unknownWords != null) {
sp.lastUnknownSearchWordComplete = lastComplete;
for (int i = 0; i < unknownWords.size(); i++) {
if (i == 0) {
@ -401,7 +399,7 @@ public class SearchPhrase {
public boolean isLastWord(ObjectType... p) {
for (int i = words.size() - 1; i >= 0; i--) {
SearchWord sw = words.get(i);
for (ObjectType o : p) {
for(ObjectType o : p) {
if (sw.getType() == o) {
return true;
}
@ -422,7 +420,7 @@ public class SearchPhrase {
}
public NameStringMatcher getNameStringMatcher() {
if (sm != null) {
if(sm != null) {
return sm;
}
sm = getNameStringMatcher(unknownSearchWordTrim, lastUnknownSearchWordComplete);
@ -438,8 +436,8 @@ public class SearchPhrase {
}
public boolean hasObjectType(ObjectType p) {
for (SearchWord s : words) {
if (s.getType() == p) {
for(SearchWord s : words) {
if(s.getType() == p) {
return true;
}
}
@ -447,17 +445,17 @@ public class SearchPhrase {
}
public void syncWordsWithResults() {
for (SearchWord w : words) {
for(SearchWord w : words) {
w.syncWordWithResult();
}
}
public String getText(boolean includeLastWord) {
StringBuilder sb = new StringBuilder();
for (SearchWord s : words) {
for(SearchWord s : words) {
sb.append(s.getWord()).append(DELIMITER.trim() + " ");
}
if (includeLastWord) {
if(includeLastWord) {
sb.append(unknownSearchPhrase);
}
return sb.toString();
@ -466,10 +464,10 @@ public class SearchPhrase {
public String getTextWithoutLastWord() {
StringBuilder sb = new StringBuilder();
List<SearchWord> words = new ArrayList<>(this.words);
if (Algorithms.isEmpty(unknownSearchWordTrim) && words.size() > 0) {
if(Algorithms.isEmpty(unknownSearchWordTrim) && words.size() > 0) {
words.remove(words.size() - 1);
}
for (SearchWord s : words) {
for(SearchWord s : words) {
sb.append(s.getWord()).append(DELIMITER.trim() + " ");
}
return sb.toString();
@ -477,7 +475,7 @@ public class SearchPhrase {
public String getStringRerpresentation() {
StringBuilder sb = new StringBuilder();
for (SearchWord s : words) {
for(SearchWord s : words) {
sb.append(s.getWord()).append(" [" + s.getType() + "], ");
}
sb.append(unknownSearchPhrase);
@ -498,16 +496,16 @@ public class SearchPhrase {
}
public SearchWord getLastSelectedWord() {
if (words.isEmpty()) {
if(words.isEmpty()) {
return null;
}
return words.get(words.size() - 1);
}
public LatLon getWordLocation() {
for (int i = words.size() - 1; i >= 0; i--) {
for(int i = words.size() - 1; i >= 0; i--) {
SearchWord sw = words.get(i);
if (sw.getLocation() != null) {
if(sw.getLocation() != null) {
return sw.getLocation();
}
}
@ -515,9 +513,9 @@ public class SearchPhrase {
}
public LatLon getLastTokenLocation() {
for (int i = words.size() - 1; i >= 0; i--) {
for(int i = words.size() - 1; i >= 0; i--) {
SearchWord sw = words.get(i);
if (sw.getLocation() != null) {
if(sw.getLocation() != null) {
return sw.getLocation();
}
}
@ -526,10 +524,10 @@ public class SearchPhrase {
}
public void selectFile(BinaryMapIndexReader object) {
if (indexes == null) {
if(indexes == null) {
indexes = new ArrayList<>();
}
if (!this.indexes.contains(object)) {
if(!this.indexes.contains(object)) {
this.indexes.add(object);
}
}
@ -589,7 +587,7 @@ public class SearchPhrase {
Iterator<BinaryMapIndexReader> it = indexes.iterator();
while (it.hasNext()) {
BinaryMapIndexReader r = it.next();
if (r.getFile().getName().matches(".*([0-9]+_*){3}\\.obf")) {
if (r.getFile().getName().matches("[a-zA-Z_-]+([0-9]+_*){3}[.a-z]+")) {
String currRegionName = r.getRegionName();
if (result.containsKey(currRegionName)) {
result.get(currRegionName).add(r);
@ -611,11 +609,11 @@ public class SearchPhrase {
}
public boolean matches(Collection<String> map) {
if (map == null) {
if(map == null) {
return false;
}
for (String v : map) {
if (sm.matches(v)) {
for(String v : map) {
if(sm.matches(v)) {
return true;
}
}
@ -634,30 +632,29 @@ public class SearchPhrase {
}
public void countUnknownWordsMatch(SearchResult sr, String localeName, Collection<String> otherNames) {
if (unknownWords.size() > 0) {
for (int i = 0; i < unknownWords.size(); i++) {
if (unknownWordsMatcher.size() == i) {
if(unknownWords.size() > 0) {
for(int i = 0; i < unknownWords.size(); i++) {
if(unknownWordsMatcher.size() == i) {
unknownWordsMatcher.add(new NameStringMatcher(unknownWords.get(i),
i < unknownWords.size() - 1 ? StringMatcherMode.CHECK_EQUALS_FROM_SPACE :
StringMatcherMode.CHECK_STARTS_FROM_SPACE));
}
NameStringMatcher ms = unknownWordsMatcher.get(i);
if (ms.matches(localeName) || ms.matches(otherNames)) {
if (sr.otherWordsMatch == null) {
if(ms.matches(localeName) || ms.matches(otherNames)) {
if(sr.otherWordsMatch == null) {
sr.otherWordsMatch = new TreeSet<>();
}
sr.otherWordsMatch.add(unknownWords.get(i));
}
}
}
if (!sr.firstUnknownWordMatches) {
if(!sr.firstUnknownWordMatches) {
sr.firstUnknownWordMatches = localeName.equals(getUnknownSearchWord()) ||
getNameStringMatcher().matches(localeName) ||
getNameStringMatcher().matches(otherNames);
}
}
public int getRadiusSearch(int meters) {
return (1 << (getRadiusLevel() - 1)) * meters;
}
@ -668,9 +665,9 @@ public class SearchPhrase {
public String getUnknownWordToSearchBuilding() {
List<String> unknownSearchWords = getUnknownSearchWords();
if (unknownSearchWords.size() > 0 && Algorithms.extractFirstIntegerNumber(getUnknownSearchWord()) == 0) {
for (String wrd : unknownSearchWords) {
if (Algorithms.extractFirstIntegerNumber(wrd) != 0) {
if(unknownSearchWords.size() > 0 && Algorithms.extractFirstIntegerNumber(getUnknownSearchWord()) == 0) {
for(String wrd : unknownSearchWords) {
if(Algorithms.extractFirstIntegerNumber(wrd) != 0) {
return wrd;
}
}
@ -689,8 +686,8 @@ public class SearchPhrase {
private int lengthWithoutNumbers(String s) {
int len = 0;
for (int k = 0; k < s.length(); k++) {
if (s.charAt(k) >= '0' && s.charAt(k) <= '9') {
for(int k = 0; k < s.length(); k++) {
if(s.charAt(k) >= '0' && s.charAt(k) <= '9') {
} else {
len++;