Fix collator issue
This commit is contained in:
parent
c7c6a74efc
commit
2dc9e63dc9
12 changed files with 58 additions and 75 deletions
|
@ -22,7 +22,7 @@ public class CollatorStringMatcher implements StringMatcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
public CollatorStringMatcher(String part, StringMatcherMode mode) {
|
public CollatorStringMatcher(String part, StringMatcherMode mode) {
|
||||||
this.collator = PlatformUtil.primaryCollator();
|
this.collator = OsmAndCollator.primaryCollator();
|
||||||
this.part = part;
|
this.part = part;
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
}
|
}
|
||||||
|
|
40
OsmAnd-java/src/net/osmand/OsmAndCollator.java
Normal file
40
OsmAnd-java/src/net/osmand/OsmAndCollator.java
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
package net.osmand;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class OsmAndCollator {
|
||||||
|
|
||||||
|
public static net.osmand.Collator primaryCollator() {
|
||||||
|
// romanian locale encounters diacritics as differnet symbols
|
||||||
|
final java.text.Collator instance = Locale.getDefault().getLanguage().equals("ro") ||
|
||||||
|
Locale.getDefault().getLanguage().equals("sk")? java.text.Collator.getInstance(Locale.US)
|
||||||
|
: java.text.Collator.getInstance();
|
||||||
|
instance.setStrength(java.text.Collator.PRIMARY);
|
||||||
|
return wrapCollator(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static net.osmand.Collator wrapCollator(final java.text.Collator instance) {
|
||||||
|
return new net.osmand.Collator() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(Object o1, Object o2) {
|
||||||
|
return instance.compare(o1, o2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
return instance.equals(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(String source, String target) {
|
||||||
|
return instance.equals(source, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(String source, String target) {
|
||||||
|
return instance.compare(source, target);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,38 +27,4 @@ public class PlatformUtil {
|
||||||
return new org.kxml2.io.KXmlParser();
|
return new org.kxml2.io.KXmlParser();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static net.osmand.Collator primaryCollator() {
|
|
||||||
// romanian locale encounters diacritics as differnet symbols
|
|
||||||
final java.text.Collator instance = Locale.getDefault().getLanguage().equals("ro") ||
|
|
||||||
Locale.getDefault().getLanguage().equals("sk")? java.text.Collator.getInstance(Locale.US)
|
|
||||||
: java.text.Collator.getInstance();
|
|
||||||
instance.setStrength(java.text.Collator.PRIMARY);
|
|
||||||
return wrapCollator(instance);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static net.osmand.Collator wrapCollator(final java.text.Collator instance) {
|
|
||||||
return new net.osmand.Collator() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compare(Object o1, Object o2) {
|
|
||||||
return instance.compare(o1, o2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
return instance.equals(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(String source, String target) {
|
|
||||||
return instance.equals(source, target);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compare(String source, String target) {
|
|
||||||
return instance.compare(source, target);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import java.util.Map.Entry;
|
||||||
import net.osmand.Collator;
|
import net.osmand.Collator;
|
||||||
import net.osmand.CollatorStringMatcher;
|
import net.osmand.CollatorStringMatcher;
|
||||||
import net.osmand.CollatorStringMatcher.StringMatcherMode;
|
import net.osmand.CollatorStringMatcher.StringMatcherMode;
|
||||||
|
import net.osmand.OsmAndCollator;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.ResultMatcher;
|
import net.osmand.ResultMatcher;
|
||||||
import net.osmand.StringMatcher;
|
import net.osmand.StringMatcher;
|
||||||
|
@ -1223,7 +1224,7 @@ public class BinaryMapIndexReader {
|
||||||
if (query == null || query.length() == 0) {
|
if (query == null || query.length() == 0) {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
Collator collator = PlatformUtil.primaryCollator();
|
Collator collator = OsmAndCollator.primaryCollator();
|
||||||
for (PoiRegion poiIndex : poiIndexes) {
|
for (PoiRegion poiIndex : poiIndexes) {
|
||||||
poiAdapter.initCategories(poiIndex);
|
poiAdapter.initCategories(poiIndex);
|
||||||
for (int i = 0; i < poiIndex.categories.size(); i++) {
|
for (int i = 0; i < poiIndex.categories.size(); i++) {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.OsmAndCollator;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
public class City extends MapObject {
|
public class City extends MapObject {
|
||||||
|
@ -42,7 +42,7 @@ public class City extends MapObject {
|
||||||
|
|
||||||
private CityType type = null;
|
private CityType type = null;
|
||||||
// Be attentive ! Working with street names ignoring case
|
// Be attentive ! Working with street names ignoring case
|
||||||
private Map<String, Street> streets = new TreeMap<String, Street>(PlatformUtil.primaryCollator());
|
private Map<String, Street> streets = new TreeMap<String, Street>(OsmAndCollator.primaryCollator());
|
||||||
private String isin = null;
|
private String isin = null;
|
||||||
private String postcode = null;
|
private String postcode = null;
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import java.io.Serializable;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
||||||
import net.osmand.Collator;
|
import net.osmand.Collator;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.OsmAndCollator;
|
||||||
|
|
||||||
|
|
||||||
public abstract class MapObject implements Comparable<MapObject>, Serializable {
|
public abstract class MapObject implements Comparable<MapObject>, Serializable {
|
||||||
|
@ -66,7 +66,7 @@ public abstract class MapObject implements Comparable<MapObject>, Serializable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(MapObject o) {
|
public int compareTo(MapObject o) {
|
||||||
return PlatformUtil.primaryCollator().compare(getName(), o.getName());
|
return OsmAndCollator.primaryCollator().compare(getName(), o.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFileOffset() {
|
public int getFileOffset() {
|
||||||
|
@ -109,7 +109,7 @@ public abstract class MapObject implements Comparable<MapObject>, Serializable {
|
||||||
|
|
||||||
public static class MapObjectComparator implements Comparator<MapObject>{
|
public static class MapObjectComparator implements Comparator<MapObject>{
|
||||||
private final boolean en;
|
private final boolean en;
|
||||||
Collator collator = PlatformUtil.primaryCollator();
|
Collator collator = OsmAndCollator.primaryCollator();
|
||||||
public MapObjectComparator(boolean en){
|
public MapObjectComparator(boolean en){
|
||||||
this.en = en;
|
this.en = en;
|
||||||
}
|
}
|
||||||
|
|
|
@ -199,8 +199,10 @@ public class RoutePlannerFrontEnd {
|
||||||
RouteRegion[] regions = ctx.reverseMap.keySet().toArray(new BinaryMapRouteReaderAdapter.RouteRegion[ctx.reverseMap.size()]);
|
RouteRegion[] regions = ctx.reverseMap.keySet().toArray(new BinaryMapRouteReaderAdapter.RouteRegion[ctx.reverseMap.size()]);
|
||||||
ctx.checkOldRoutingFiles(ctx.startX, ctx.startY);
|
ctx.checkOldRoutingFiles(ctx.startX, ctx.startY);
|
||||||
ctx.checkOldRoutingFiles(ctx.targetX, ctx.targetY);
|
ctx.checkOldRoutingFiles(ctx.targetX, ctx.targetY);
|
||||||
|
long time = System.currentTimeMillis();
|
||||||
RouteSegmentResult[] res = ctx.nativeLib.runNativeRouting(ctx.startX, ctx.startY, ctx.targetX, ctx.targetY,
|
RouteSegmentResult[] res = ctx.nativeLib.runNativeRouting(ctx.startX, ctx.startY, ctx.targetX, ctx.targetY,
|
||||||
ctx.config, regions, ctx.calculationProgress, ctx.precalculatedRouteDirection, ctx.calculationMode == RouteCalculationMode.BASE);
|
ctx.config, regions, ctx.calculationProgress, ctx.precalculatedRouteDirection, ctx.calculationMode == RouteCalculationMode.BASE);
|
||||||
|
System.out.println("Native routing took " + (System.currentTimeMillis() - time) / 1000f + " seconds");
|
||||||
ArrayList<RouteSegmentResult> result = new ArrayList<RouteSegmentResult>(Arrays.asList(res));
|
ArrayList<RouteSegmentResult> result = new ArrayList<RouteSegmentResult>(Arrays.asList(res));
|
||||||
ctx.routingTime = ctx.calculationProgress.routingCalculatedTime;
|
ctx.routingTime = ctx.calculationProgress.routingCalculatedTime;
|
||||||
ctx.visitedSegments = ctx.calculationProgress.visitedSegments;
|
ctx.visitedSegments = ctx.calculationProgress.visitedSegments;
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
package net.osmand;
|
package net.osmand;
|
||||||
|
|
||||||
import java.text.Collator;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
import org.xmlpull.v1.XmlPullParserFactory;
|
|
||||||
import org.xmlpull.v1.XmlSerializer;
|
import org.xmlpull.v1.XmlSerializer;
|
||||||
|
|
||||||
import android.util.Xml;
|
import android.util.Xml;
|
||||||
|
@ -169,30 +166,5 @@ public class PlatformUtil {
|
||||||
return Xml.newSerializer();
|
return Xml.newSerializer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static net.osmand.Collator primaryCollator(){
|
|
||||||
final Collator instance = Collator.getInstance();
|
|
||||||
instance.setStrength(Collator.PRIMARY);
|
|
||||||
return new net.osmand.Collator() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compare(Object o1, Object o2) {
|
|
||||||
return instance.compare(o1, o2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
return instance.equals(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(String source, String target) {
|
|
||||||
return instance.equals(source, target);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compare(String source, String target) {
|
|
||||||
return instance.compare(source, target);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import java.util.Map;
|
||||||
import net.osmand.Collator;
|
import net.osmand.Collator;
|
||||||
import net.osmand.CollatorStringMatcher;
|
import net.osmand.CollatorStringMatcher;
|
||||||
import net.osmand.CollatorStringMatcher.StringMatcherMode;
|
import net.osmand.CollatorStringMatcher.StringMatcherMode;
|
||||||
|
import net.osmand.OsmAndCollator;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.MapObject;
|
import net.osmand.data.MapObject;
|
||||||
|
@ -113,7 +114,7 @@ public abstract class SearchByNameAbstractActivity<T> extends OsmandListActivity
|
||||||
final NamesAdapter namesAdapter = new NamesAdapter(new ArrayList<T>(), createComparator()); //$NON-NLS-1$
|
final NamesAdapter namesAdapter = new NamesAdapter(new ArrayList<T>(), createComparator()); //$NON-NLS-1$
|
||||||
setListAdapter(namesAdapter);
|
setListAdapter(namesAdapter);
|
||||||
|
|
||||||
collator = PlatformUtil.primaryCollator();
|
collator = OsmAndCollator.primaryCollator();
|
||||||
|
|
||||||
|
|
||||||
progress = (ProgressBar) findViewById(R.id.ProgressBar);
|
progress = (ProgressBar) findViewById(R.id.ProgressBar);
|
||||||
|
|
|
@ -6,7 +6,7 @@ import java.util.List;
|
||||||
|
|
||||||
import net.osmand.CollatorStringMatcher;
|
import net.osmand.CollatorStringMatcher;
|
||||||
import net.osmand.CollatorStringMatcher.StringMatcherMode;
|
import net.osmand.CollatorStringMatcher.StringMatcherMode;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.OsmAndCollator;
|
||||||
import net.osmand.ResultMatcher;
|
import net.osmand.ResultMatcher;
|
||||||
import net.osmand.data.City;
|
import net.osmand.data.City;
|
||||||
import net.osmand.data.City.CityType;
|
import net.osmand.data.City.CityType;
|
||||||
|
@ -180,7 +180,7 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity<City>
|
||||||
private CityComparator(StringMatcherMode startsWith,
|
private CityComparator(StringMatcherMode startsWith,
|
||||||
boolean en) {
|
boolean en) {
|
||||||
this.startsWith = startsWith;
|
this.startsWith = startsWith;
|
||||||
this.cs = PlatformUtil.primaryCollator();
|
this.cs = OsmAndCollator.primaryCollator();
|
||||||
this.en = en;
|
this.en = en;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import java.util.TreeMap;
|
||||||
import net.osmand.Collator;
|
import net.osmand.Collator;
|
||||||
import net.osmand.CollatorStringMatcher;
|
import net.osmand.CollatorStringMatcher;
|
||||||
import net.osmand.CollatorStringMatcher.StringMatcherMode;
|
import net.osmand.CollatorStringMatcher.StringMatcherMode;
|
||||||
|
import net.osmand.OsmAndCollator;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.ResultMatcher;
|
import net.osmand.ResultMatcher;
|
||||||
import net.osmand.binary.BinaryMapAddressReaderAdapter;
|
import net.osmand.binary.BinaryMapAddressReaderAdapter;
|
||||||
|
@ -40,8 +41,8 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
|
||||||
public RegionAddressRepositoryBinary(BinaryMapIndexReader file, String name) {
|
public RegionAddressRepositoryBinary(BinaryMapIndexReader file, String name) {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
this.region = name;
|
this.region = name;
|
||||||
this.collator = PlatformUtil.primaryCollator();
|
this.collator = OsmAndCollator.primaryCollator();
|
||||||
this.postCodes = new TreeMap<String, City>(PlatformUtil.primaryCollator());
|
this.postCodes = new TreeMap<String, City>(OsmAndCollator.primaryCollator());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue