Search in sources :

Example 36 with Collator

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));
}
Also used : RuleBasedCollator(java.text.RuleBasedCollator) Collator(java.text.Collator)

Example 37 with Collator

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);
}
Also used : RuleBasedCollator(java.text.RuleBasedCollator) Collator(java.text.Collator)

Example 38 with Collator

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;
        }
    });
}
Also used : Collator(java.text.Collator)

Example 39 with Collator

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();
}
Also used : RuleBasedCollator(java.text.RuleBasedCollator) ParseException(java.text.ParseException) RuleBasedCollator(java.text.RuleBasedCollator) Collator(java.text.Collator)

Example 40 with Collator

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;
}
Also used : Collator(java.text.Collator)

Aggregations

Collator (java.text.Collator)70 ArrayList (java.util.ArrayList)14 RuleBasedCollator (java.text.RuleBasedCollator)8 HashMap (java.util.HashMap)7 Comparator (java.util.Comparator)5 List (java.util.List)5 GraphObject (com.facebook.model.GraphObject)4 Context (android.content.Context)3 InputMethodInfo (android.view.inputmethod.InputMethodInfo)3 HashSet (java.util.HashSet)3 LinkedHashMap (java.util.LinkedHashMap)3 Locale (java.util.Locale)3 Entry (java.util.Map.Entry)3 SharedPreferences (android.content.SharedPreferences)2 ApplicationInfo (android.content.pm.ApplicationInfo)2 PackageInfo (android.content.pm.PackageInfo)2 DBObject (com.mongodb.DBObject)2 SMSException (com.sun.identity.sm.SMSException)2 ServiceSchema (com.sun.identity.sm.ServiceSchema)2 AutoPilot (com.ximpleware.AutoPilot)2