From 2dc9e63dc947c12117d609fa665dc7fe00310e3f Mon Sep 17 00:00:00 2001 From: vshcherb Date: Sat, 12 Apr 2014 23:37:18 +0200 Subject: [PATCH] Fix collator issue --- OsmAnd-java/src/net/osmand/Collator.java | 2 +- .../src/net/osmand/CollatorStringMatcher.java | 2 +- .../src/net/osmand/OsmAndCollator.java | 40 +++++++++++++++++++ OsmAnd-java/src/net/osmand/PlatformUtil.java | 34 ---------------- .../osmand/binary/BinaryMapIndexReader.java | 3 +- OsmAnd-java/src/net/osmand/data/City.java | 4 +- .../src/net/osmand/data/MapObject.java | 6 +-- .../osmand/router/RoutePlannerFrontEnd.java | 2 + OsmAnd/src/net/osmand/PlatformUtil.java | 28 ------------- .../search/SearchByNameAbstractActivity.java | 3 +- .../search/SearchCityByNameActivity.java | 4 +- .../RegionAddressRepositoryBinary.java | 5 ++- 12 files changed, 58 insertions(+), 75 deletions(-) create mode 100644 OsmAnd-java/src/net/osmand/OsmAndCollator.java diff --git a/OsmAnd-java/src/net/osmand/Collator.java b/OsmAnd-java/src/net/osmand/Collator.java index 3991947b01..7fd96f0bc6 100644 --- a/OsmAnd-java/src/net/osmand/Collator.java +++ b/OsmAnd-java/src/net/osmand/Collator.java @@ -3,7 +3,7 @@ package net.osmand; /** * Wrapper of java.text. Collator */ -public interface Collator extends java.util.Comparator, Cloneable{ +public interface Collator extends java.util.Comparator, Cloneable { public boolean equals(String source, String target); diff --git a/OsmAnd-java/src/net/osmand/CollatorStringMatcher.java b/OsmAnd-java/src/net/osmand/CollatorStringMatcher.java index 0b9419ef88..1fa8ce9088 100644 --- a/OsmAnd-java/src/net/osmand/CollatorStringMatcher.java +++ b/OsmAnd-java/src/net/osmand/CollatorStringMatcher.java @@ -22,7 +22,7 @@ public class CollatorStringMatcher implements StringMatcher { } public CollatorStringMatcher(String part, StringMatcherMode mode) { - this.collator = PlatformUtil.primaryCollator(); + this.collator = OsmAndCollator.primaryCollator(); this.part = part; this.mode = mode; } diff --git a/OsmAnd-java/src/net/osmand/OsmAndCollator.java b/OsmAnd-java/src/net/osmand/OsmAndCollator.java new file mode 100644 index 0000000000..1ba11f3d60 --- /dev/null +++ b/OsmAnd-java/src/net/osmand/OsmAndCollator.java @@ -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); + } + }; + } +} diff --git a/OsmAnd-java/src/net/osmand/PlatformUtil.java b/OsmAnd-java/src/net/osmand/PlatformUtil.java index a3517ff0ba..97149ef97f 100644 --- a/OsmAnd-java/src/net/osmand/PlatformUtil.java +++ b/OsmAnd-java/src/net/osmand/PlatformUtil.java @@ -27,38 +27,4 @@ public class PlatformUtil { 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); - } - }; - } } diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java b/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java index b48ee00f61..8f898b60de 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java @@ -20,6 +20,7 @@ import java.util.Map.Entry; import net.osmand.Collator; import net.osmand.CollatorStringMatcher; import net.osmand.CollatorStringMatcher.StringMatcherMode; +import net.osmand.OsmAndCollator; import net.osmand.PlatformUtil; import net.osmand.ResultMatcher; import net.osmand.StringMatcher; @@ -1223,7 +1224,7 @@ public class BinaryMapIndexReader { if (query == null || query.length() == 0) { throw new IllegalArgumentException(); } - Collator collator = PlatformUtil.primaryCollator(); + Collator collator = OsmAndCollator.primaryCollator(); for (PoiRegion poiIndex : poiIndexes) { poiAdapter.initCategories(poiIndex); for (int i = 0; i < poiIndex.categories.size(); i++) { diff --git a/OsmAnd-java/src/net/osmand/data/City.java b/OsmAnd-java/src/net/osmand/data/City.java index cbadc9c975..1ed62b8ecd 100644 --- a/OsmAnd-java/src/net/osmand/data/City.java +++ b/OsmAnd-java/src/net/osmand/data/City.java @@ -4,7 +4,7 @@ import java.util.Collection; import java.util.Map; import java.util.TreeMap; -import net.osmand.PlatformUtil; +import net.osmand.OsmAndCollator; import net.osmand.util.Algorithms; public class City extends MapObject { @@ -42,7 +42,7 @@ public class City extends MapObject { private CityType type = null; // Be attentive ! Working with street names ignoring case - private Map streets = new TreeMap(PlatformUtil.primaryCollator()); + private Map streets = new TreeMap(OsmAndCollator.primaryCollator()); private String isin = null; private String postcode = null; diff --git a/OsmAnd-java/src/net/osmand/data/MapObject.java b/OsmAnd-java/src/net/osmand/data/MapObject.java index 291929eb66..f35b695a1f 100644 --- a/OsmAnd-java/src/net/osmand/data/MapObject.java +++ b/OsmAnd-java/src/net/osmand/data/MapObject.java @@ -5,7 +5,7 @@ import java.io.Serializable; import java.util.Comparator; import net.osmand.Collator; -import net.osmand.PlatformUtil; +import net.osmand.OsmAndCollator; public abstract class MapObject implements Comparable, Serializable { @@ -66,7 +66,7 @@ public abstract class MapObject implements Comparable, Serializable { @Override public int compareTo(MapObject o) { - return PlatformUtil.primaryCollator().compare(getName(), o.getName()); + return OsmAndCollator.primaryCollator().compare(getName(), o.getName()); } public int getFileOffset() { @@ -109,7 +109,7 @@ public abstract class MapObject implements Comparable, Serializable { public static class MapObjectComparator implements Comparator{ private final boolean en; - Collator collator = PlatformUtil.primaryCollator(); + Collator collator = OsmAndCollator.primaryCollator(); public MapObjectComparator(boolean en){ this.en = en; } diff --git a/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java b/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java index 82fc93bbb2..8191ff5fe0 100644 --- a/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java +++ b/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java @@ -199,8 +199,10 @@ public class RoutePlannerFrontEnd { RouteRegion[] regions = ctx.reverseMap.keySet().toArray(new BinaryMapRouteReaderAdapter.RouteRegion[ctx.reverseMap.size()]); ctx.checkOldRoutingFiles(ctx.startX, ctx.startY); ctx.checkOldRoutingFiles(ctx.targetX, ctx.targetY); + long time = System.currentTimeMillis(); RouteSegmentResult[] res = ctx.nativeLib.runNativeRouting(ctx.startX, ctx.startY, ctx.targetX, ctx.targetY, ctx.config, regions, ctx.calculationProgress, ctx.precalculatedRouteDirection, ctx.calculationMode == RouteCalculationMode.BASE); + System.out.println("Native routing took " + (System.currentTimeMillis() - time) / 1000f + " seconds"); ArrayList result = new ArrayList(Arrays.asList(res)); ctx.routingTime = ctx.calculationProgress.routingCalculatedTime; ctx.visitedSegments = ctx.calculationProgress.visitedSegments; diff --git a/OsmAnd/src/net/osmand/PlatformUtil.java b/OsmAnd/src/net/osmand/PlatformUtil.java index 76afb9fe30..68cecdec45 100644 --- a/OsmAnd/src/net/osmand/PlatformUtil.java +++ b/OsmAnd/src/net/osmand/PlatformUtil.java @@ -1,11 +1,8 @@ package net.osmand; -import java.text.Collator; - import org.apache.commons.logging.Log; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; -import org.xmlpull.v1.XmlPullParserFactory; import org.xmlpull.v1.XmlSerializer; import android.util.Xml; @@ -169,30 +166,5 @@ public class PlatformUtil { 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); - } - }; - } } diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchByNameAbstractActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchByNameAbstractActivity.java index deb0b00201..d92b062186 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchByNameAbstractActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchByNameAbstractActivity.java @@ -12,6 +12,7 @@ import java.util.Map; import net.osmand.Collator; import net.osmand.CollatorStringMatcher; import net.osmand.CollatorStringMatcher.StringMatcherMode; +import net.osmand.OsmAndCollator; import net.osmand.PlatformUtil; import net.osmand.data.LatLon; import net.osmand.data.MapObject; @@ -113,7 +114,7 @@ public abstract class SearchByNameAbstractActivity extends OsmandListActivity final NamesAdapter namesAdapter = new NamesAdapter(new ArrayList(), createComparator()); //$NON-NLS-1$ setListAdapter(namesAdapter); - collator = PlatformUtil.primaryCollator(); + collator = OsmAndCollator.primaryCollator(); progress = (ProgressBar) findViewById(R.id.ProgressBar); diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchCityByNameActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchCityByNameActivity.java index 73606fe1ac..f041a952ce 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchCityByNameActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchCityByNameActivity.java @@ -6,7 +6,7 @@ import java.util.List; import net.osmand.CollatorStringMatcher; import net.osmand.CollatorStringMatcher.StringMatcherMode; -import net.osmand.PlatformUtil; +import net.osmand.OsmAndCollator; import net.osmand.ResultMatcher; import net.osmand.data.City; import net.osmand.data.City.CityType; @@ -180,7 +180,7 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity private CityComparator(StringMatcherMode startsWith, boolean en) { this.startsWith = startsWith; - this.cs = PlatformUtil.primaryCollator(); + this.cs = OsmAndCollator.primaryCollator(); this.en = en; } diff --git a/OsmAnd/src/net/osmand/plus/resources/RegionAddressRepositoryBinary.java b/OsmAnd/src/net/osmand/plus/resources/RegionAddressRepositoryBinary.java index 021af0c502..23d75f0077 100644 --- a/OsmAnd/src/net/osmand/plus/resources/RegionAddressRepositoryBinary.java +++ b/OsmAnd/src/net/osmand/plus/resources/RegionAddressRepositoryBinary.java @@ -12,6 +12,7 @@ import java.util.TreeMap; import net.osmand.Collator; import net.osmand.CollatorStringMatcher; import net.osmand.CollatorStringMatcher.StringMatcherMode; +import net.osmand.OsmAndCollator; import net.osmand.PlatformUtil; import net.osmand.ResultMatcher; import net.osmand.binary.BinaryMapAddressReaderAdapter; @@ -40,8 +41,8 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository { public RegionAddressRepositoryBinary(BinaryMapIndexReader file, String name) { this.file = file; this.region = name; - this.collator = PlatformUtil.primaryCollator(); - this.postCodes = new TreeMap(PlatformUtil.primaryCollator()); + this.collator = OsmAndCollator.primaryCollator(); + this.postCodes = new TreeMap(OsmAndCollator.primaryCollator()); } @Override