Search in sources :

Example 6 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 7 with Collator

use of java.text.Collator in project es6draft by anba.

the class Realm method getCollator.

/**
     * Returns a {@link Collator} for this realm's locale
     * 
     * @deprecated No longer used
     * @return the locale specific collator
     */
@Deprecated
public Collator getCollator() {
    Collator collator = Collator.getInstance(getLocale());
    // Use Normalized Form D for comparison (cf. 21.1.3.10, Note 2)
    collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
    // `"".localeCompare("") == -1` should yield true
    collator.setStrength(Collator.IDENTICAL);
    return collator;
}
Also used : Collator(java.text.Collator)

Example 8 with Collator

use of java.text.Collator in project facebook-api-android-maven by avianey.

the class GraphObjectAdapter method rebuildSections.

private void rebuildSections() {
    sectionKeys = new ArrayList<String>();
    graphObjectsBySection = new HashMap<String, ArrayList<T>>();
    graphObjectsById = new HashMap<String, T>();
    displaySections = false;
    if (cursor == null || cursor.getCount() == 0) {
        return;
    }
    int objectsAdded = 0;
    cursor.moveToFirst();
    do {
        T graphObject = cursor.getGraphObject();
        if (!filterIncludesItem(graphObject)) {
            continue;
        }
        objectsAdded++;
        String sectionKeyOfItem = getSectionKeyOfGraphObject(graphObject);
        if (!graphObjectsBySection.containsKey(sectionKeyOfItem)) {
            sectionKeys.add(sectionKeyOfItem);
            graphObjectsBySection.put(sectionKeyOfItem, new ArrayList<T>());
        }
        List<T> section = graphObjectsBySection.get(sectionKeyOfItem);
        section.add(graphObject);
        graphObjectsById.put(getIdOfGraphObject(graphObject), graphObject);
    } while (cursor.moveToNext());
    if (sortFields != null) {
        final Collator collator = Collator.getInstance();
        for (List<T> section : graphObjectsBySection.values()) {
            Collections.sort(section, new Comparator<GraphObject>() {

                @Override
                public int compare(GraphObject a, GraphObject b) {
                    return compareGraphObjects(a, b, sortFields, collator);
                }
            });
        }
    }
    Collections.sort(sectionKeys, Collator.getInstance());
    displaySections = sectionKeys.size() > 1 && objectsAdded > DISPLAY_SECTIONS_THRESHOLD;
}
Also used : GraphObject(com.facebook.model.GraphObject) Collator(java.text.Collator)

Example 9 with Collator

use of java.text.Collator in project facebook-android-sdk by facebook.

the class GraphObjectAdapter method rebuildSections.

private void rebuildSections() {
    sectionKeys = new ArrayList<String>();
    graphObjectsBySection = new HashMap<String, ArrayList<JSONObject>>();
    graphObjectsById = new HashMap<String, JSONObject>();
    displaySections = false;
    if (cursor == null || cursor.getCount() == 0) {
        return;
    }
    int objectsAdded = 0;
    cursor.moveToFirst();
    do {
        JSONObject graphObject = cursor.getGraphObject();
        if (!filterIncludesItem(graphObject)) {
            continue;
        }
        objectsAdded++;
        String sectionKeyOfItem = getSectionKeyOfGraphObject(graphObject);
        if (!graphObjectsBySection.containsKey(sectionKeyOfItem)) {
            sectionKeys.add(sectionKeyOfItem);
            graphObjectsBySection.put(sectionKeyOfItem, new ArrayList<JSONObject>());
        }
        List<JSONObject> section = graphObjectsBySection.get(sectionKeyOfItem);
        section.add(graphObject);
        graphObjectsById.put(getIdOfGraphObject(graphObject), graphObject);
    } while (cursor.moveToNext());
    if (sortFields != null) {
        final Collator collator = Collator.getInstance();
        for (List<JSONObject> section : graphObjectsBySection.values()) {
            Collections.sort(section, new Comparator<JSONObject>() {

                @Override
                public int compare(JSONObject a, JSONObject b) {
                    return compareGraphObjects(a, b, sortFields, collator);
                }
            });
        }
    }
    Collections.sort(sectionKeys, Collator.getInstance());
    displaySections = sectionKeys.size() > 1 && objectsAdded > DISPLAY_SECTIONS_THRESHOLD;
}
Also used : JSONObject(org.json.JSONObject) Collator(java.text.Collator)

Example 10 with Collator

use of java.text.Collator in project j2objc by google.

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 : Collator(java.text.Collator)

Aggregations

Collator (java.text.Collator)66 ArrayList (java.util.ArrayList)14 RuleBasedCollator (java.text.RuleBasedCollator)7 HashMap (java.util.HashMap)7 List (java.util.List)5 GraphObject (com.facebook.model.GraphObject)4 Comparator (java.util.Comparator)4 Context (android.content.Context)3 InputMethodInfo (android.view.inputmethod.InputMethodInfo)3 HashSet (java.util.HashSet)3 LinkedHashMap (java.util.LinkedHashMap)3 Entry (java.util.Map.Entry)3 TreeMap (java.util.TreeMap)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