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 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;
}
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;
}
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;
}
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) {
}
}
Aggregations