Merge pull request #2609 from osmandapp/obf-merge

[WIP] Obf merge
This commit is contained in:
vshcherb 2016-05-30 22:06:12 +02:00
commit cea1435200
7 changed files with 126 additions and 55 deletions

View file

@ -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;
@ -49,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;
@ -120,12 +118,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;
@ -1068,18 +1066,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.ACCEPT_ALL_POI_TYPE_FILTER,
new ResultMatcher<Amenity>() {
@Override
public boolean publish(Amenity object) {

View file

@ -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,6 +1556,18 @@ public class BinaryMapIndexReader {
public boolean isEmpty();
}
public static final SearchPoiTypeFilter ACCEPT_ALL_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 +2158,7 @@ public class BinaryMapIndexReader {
println(" " + poiRegion.subcategories.get(i));
}
SearchRequest<Amenity> 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<Amenity> req = buildSearchPoiRequest(sleft, sright, stop, sbottom, -1, ACCEPT_ALL_POI_TYPE_FILTER, null);
List<Amenity> results = reader.searchPoi(req);
for (Amenity a : results) {
println(a.getType() + " " + a.getSubType() + " " + a.getName() + " " + a.getLocation());

View file

@ -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,21 @@ public class Amenity extends MapObject {
setAdditionalInfo(OPENING_HOURS, openingHours);
}
public static class AmenityByIdComparator implements Comparator<Amenity> {
@Override
public int compare(Amenity a1, Amenity a2) {
int result = MapObject.BY_ID_COMPARATOR.compare(a1, a2);
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) && a1.subType.equals(a2.subType);
}
}
}

View file

@ -19,7 +19,8 @@ import net.sf.junidecode.Junidecode;
public abstract class MapObject implements Comparable<MapObject> {
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;
@ -208,7 +209,7 @@ public abstract class MapObject implements Comparable<MapObject> {
return false;
return true;
}
public static class MapObjectComparator implements Comparator<MapObject> {
private final String l;
Collator collator = OsmAndCollator.primaryCollator();
@ -220,7 +221,7 @@ public abstract class MapObject implements Comparable<MapObject> {
public MapObjectComparator(String lang) {
this.l = lang;
}
@Override
public int compare(MapObject o1, MapObject o2) {
if (o1 == null ^ o2 == null) {
@ -233,14 +234,33 @@ public abstract class MapObject implements Comparable<MapObject> {
}
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));
}
}
}
public static class MapObjectByIdComparator implements Comparator<MapObject> {
@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) {
return o2 == null;
} else {
return o1.id.equals(o2.id);
}
}
}
}

View file

@ -8,7 +8,7 @@ import java.util.Map;
import java.util.Set;
public class PoiCategory extends PoiFilter {
public class PoiCategory extends PoiFilter implements Comparable<PoiCategory> {
private List<PoiFilter> poiFilters = new ArrayList<PoiFilter>();
private Set<PoiType> 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 + ")";
}
}

View file

@ -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;
}
}
public static <T> Set<T> findDuplicates(Collection<T> list) {
Set<T> duplicates = new LinkedHashSet<T>();
Set<T> uniques = new HashSet<T>();
for (T t : list) {
if (!uniques.add(t)) {
duplicates.add(t);
}
}
return duplicates;
}
}

View file

@ -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 {
@ -134,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) {
@ -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;
}