From 3e9ef3914b3b3962d00e2803bdd2ad6411cb6523 Mon Sep 17 00:00:00 2001 From: Kseniia Date: Mon, 4 Jan 2021 10:08:10 +0200 Subject: [PATCH 1/6] add filterPoiByType() --- .../java/net/osmand/search/SearchUICore.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) 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 e63870b1a7..14a4566279 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java @@ -204,6 +204,7 @@ public class SearchUICore { for (SearchResult rs : lstUnique) { same = sameSearchResult(rs, r); if (same) { + filterPoiByType(rs, r, lst); break; } } @@ -217,6 +218,24 @@ public class SearchUICore { } } } + + private void filterPoiByType(SearchResult r1, SearchResult r2, List list) { + if (r1.object instanceof Amenity) { + + Amenity a1 = (Amenity) r1.object; + Amenity a2 = (Amenity) r2.object; + + if (!(a2.getSubType().equals("building") || a2.getSubType().contains("internet")) + && (a1.getSubType().equals("building") || a1.getSubType().contains("internet"))) { + + int index = list.indexOf(r1); + + if (list.contains(r1)) { + list.set(index, r2); + } + } + } + } public boolean sameSearchResult(SearchResult r1, SearchResult r2) { if (r1.location != null && r2.location != null && @@ -244,10 +263,16 @@ public class SearchUICore { String type2 = a2.getType().getKeyName(); String subType1 = a1.getSubType(); String subType2 = a2.getSubType(); - if(a1.getId().longValue() == a2.getId().longValue() && (subType1.equals("building") || subType2.equals("building"))) { + + if (a1.getId().longValue() == a2.getId().longValue() + && ((subType1.equals("building") || subType2.equals("building")))) { return true; } if (!type1.equals(type2)) { + if (a1.getId().longValue() == a2.getId().longValue() && subType1.contains("internet") + || subType2.contains("internet")) { + return true; + } return false; } if (type1.equals("natural")) { From b9339cdab55bd43a1a973671c99ee8ad4b26cb99 Mon Sep 17 00:00:00 2001 From: Kseniia Date: Tue, 5 Jan 2021 15:11:14 +0200 Subject: [PATCH 2/6] fix filter by building and internet poi --- .../java/net/osmand/search/SearchUICore.java | 42 +++++++------------ 1 file changed, 14 insertions(+), 28 deletions(-) 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 14a4566279..573068d207 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java @@ -204,7 +204,6 @@ public class SearchUICore { for (SearchResult rs : lstUnique) { same = sameSearchResult(rs, r); if (same) { - filterPoiByType(rs, r, lst); break; } } @@ -218,24 +217,6 @@ public class SearchUICore { } } } - - private void filterPoiByType(SearchResult r1, SearchResult r2, List list) { - if (r1.object instanceof Amenity) { - - Amenity a1 = (Amenity) r1.object; - Amenity a2 = (Amenity) r2.object; - - if (!(a2.getSubType().equals("building") || a2.getSubType().contains("internet")) - && (a1.getSubType().equals("building") || a1.getSubType().contains("internet"))) { - - int index = list.indexOf(r1); - - if (list.contains(r1)) { - list.set(index, r2); - } - } - } - } public boolean sameSearchResult(SearchResult r1, SearchResult r2) { if (r1.location != null && r2.location != null && @@ -263,7 +244,7 @@ public class SearchUICore { String type2 = a2.getType().getKeyName(); String subType1 = a1.getSubType(); String subType2 = a2.getSubType(); - + if (a1.getId().longValue() == a2.getId().longValue() && ((subType1.equals("building") || subType2.equals("building")))) { return true; @@ -275,6 +256,7 @@ public class SearchUICore { } return false; } + if (type1.equals("natural")) { similarityRadius = 50000; } else if (subType1.equals(subType2)) { @@ -1012,16 +994,20 @@ public class SearchUICore { // here 2 points are amenity Amenity a1 = (Amenity) o1.object; Amenity a2 = (Amenity) o2.object; - String type1 = a1.getType().getKeyName(); - String type2 = a2.getType().getKeyName(); - int cmp = c.collator.compare(type1, type2); - if (cmp != 0) { - return cmp; - } - + String subType1 = a1.getSubType() == null ? "" : a1.getSubType(); String subType2 = a2.getSubType() == null ? "" : a2.getSubType(); - cmp = c.collator.compare(subType1, subType2); + + int cmp; + + if(subType1.equals("building") || subType1.contains("internet")) { + cmp = 1; + } else if(subType2.equals("building") || subType2.contains("internet")) { + cmp = -1; + } else { + cmp = c.collator.compare(subType1, subType2); + } + if (cmp != 0) { return cmp; } From d74e57db84858661acb66007c3a2a73182aa8b1c Mon Sep 17 00:00:00 2001 From: Kseniia Date: Tue, 5 Jan 2021 22:49:39 +0200 Subject: [PATCH 3/6] refactoring --- .../java/net/osmand/search/SearchUICore.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) 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 573068d207..f8b738a509 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java @@ -41,10 +41,13 @@ import java.util.LinkedList; import java.util.List; import java.util.ListIterator; import java.util.Set; +import java.util.TreeSet; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; +import java.util.stream.Stream; public class SearchUICore { @@ -67,6 +70,8 @@ public class SearchUICore { private MapPoiTypes poiTypes; private static boolean debugMode = false; + + private static final Set FILTER_DUPLICATE_POI_SUBTYPE = Stream.of("building").collect((Collectors.toCollection(TreeSet::new))); public SearchUICore(MapPoiTypes poiTypes, String locale, boolean transliterate) { this.poiTypes = poiTypes; @@ -245,18 +250,20 @@ public class SearchUICore { String subType1 = a1.getSubType(); String subType2 = a2.getSubType(); - if (a1.getId().longValue() == a2.getId().longValue() - && ((subType1.equals("building") || subType2.equals("building")))) { + boolean isEqualId = a1.getId().longValue() == a2.getId().longValue(); + + if (isEqualId && (FILTER_DUPLICATE_POI_SUBTYPE.contains(subType1) + || FILTER_DUPLICATE_POI_SUBTYPE.contains(subType2))) { return true; + } if (!type1.equals(type2)) { - if (a1.getId().longValue() == a2.getId().longValue() && subType1.contains("internet") - || subType2.contains("internet")) { + if (isEqualId && (subType1.contains("internet") || subType2.contains("internet"))) { return true; } return false; } - + if (type1.equals("natural")) { similarityRadius = 50000; } else if (subType1.equals(subType2)) { @@ -1000,9 +1007,9 @@ public class SearchUICore { int cmp; - if(subType1.equals("building") || subType1.contains("internet")) { + if(FILTER_DUPLICATE_POI_SUBTYPE.contains(subType1) || subType1.contains("internet")) { cmp = 1; - } else if(subType2.equals("building") || subType2.contains("internet")) { + } else if(FILTER_DUPLICATE_POI_SUBTYPE.contains(subType2) || subType2.contains("internet")) { cmp = -1; } else { cmp = c.collator.compare(subType1, subType2); From be80a4c5748bdcbb9b4e3fa02869c0938044fe31 Mon Sep 17 00:00:00 2001 From: Kseniia Date: Tue, 5 Jan 2021 23:29:26 +0200 Subject: [PATCH 4/6] refactoring --- .../java/net/osmand/search/SearchUICore.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) 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 f8b738a509..589dfb3b3f 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java @@ -34,6 +34,7 @@ import org.json.JSONObject; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; @@ -71,7 +72,7 @@ public class SearchUICore { private static boolean debugMode = false; - private static final Set FILTER_DUPLICATE_POI_SUBTYPE = Stream.of("building").collect((Collectors.toCollection(TreeSet::new))); + private static final Set FILTER_DUPLICATE_POI_SUBTYPE = new TreeSet(Arrays.asList("building", "internet_access_yes")); public SearchUICore(MapPoiTypes poiTypes, String locale, boolean transliterate) { this.poiTypes = poiTypes; @@ -249,16 +250,17 @@ public class SearchUICore { String type2 = a2.getType().getKeyName(); String subType1 = a1.getSubType(); String subType2 = a2.getSubType(); - - boolean isEqualId = a1.getId().longValue() == a2.getId().longValue(); + boolean isEqualId = a1.getId().longValue() == a2.getId().longValue(); + if (isEqualId && (FILTER_DUPLICATE_POI_SUBTYPE.contains(subType1) || FILTER_DUPLICATE_POI_SUBTYPE.contains(subType2))) { return true; } if (!type1.equals(type2)) { - if (isEqualId && (subType1.contains("internet") || subType2.contains("internet"))) { + if (isEqualId && (FILTER_DUPLICATE_POI_SUBTYPE.contains(subType1) + || FILTER_DUPLICATE_POI_SUBTYPE.contains(subType2))) { return true; } return false; @@ -1001,20 +1003,20 @@ public class SearchUICore { // here 2 points are amenity Amenity a1 = (Amenity) o1.object; Amenity a2 = (Amenity) o2.object; - + String subType1 = a1.getSubType() == null ? "" : a1.getSubType(); String subType2 = a2.getSubType() == null ? "" : a2.getSubType(); - + int cmp; - - if(FILTER_DUPLICATE_POI_SUBTYPE.contains(subType1) || subType1.contains("internet")) { + + if (FILTER_DUPLICATE_POI_SUBTYPE.contains(subType1)) { cmp = 1; - } else if(FILTER_DUPLICATE_POI_SUBTYPE.contains(subType2) || subType2.contains("internet")) { + } else if (FILTER_DUPLICATE_POI_SUBTYPE.contains(subType2)) { cmp = -1; } else { cmp = c.collator.compare(subType1, subType2); } - + if (cmp != 0) { return cmp; } From 3096f6f8fde3facfd016f95487ae514a0e796a8b Mon Sep 17 00:00:00 2001 From: Kseniia Date: Wed, 6 Jan 2021 00:05:21 +0200 Subject: [PATCH 5/6] refactoring --- .../java/net/osmand/search/SearchUICore.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) 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 589dfb3b3f..df8c2bd5be 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java @@ -47,8 +47,6 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; -import java.util.stream.Stream; public class SearchUICore { @@ -72,7 +70,8 @@ public class SearchUICore { private static boolean debugMode = false; - private static final Set FILTER_DUPLICATE_POI_SUBTYPE = new TreeSet(Arrays.asList("building", "internet_access_yes")); + private static final Set FILTER_DUPLICATE_POI_SUBTYPE = new TreeSet( + Arrays.asList("building", "internet_access_yes")); public SearchUICore(MapPoiTypes poiTypes, String locale, boolean transliterate) { this.poiTypes = poiTypes; @@ -252,17 +251,12 @@ public class SearchUICore { String subType2 = a2.getSubType(); boolean isEqualId = a1.getId().longValue() == a2.getId().longValue(); - + if (isEqualId && (FILTER_DUPLICATE_POI_SUBTYPE.contains(subType1) || FILTER_DUPLICATE_POI_SUBTYPE.contains(subType2))) { return true; - } - if (!type1.equals(type2)) { - if (isEqualId && (FILTER_DUPLICATE_POI_SUBTYPE.contains(subType1) - || FILTER_DUPLICATE_POI_SUBTYPE.contains(subType2))) { - return true; - } + } else if (!type1.equals(type2)) { return false; } @@ -1004,19 +998,29 @@ public class SearchUICore { Amenity a1 = (Amenity) o1.object; Amenity a2 = (Amenity) o2.object; + String type1 = a1.getType().getKeyName(); + String type2 = a2.getType().getKeyName(); String subType1 = a1.getSubType() == null ? "" : a1.getSubType(); String subType2 = a2.getSubType() == null ? "" : a2.getSubType(); - int cmp; + int cmp = 0; if (FILTER_DUPLICATE_POI_SUBTYPE.contains(subType1)) { cmp = 1; } else if (FILTER_DUPLICATE_POI_SUBTYPE.contains(subType2)) { cmp = -1; - } else { - cmp = c.collator.compare(subType1, subType2); + } + + if (cmp != 0) { + return cmp; } + cmp = c.collator.compare(type1, type2); + if (cmp != 0) { + return cmp; + } + + cmp = c.collator.compare(subType1, subType2); if (cmp != 0) { return cmp; } From 2ebbcb8a9078d19107c92de76aa8b50194f0b62e Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 6 Jan 2021 13:41:15 +0200 Subject: [PATCH 6/6] fix typo --- OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index b8835ff2c6..b2cef88e80 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -2544,7 +2544,7 @@ public class GPXUtilities { if (maxlat == null) { maxlat = parser.getAttributeValue("", "maxLat"); } - if (maxlat == null) { + if (maxlon == null) { maxlon = parser.getAttributeValue("", "maxLon"); }