From 37b91eeadbaed7deb3cd1b24d2fc2daf9f10e61a Mon Sep 17 00:00:00 2001 From: PaulStets Date: Sat, 16 Sep 2017 14:39:02 +0300 Subject: [PATCH] Fixes according to review --- .../net/osmand/search/core/SearchPhrase.java | 116 +++++++++--------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/search/core/SearchPhrase.java b/OsmAnd-java/src/net/osmand/search/core/SearchPhrase.java index 2f04d4bae7..3ace3ac1ac 100644 --- a/OsmAnd-java/src/net/osmand/search/core/SearchPhrase.java +++ b/OsmAnd-java/src/net/osmand/search/core/SearchPhrase.java @@ -532,73 +532,73 @@ public class SearchPhrase { } } - public void sortFiles() { - if (indexes == null) { - indexes = new ArrayList<>(getOfflineIndexes()); - } - Map> diffsByRegion = getDiffsByRegion(); - final LatLon ll = getLastTokenLocation(); - if (ll != null) { - Collections.sort(indexes, new Comparator() { - Map locations = new HashMap<>(); + public void sortFiles() { + if(indexes == null) { + indexes = new ArrayList<>(getOfflineIndexes()); + } + Map> diffsByRegion = getDiffsByRegion(); + final LatLon ll = getLastTokenLocation(); + if(ll != null) { + Collections.sort(indexes, new Comparator() { + Map locations = new HashMap<>(); - @Override - public int compare(BinaryMapIndexReader o1, BinaryMapIndexReader o2) { - LatLon rc1 = o1 == null ? null : getLocation(o1); - LatLon rc2 = o2 == null ? null : getLocation(o2); - double d1 = rc1 == null ? 10000000d : MapUtils.getDistance(rc1, ll); - double d2 = rc2 == null ? 10000000d : MapUtils.getDistance(rc2, ll); - return Double.compare(d1, d2); - } + @Override + public int compare(BinaryMapIndexReader o1, BinaryMapIndexReader o2) { + LatLon rc1 = o1 == null ? null : getLocation(o1); + LatLon rc2 = o2 == null ? null : getLocation(o2); + double d1 = rc1 == null ? 10000000d : MapUtils.getDistance(rc1, ll); + double d2 = rc2 == null ? 10000000d : MapUtils.getDistance(rc2, ll); + return Double.compare(d1, d2); + } - private LatLon getLocation(BinaryMapIndexReader o1) { - if (locations.containsKey(o1)) { - return locations.get(o1); - } - LatLon rc1 = null; - if (o1.containsMapData()) { - rc1 = o1.getMapIndexes().get(0).getCenterLatLon(); - } else { - rc1 = o1.getRegionCenter(); - } - locations.put(o1, rc1); - return rc1; - } - }); - if (!diffsByRegion.isEmpty()) { - List finalSort = new ArrayList<>(); - for (int i = 0; i < indexes.size(); i++) { - BinaryMapIndexReader currFile = indexes.get(i); + private LatLon getLocation(BinaryMapIndexReader o1) { + if(locations.containsKey(o1)) { + return locations.get(o1); + } + LatLon rc1 = null; + if(o1.containsMapData()) { + rc1 = o1.getMapIndexes().get(0).getCenterLatLon(); + } else { + rc1 = o1.getRegionCenter(); + } + locations.put(o1, rc1); + return rc1; + } + }); + if (!diffsByRegion.isEmpty()) { + List finalSort = new ArrayList<>(); + for (int i = 0; i < indexes.size(); i++) { + BinaryMapIndexReader currFile = indexes.get(i); if (diffsByRegion.get(currFile.getRegionName()) != null) { finalSort.addAll(diffsByRegion.get(currFile.getRegionName())); finalSort.add(currFile); } else { finalSort.add(currFile); } - } - indexes.clear(); - indexes.addAll(finalSort); - } - } - } - - private Map> getDiffsByRegion() { - Map> result = new HashMap<>(); + } + indexes.clear(); + indexes.addAll(finalSort); + } + } + } + + private Map> getDiffsByRegion() { + Map> result = new HashMap<>(); Iterator it = indexes.iterator(); - while (it.hasNext()) { - BinaryMapIndexReader r = it.next(); - 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); - } else { - result.put(currRegionName, new ArrayList<>(Arrays.asList(r))); - } - it.remove(); - } - } - return result; - } + while (it.hasNext()) { + BinaryMapIndexReader r = it.next(); + 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); + } else { + result.put(currRegionName, new ArrayList<>(Arrays.asList(r))); + } + it.remove(); + } + } + return result; + } public static class NameStringMatcher implements StringMatcher {