Search in sources :

Example 61 with Collator

use of java.text.Collator in project robovm by robovm.

the class CollatorTest method test_setStrengthI.

public void test_setStrengthI() throws Exception {
    Collator collator = Collator.getInstance();
    collator.setStrength(Collator.PRIMARY);
    assertEquals(Collator.PRIMARY, collator.getStrength());
    collator.setStrength(Collator.SECONDARY);
    assertEquals(Collator.SECONDARY, collator.getStrength());
    collator.setStrength(Collator.TERTIARY);
    assertEquals(Collator.TERTIARY, collator.getStrength());
    collator.setStrength(Collator.IDENTICAL);
    assertEquals(Collator.IDENTICAL, collator.getStrength());
    try {
        collator.setStrength(-1);
        fail("IllegalArgumentException was not thrown.");
    } catch (IllegalArgumentException expected) {
    }
}
Also used : RuleBasedCollator(java.text.RuleBasedCollator) Collator(java.text.Collator)

Example 62 with Collator

use of java.text.Collator in project robovm by robovm.

the class CollatorTest method test_stackCorruption.

public void test_stackCorruption() throws Exception {
    // This used to crash Android.
    Collator mColl = Collator.getInstance();
    mColl.setStrength(Collator.PRIMARY);
    mColl.getCollationKey("2d294f2d3739433565147655394f3762f3147312d3731641452f310");
}
Also used : RuleBasedCollator(java.text.RuleBasedCollator) Collator(java.text.Collator)

Example 63 with Collator

use of java.text.Collator in project robovm by robovm.

the class OldTreeMapTest method test_headMapLjava_lang_Object.

public void test_headMapLjava_lang_Object() {
    // Test for method java.util.SortedMap
    // java.util.TreeMap.headMap(java.lang.Object)
    Map head = tm.headMap("100");
    assertEquals("Returned map of incorrect size", 3, head.size());
    assertTrue("Returned incorrect elements", head.containsKey("0") && head.containsValue(new Integer("1")) && head.containsKey("10"));
    SortedMap sort = tm.headMap("100");
    try {
        sort.headMap("50");
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    //expected
    }
    try {
        tm.headMap(this);
        fail("ClassCastException expected");
    } catch (ClassCastException e) {
    //expected
    }
    try {
        tm.headMap(null);
        fail("NullPointerException expected");
    } catch (NullPointerException e) {
    //expected
    }
    // Regression for Harmony-1026
    TreeMap<Integer, Double> map = new TreeMap<Integer, Double>(new MockComparator());
    map.put(1, 2.1);
    map.put(2, 3.1);
    map.put(3, 4.5);
    map.put(7, 21.3);
    map.put(null, null);
    SortedMap<Integer, Double> smap = map.headMap(null);
    assertEquals(0, smap.size());
    Set<Integer> keySet = smap.keySet();
    assertEquals(0, keySet.size());
    Set<Map.Entry<Integer, Double>> entrySet = smap.entrySet();
    assertEquals(0, entrySet.size());
    Collection<Double> valueCollection = smap.values();
    assertEquals(0, valueCollection.size());
    // Regression for Harmony-1066
    assertTrue(head instanceof Serializable);
    // Regression for ill-behaved collator
    Collator c = new Collator() {

        @Override
        public int compare(String o1, String o2) {
            if (o1 == null) {
                return 0;
            }
            return o1.compareTo(o2);
        }

        @Override
        public CollationKey getCollationKey(String string) {
            return null;
        }

        @Override
        public int hashCode() {
            return 0;
        }
    };
    TreeMap<String, String> treemap = new TreeMap<String, String>(c);
    assertEquals(0, treemap.headMap(null).size());
}
Also used : Serializable(java.io.Serializable) TreeMap(java.util.TreeMap) Collator(java.text.Collator) SortedMap(java.util.SortedMap) TreeMap(java.util.TreeMap) Map(java.util.Map) HashMap(java.util.HashMap) SortedMap(java.util.SortedMap)

Example 64 with Collator

use of java.text.Collator in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AppWidgetLoader method getItems.

/**
     * Build and return list of items to be shown in dialog. This will mix both
     * installed {@link AppWidgetProviderInfo} and those provided through
     * {@link AppWidgetManager#EXTRA_CUSTOM_INFO}, sorting them alphabetically.
     */
protected List<Item> getItems(Intent intent) {
    boolean sortCustomAppWidgets = intent.getBooleanExtra(AppWidgetManager.EXTRA_CUSTOM_SORT, true);
    List<Item> items = new ArrayList<Item>();
    // Default category is home screen
    int categoryFilter = intent.getIntExtra(AppWidgetManager.EXTRA_CATEGORY_FILTER, AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN);
    putInstalledAppWidgets(items, categoryFilter);
    // Sort all items together by label
    if (sortCustomAppWidgets) {
        putCustomAppWidgets(items, intent);
    }
    Collections.sort(items, new Comparator<Item>() {

        Collator mCollator = Collator.getInstance();

        public int compare(Item lhs, Item rhs) {
            return mCollator.compare(lhs.getLabel(), rhs.getLabel());
        }
    });
    if (!sortCustomAppWidgets) {
        List<Item> customItems = new ArrayList<Item>();
        putCustomAppWidgets(customItems, intent);
        items.addAll(customItems);
    }
    return items;
}
Also used : ArrayList(java.util.ArrayList) Collator(java.text.Collator)

Example 65 with Collator

use of java.text.Collator in project symmetric-ds by JumpMind.

the class Table method sortForeignKeys.

/**
     * Sorts the foreign keys alphabetically.
     * 
     * @param caseSensitive
     *            Whether case matters
     */
public void sortForeignKeys(final boolean caseSensitive) {
    if (!foreignKeys.isEmpty()) {
        final Collator collator = Collator.getInstance();
        Collections.sort(foreignKeys, new Comparator<ForeignKey>() {

            public int compare(ForeignKey obj1, ForeignKey obj2) {
                String fk1Name = ((ForeignKey) obj1).getName();
                String fk2Name = ((ForeignKey) obj2).getName();
                if (!caseSensitive) {
                    fk1Name = (fk1Name != null ? fk1Name.toLowerCase() : null);
                    fk2Name = (fk2Name != null ? fk2Name.toLowerCase() : null);
                }
                return collator.compare(fk1Name, fk2Name);
            }
        });
    }
}
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