OsmAnd/OsmAnd-java/src/net/osmand/OsmAndCollator.java

42 lines
1.1 KiB
Java
Raw Normal View History

2014-04-12 23:37:18 +02:00
package net.osmand;
import java.util.Locale;
public class OsmAndCollator {
public static net.osmand.Collator primaryCollator() {
2016-02-19 16:52:16 +01:00
// romanian locale encounters diacritics as different symbols
2014-04-12 23:37:18 +02:00
final java.text.Collator instance = Locale.getDefault().getLanguage().equals("ro") ||
Locale.getDefault().getLanguage().equals("cs") ||
2014-04-12 23:37:18 +02:00
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);
}
};
}
}