From a2984f5c7c59332f23fa6a7e75948980a1a89374 Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Sat, 28 May 2016 00:26:20 +0300 Subject: [PATCH 1/7] Add BinaryMapIndexReader.EMPTY_SEARCH_POI_TYPE_FILTER --- .../net/osmand/binary/BinaryInspector.java | 13 +--------- .../osmand/binary/BinaryMapIndexReader.java | 25 ++++++++++--------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java index 73a23c02e0..28b366bc4d 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java @@ -1068,18 +1068,7 @@ public class BinaryInspector { MapUtils.get31TileNumberY(verbose.lattop), MapUtils.get31TileNumberY(verbose.latbottom), verbose.getZoom(), - new SearchPoiTypeFilter() { - @Override - public boolean accept(PoiCategory type, String subcategory) { - return true; - } - - @Override - public boolean isEmpty() { - return false; - } - - }, + BinaryMapIndexReader.EMPTY_SEARCH_POI_TYPE_FILTER, new ResultMatcher() { @Override public boolean publish(Amenity object) { diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java b/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java index e4c1e544a7..b42c07e8c2 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java @@ -1557,6 +1557,18 @@ public class BinaryMapIndexReader { public boolean isEmpty(); } + public static final SearchPoiTypeFilter EMPTY_SEARCH_POI_TYPE_FILTER = new SearchPoiTypeFilter() { + @Override + public boolean accept(PoiCategory type, String subcategory) { + return true; + } + + @Override + public boolean isEmpty() { + return false; + } + }; + public static class MapObjectStat { public int lastStringNamesSize; public int lastObjectIdSize; @@ -2147,18 +2159,7 @@ public class BinaryMapIndexReader { println(" " + poiRegion.subcategories.get(i)); } - SearchRequest req = buildSearchPoiRequest(sleft, sright, stop, sbottom, -1, new SearchPoiTypeFilter() { - @Override - public boolean accept(PoiCategory type, String subcategory) { - return true; - } - - @Override - public boolean isEmpty() { - return false; - } - - }, null); + SearchRequest req = buildSearchPoiRequest(sleft, sright, stop, sbottom, -1, EMPTY_SEARCH_POI_TYPE_FILTER, null); List results = reader.searchPoi(req); for (Amenity a : results) { println(a.getType() + " " + a.getSubType() + " " + a.getName() + " " + a.getLocation()); From 9ac6faec250bc266d9e912feceda66bcb404f934 Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Sat, 28 May 2016 00:27:07 +0300 Subject: [PATCH 2/7] LATITUDE and LONGITUDE constants --- .../net/osmand/binary/BinaryInspector.java | 11 ++++---- .../src/net/osmand/data/MapObject.java | 4 +-- OsmAnd-java/src/net/osmand/util/MapUtils.java | 27 ++++++++++++------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java index 28b366bc4d..a7e34a3093 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java @@ -35,7 +35,6 @@ import net.osmand.binary.BinaryMapIndexReader.MapIndex; import net.osmand.binary.BinaryMapIndexReader.MapObjectStat; import net.osmand.binary.BinaryMapIndexReader.MapRoot; import net.osmand.binary.BinaryMapIndexReader.SearchFilter; -import net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter; import net.osmand.binary.BinaryMapIndexReader.SearchRequest; import net.osmand.binary.BinaryMapIndexReader.TagValuePair; import net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion; @@ -120,12 +119,12 @@ public class BinaryInspector { boolean vstats; boolean osm; FileOutputStream osmOut = null; - double lattop = 85; - double latbottom = -85; - double lonleft = -180; - double lonright = 180; + double lattop = MapUtils.LATITUDE_MIN; + double latbottom = MapUtils.LATITUDE_MAX; + double lonleft = MapUtils.LONGITUDE_MIN; + double lonright = MapUtils.LONGITUDE_MAX; String lang = null; - int zoom = -1; + int zoom = MapUtils.NO_ZOOM; public boolean isVaddress() { return vaddress; diff --git a/OsmAnd-java/src/net/osmand/data/MapObject.java b/OsmAnd-java/src/net/osmand/data/MapObject.java index 3c9eae0751..02e03a31a8 100644 --- a/OsmAnd-java/src/net/osmand/data/MapObject.java +++ b/OsmAnd-java/src/net/osmand/data/MapObject.java @@ -208,7 +208,7 @@ public abstract class MapObject implements Comparable { return false; return true; } - + public static class MapObjectComparator implements Comparator { private final String l; Collator collator = OsmAndCollator.primaryCollator(); @@ -220,7 +220,7 @@ public abstract class MapObject implements Comparable { public MapObjectComparator(String lang) { this.l = lang; } - + @Override public int compare(MapObject o1, MapObject o2) { if (o1 == null ^ o2 == null) { diff --git a/OsmAnd-java/src/net/osmand/util/MapUtils.java b/OsmAnd-java/src/net/osmand/util/MapUtils.java index 5246883e50..8665a3b4b8 100644 --- a/OsmAnd-java/src/net/osmand/util/MapUtils.java +++ b/OsmAnd-java/src/net/osmand/util/MapUtils.java @@ -19,12 +19,19 @@ import net.osmand.util.GeoPointParserUtil.GeoParsedPoint; */ public class MapUtils { - public static final double MIN_LATITUDE = -85.0511; - public static final double MAX_LATITUDE = 85.0511; + public static final double LATITUDE_MIN = -85.0511; + public static final double LATITUDE_MAX = 85.0511; public static final double LATITUDE_TURN = 180.0; - public static final double MIN_LONGITUDE = -180.0; - public static final double MAX_LONGITUDE = 180.0; + public static final double LONGITUDE_MIN = -180.0; + public static final double LONGITUDE_MAX = 180.0; public static final double LONGITUDE_TURN = 360.0; + public static final int[] MAP_BOUNDING_BOX_31_TILE_NUMBER = { + MapUtils.get31TileNumberX(LONGITUDE_MIN), + MapUtils.get31TileNumberX(LONGITUDE_MAX), + MapUtils.get31TileNumberY(LATITUDE_MAX), + MapUtils.get31TileNumberY(LATITUDE_MIN), + }; + public static final int NO_ZOOM = -1; // TODO change the hostname back to osm.org once HTTPS works for it // https://github.com/openstreetmap/operations/issues/2 @@ -120,10 +127,10 @@ public class MapUtils { } public static double checkLongitude(double longitude) { - if (longitude > MIN_LONGITUDE && longitude <= MAX_LONGITUDE) { + if (longitude > LONGITUDE_MIN && longitude <= LONGITUDE_MAX) { return longitude; } - while (longitude <= MIN_LONGITUDE || longitude > MAX_LONGITUDE) { + while (longitude < LONGITUDE_MIN || longitude > LONGITUDE_MAX) { if (longitude < 0) { longitude += LONGITUDE_TURN; } else { @@ -144,10 +151,10 @@ public class MapUtils { latitude -= LATITUDE_TURN; } } - if (latitude < MIN_LATITUDE) { - return MIN_LATITUDE; - } else if (latitude > MAX_LATITUDE) { - return MAX_LATITUDE; + if (latitude < LATITUDE_MIN) { + return LATITUDE_MIN; + } else if (latitude > LATITUDE_MAX) { + return LATITUDE_MAX; } return latitude; } From 4340405b5990ae43572eb71f0208c835581fe2a7 Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Sat, 28 May 2016 00:27:31 +0300 Subject: [PATCH 3/7] Add MapObjectByIdComparator --- .../src/net/osmand/data/MapObject.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/OsmAnd-java/src/net/osmand/data/MapObject.java b/OsmAnd-java/src/net/osmand/data/MapObject.java index 02e03a31a8..24cf5b2cad 100644 --- a/OsmAnd-java/src/net/osmand/data/MapObject.java +++ b/OsmAnd-java/src/net/osmand/data/MapObject.java @@ -19,7 +19,8 @@ import net.sf.junidecode.Junidecode; public abstract class MapObject implements Comparable { public static final MapObjectComparator BY_NAME_COMPARATOR = new MapObjectComparator(); - + public static final MapObjectByIdComparator BY_ID_COMPARATOR = new MapObjectByIdComparator(); + protected String name = null; protected String enName = null; @@ -241,6 +242,29 @@ public abstract class MapObject implements Comparable { return collator.equals(o1.getName(l), o2.getName(l)); } } + } + + public static class MapObjectByIdComparator implements Comparator { + @Override + public int compare(MapObject o1, MapObject o2) { + if (o1 == null ^ o2 == null) { + return (o1 == null) ? -1 : 1; + } else if (o1 == o2) { + return 0; + } else { + return Double.compare(o1.id, o2.id); + } + } + + public boolean areEqual(MapObject o1, MapObject o2) { + if (o1 == null ^ o2 == null) { + return false; + } else if (o1 == o2) { + return true; + } else { + return o1.id.equals(o2.id); + } + } } } From 1cdb28d2fc6d48967e3519c4656cedeed368927a Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Sat, 28 May 2016 09:48:48 +0300 Subject: [PATCH 4/7] LATITUDE and LONGITUDE constants --- OsmAnd-java/src/net/osmand/util/MapUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd-java/src/net/osmand/util/MapUtils.java b/OsmAnd-java/src/net/osmand/util/MapUtils.java index 8665a3b4b8..8b9081fcb9 100644 --- a/OsmAnd-java/src/net/osmand/util/MapUtils.java +++ b/OsmAnd-java/src/net/osmand/util/MapUtils.java @@ -141,7 +141,7 @@ public class MapUtils { } public static double checkLatitude(double latitude) { - if (latitude >= MIN_LATITUDE && latitude <= MAX_LATITUDE) { + if (latitude > LATITUDE_MIN && latitude <= LATITUDE_MAX) { return latitude; } while (latitude < -90 || latitude > 90) { From e7897826caf7fd5db4d437640339af6974fb9717 Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Mon, 30 May 2016 09:43:21 +0300 Subject: [PATCH 5/7] Rename: EMPTY_SEARCH_POI_TYPE_FILTER -> ACCEPT_ALL_POI_TYPE_FILTER --- OsmAnd-java/src/net/osmand/binary/BinaryInspector.java | 3 +-- OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java index a7e34a3093..f71690557f 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java @@ -48,7 +48,6 @@ import net.osmand.data.Building; import net.osmand.data.City; import net.osmand.data.MapObject; import net.osmand.data.Street; -import net.osmand.osm.PoiCategory; import net.osmand.util.MapUtils; import com.google.protobuf.CodedOutputStream; @@ -1067,7 +1066,7 @@ public class BinaryInspector { MapUtils.get31TileNumberY(verbose.lattop), MapUtils.get31TileNumberY(verbose.latbottom), verbose.getZoom(), - BinaryMapIndexReader.EMPTY_SEARCH_POI_TYPE_FILTER, + BinaryMapIndexReader.ACCEPT_ALL_POI_TYPE_FILTER, new ResultMatcher() { @Override public boolean publish(Amenity object) { diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java b/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java index b42c07e8c2..01d7dac157 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java @@ -21,7 +21,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; -import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -1557,7 +1556,7 @@ public class BinaryMapIndexReader { public boolean isEmpty(); } - public static final SearchPoiTypeFilter EMPTY_SEARCH_POI_TYPE_FILTER = new SearchPoiTypeFilter() { + public static final SearchPoiTypeFilter ACCEPT_ALL_POI_TYPE_FILTER = new SearchPoiTypeFilter() { @Override public boolean accept(PoiCategory type, String subcategory) { return true; @@ -2159,7 +2158,7 @@ public class BinaryMapIndexReader { println(" " + poiRegion.subcategories.get(i)); } - SearchRequest req = buildSearchPoiRequest(sleft, sright, stop, sbottom, -1, EMPTY_SEARCH_POI_TYPE_FILTER, null); + SearchRequest req = buildSearchPoiRequest(sleft, sright, stop, sbottom, -1, ACCEPT_ALL_POI_TYPE_FILTER, null); List results = reader.searchPoi(req); for (Amenity a : results) { println(a.getType() + " " + a.getSubType() + " " + a.getName() + " " + a.getLocation()); From e0fc6d64c55a16f02f8ef51e782f4a09d8db939e Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Mon, 30 May 2016 15:06:53 +0300 Subject: [PATCH 6/7] Add Amenity and PoiFilter comparators --- OsmAnd-java/src/net/osmand/data/Amenity.java | 14 ++++++++- .../src/net/osmand/data/MapObject.java | 12 +++----- .../src/net/osmand/osm/PoiCategory.java | 30 +++++++++++++++++-- .../src/net/osmand/util/Algorithms.java | 17 ++++++++++- 4 files changed, 60 insertions(+), 13 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/data/Amenity.java b/OsmAnd-java/src/net/osmand/data/Amenity.java index c14e2fa9db..ba88265286 100644 --- a/OsmAnd-java/src/net/osmand/data/Amenity.java +++ b/OsmAnd-java/src/net/osmand/data/Amenity.java @@ -10,6 +10,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; @@ -19,6 +20,7 @@ import java.util.zip.GZIPInputStream; public class Amenity extends MapObject { + public static final AmenityByIdComparator BY_ID_COMPARATOR = new AmenityByIdComparator(); public static final String WEBSITE = "website"; public static final String PHONE = "phone"; @@ -249,5 +251,15 @@ public class Amenity extends MapObject { setAdditionalInfo(OPENING_HOURS, openingHours); } - + public static class AmenityByIdComparator implements Comparator { + @Override + public int compare(Amenity a1, Amenity a2) { + int result = MapObject.BY_ID_COMPARATOR.compare(a1, a2); + return result != 0 ? result : a1.type.compareTo(a2.type); + } + + public boolean areEqual(Amenity a1, Amenity a2) { + return MapObject.BY_ID_COMPARATOR.areEqual(a1, a2) && a1.type.equals(a2.type); + } + } } diff --git a/OsmAnd-java/src/net/osmand/data/MapObject.java b/OsmAnd-java/src/net/osmand/data/MapObject.java index 24cf5b2cad..6bf76f6dec 100644 --- a/OsmAnd-java/src/net/osmand/data/MapObject.java +++ b/OsmAnd-java/src/net/osmand/data/MapObject.java @@ -234,10 +234,8 @@ public abstract class MapObject implements Comparable { } public boolean areEqual(MapObject o1, MapObject o2) { - if (o1 == null ^ o2 == null) { - return false; - } else if (o1 == o2) { - return true; + if (o1 == null) { + return o2 == null; } else { return collator.equals(o1.getName(l), o2.getName(l)); } @@ -257,10 +255,8 @@ public abstract class MapObject implements Comparable { } public boolean areEqual(MapObject o1, MapObject o2) { - if (o1 == null ^ o2 == null) { - return false; - } else if (o1 == o2) { - return true; + if (o1 == null) { + return o2 == null; } else { return o1.id.equals(o2.id); } diff --git a/OsmAnd-java/src/net/osmand/osm/PoiCategory.java b/OsmAnd-java/src/net/osmand/osm/PoiCategory.java index 33c1ff89fa..cb0a94b9fa 100644 --- a/OsmAnd-java/src/net/osmand/osm/PoiCategory.java +++ b/OsmAnd-java/src/net/osmand/osm/PoiCategory.java @@ -8,7 +8,7 @@ import java.util.Map; import java.util.Set; -public class PoiCategory extends PoiFilter { +public class PoiCategory extends PoiFilter implements Comparable { private List poiFilters = new ArrayList(); private Set basemapPoi = null; @@ -30,8 +30,7 @@ public class PoiCategory extends PoiFilter { public String getDefaultTag() { if(defaultTag == null) { - return keyName; - } + return keyName; } return defaultTag; } @@ -70,4 +69,29 @@ public class PoiCategory extends PoiFilter { } return basemapPoi.contains(pt); } + + @Override + public boolean equals(Object o) { + if (!(o instanceof PoiCategory)) { + return false; + } + PoiCategory other = (PoiCategory) o; + return regId == other.regId; + } + + @Override + public int hashCode() { + return regId; + } + + @Override + public int compareTo(PoiCategory poiCategory) { + return Double.compare(regId, poiCategory.regId); + } + + @Override + public String toString() { + return keyName + " (" + regId + ")"; + } + } diff --git a/OsmAnd-java/src/net/osmand/util/Algorithms.java b/OsmAnd-java/src/net/osmand/util/Algorithms.java index 99bff0bc20..a3583fe133 100644 --- a/OsmAnd-java/src/net/osmand/util/Algorithms.java +++ b/OsmAnd-java/src/net/osmand/util/Algorithms.java @@ -16,13 +16,17 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedHashSet; import java.util.Locale; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; /** @@ -595,4 +599,15 @@ public class Algorithms { return 0xFFFF00FF; } -} \ No newline at end of file + public static Set findDuplicates(Collection list) { + Set duplicates = new LinkedHashSet(); + Set uniques = new HashSet(); + for (T t : list) { + if (!uniques.add(t)) { + duplicates.add(t); + } + } + return duplicates; + } + +} From d34f906b48f6ac5c43bdb3078ba6609478515d3a Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Mon, 30 May 2016 22:27:39 +0300 Subject: [PATCH 7/7] Amenity comparator --- OsmAnd-java/src/net/osmand/data/Amenity.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/data/Amenity.java b/OsmAnd-java/src/net/osmand/data/Amenity.java index ba88265286..e303051baf 100644 --- a/OsmAnd-java/src/net/osmand/data/Amenity.java +++ b/OsmAnd-java/src/net/osmand/data/Amenity.java @@ -255,11 +255,17 @@ public class Amenity extends MapObject { @Override public int compare(Amenity a1, Amenity a2) { int result = MapObject.BY_ID_COMPARATOR.compare(a1, a2); - return result != 0 ? result : a1.type.compareTo(a2.type); + if (result == 0) { + result = a1.type.compareTo(a2.type); + } + if (result == 0) { + result = a1.subType.compareTo(a2.subType); + } + return result; } public boolean areEqual(Amenity a1, Amenity a2) { - return MapObject.BY_ID_COMPARATOR.areEqual(a1, a2) && a1.type.equals(a2.type); + return MapObject.BY_ID_COMPARATOR.areEqual(a1, a2) && a1.type.equals(a2.type) && a1.subType.equals(a2.subType); } } }