use of java.text.Collator in project robovm by robovm.
the class CollatorTest method test_collationKeySize.
public void test_collationKeySize() throws Exception {
// Test to verify that very large collation keys are not truncated.
StringBuilder b = new StringBuilder();
for (int i = 0; i < 1024; i++) {
b.append("0123456789ABCDEF");
}
String sixteen = b.toString();
b.append("_THE_END");
String sixteenplus = b.toString();
Collator mColl = Collator.getInstance();
mColl.setStrength(Collator.PRIMARY);
byte[] arr = mColl.getCollationKey(sixteen).toByteArray();
int len = arr.length;
assertTrue("Collation key not 0 terminated", arr[arr.length - 1] == 0);
len--;
String foo = new String(arr, 0, len, "iso8859-1");
arr = mColl.getCollationKey(sixteen).toByteArray();
len = arr.length;
assertTrue("Collation key not 0 terminated", arr[arr.length - 1] == 0);
len--;
String bar = new String(arr, 0, len, "iso8859-1");
assertTrue("Collation keys should differ", foo.equals(bar));
}
use of java.text.Collator in project robovm by robovm.
the class CollatorTest method test_decompositionCompatibility.
public void test_decompositionCompatibility() throws Exception {
Collator myCollator = Collator.getInstance();
myCollator.setDecomposition(Collator.NO_DECOMPOSITION);
assertFalse("Error: ḁ̀ should not equal to ḁ̀ without decomposition", myCollator.compare("ḁ̀", "ḁ̀") == 0);
myCollator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
assertTrue("Error: ḁ̀ should equal to ḁ̀ with decomposition", myCollator.compare("ḁ̀", "ḁ̀") == 0);
}
use of java.text.Collator in project dbeaver by serge-rider.
the class TableColumnSortListener method handleEvent.
@Override
public void handleEvent(Event e) {
final Collator collator = Collator.getInstance(Locale.getDefault());
TableColumn column = (TableColumn) e.widget;
if (prevColumn == column) {
// Set reverse order
sortDirection = (sortDirection == SWT.UP ? SWT.DOWN : SWT.UP);
}
prevColumn = column;
this.table.setSortColumn(column);
this.table.setSortDirection(sortDirection);
UIUtils.sortTable(this.table, new Comparator<TableItem>() {
@Override
public int compare(TableItem e1, TableItem e2) {
int mul = (sortDirection == SWT.UP ? 1 : -1);
String text1 = e1.getText(columnIndex);
String text2 = e2.getText(columnIndex);
try {
Double num1 = getNumberFromString(text1);
if (num1 != null) {
Double num2 = getNumberFromString(text2);
if (num2 != null) {
return (int) (num1 - num2) * mul;
}
}
} catch (NumberFormatException e3) {
// Ignore
}
return collator.compare(text1, text2) * mul;
}
});
}
use of java.text.Collator in project jdk8u_jdk by JetBrains.
the class CollatorProviderImpl method getInstance.
/**
* Returns a new <code>Collator</code> instance for the specified locale.
* @param locale the desired locale.
* @return the <code>Collator</code> for the desired locale.
* @exception NullPointerException if
* <code>locale</code> is null
* @exception IllegalArgumentException if <code>locale</code> isn't
* one of the locales returned from
* {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
* getAvailableLocales()}.
* @see java.text.Collator#getInstance(java.util.Locale)
*/
@Override
public Collator getInstance(Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
Collator result = null;
// Load the resource of the desired locale from resource
// manager.
String colString = LocaleProviderAdapter.forType(type).getLocaleResources(locale).getCollationData();
try {
result = new RuleBasedCollator(CollationRules.DEFAULTRULES + colString);
} catch (ParseException foo) {
// predefined tables should contain correct grammar
try {
result = new RuleBasedCollator(CollationRules.DEFAULTRULES);
} catch (ParseException bar) {
// the default rules should always be parsable.
throw new InternalError(bar);
}
}
// Now that RuleBasedCollator adds expansions for pre-composed characters
// into their decomposed equivalents, the default collators don't need
// to have decomposition turned on. Laura, 5/5/98, bug 4114077
result.setDecomposition(Collator.NO_DECOMPOSITION);
return (Collator) result.clone();
}
use of java.text.Collator in project Lucee by lucee.
the class ComparatorUtil method toCollator.
private static Comparator toCollator(Locale l, int strength) {
Collator c = Collator.getInstance(l);
c.setStrength(strength);
c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
return c;
}
Aggregations