use of java.text.Collator in project knime-core by knime.
the class AccuracyScorerNodeModel method sort.
/**
* @param order The cells to sort.
*/
private void sort(final DataCell[] order) {
if (order.length == 0) {
return;
}
DataType type = order[0].getType();
for (DataCell dataCell : order) {
type = DataType.getCommonSuperType(type, dataCell.getType());
}
final Comparator<DataCell> comparator;
switch(m_sortingStrategy) {
case InsertionOrder:
if (m_sortingReversed) {
reverse(order);
}
return;
case Unsorted:
return;
case Lexical:
if (StringCell.TYPE.isASuperTypeOf(type)) {
Comparator<String> stringComparator;
Collator instance = Collator.getInstance();
// do not try to combine characters
instance.setDecomposition(Collator.NO_DECOMPOSITION);
// case and accents matter.
instance.setStrength(Collator.IDENTICAL);
@SuppressWarnings("unchecked") Comparator<String> collator = (Comparator<String>) (Comparator<?>) instance;
stringComparator = collator;
comparator = new StringValueComparator(stringComparator);
} else if (DoubleCell.TYPE.isASuperTypeOf(type)) {
comparator = new DataValueComparator() {
@Override
protected int compareDataValues(final DataValue v1, final DataValue v2) {
String s1 = v1.toString();
String s2 = v2.toString();
return s1.compareTo(s2);
}
};
} else {
throw new IllegalStateException("Lexical sorting strategy is not supported.");
}
break;
case Numeric:
if (DoubleCell.TYPE.isASuperTypeOf(type)) {
comparator = type.getComparator();
} else {
throw new IllegalStateException("Numerical sorting strategy is not supported.");
}
break;
default:
throw new IllegalStateException("Unrecognized sorting strategy: " + m_sortingStrategy);
}
Arrays.sort(order, comparator);
if (m_sortingReversed) {
reverse(order);
}
}
use of java.text.Collator in project eclipse.platform.swt by eclipse.
the class MJ_Table method sort_by_column_Snippet2.
@Test
public void sort_by_column_Snippet2() {
Shell shell = mkShell("Click on columns to verify items are sorted properly");
shell.setLayout(new FillLayout());
final Table table = new Table(shell, SWT.BORDER);
table.setHeaderVisible(true);
final TableColumn column1 = new TableColumn(table, SWT.NONE);
column1.setText("Column 1");
final TableColumn column2 = new TableColumn(table, SWT.NONE);
column2.setText("Column 2");
TableItem item = new TableItem(table, SWT.NONE);
item.setText(new String[] { "a", "3" });
item = new TableItem(table, SWT.NONE);
item.setText(new String[] { "b", "2" });
item = new TableItem(table, SWT.NONE);
item.setText(new String[] { "c", "1" });
column1.setWidth(100);
column2.setWidth(100);
Listener sortListener = e -> {
TableItem[] items = table.getItems();
Collator collator = Collator.getInstance(Locale.getDefault());
TableColumn column = (TableColumn) e.widget;
int index = column == column1 ? 0 : 1;
for (int i = 1; i < items.length; i++) {
String value1 = items[i].getText(index);
for (int j = 0; j < i; j++) {
String value2 = items[j].getText(index);
if (collator.compare(value1, value2) < 0) {
String[] values = { items[i].getText(0), items[i].getText(1) };
items[i].dispose();
TableItem item1 = new TableItem(table, SWT.NONE, j);
item1.setText(values);
items = table.getItems();
break;
}
}
}
table.setSortColumn(column);
};
column1.addListener(SWT.Selection, sortListener);
column2.addListener(SWT.Selection, sortListener);
table.setSortColumn(column1);
table.setSortDirection(SWT.UP);
shell.setSize(SWIDTH, SHEIGHT);
shell.open();
mainLoop(shell);
}
use of java.text.Collator in project OpenAM by OpenRock.
the class AMFormatUtils method sortItems.
/**
* Sorts items in a set.
*
* @param collection to sort.
* @param locale of user.
* @return list of sorted items.
*/
public static List sortItems(Collection collection, Locale locale) {
List sorted = Collections.EMPTY_LIST;
if ((collection != null) && !collection.isEmpty()) {
sorted = new ArrayList(collection);
Collator collator = Collator.getInstance(locale);
Collections.sort(sorted, collator);
}
return sorted;
}
use of java.text.Collator in project OpenAM by OpenRock.
the class SubConfigMeta method getSubConfigurationsFromConfig.
private void getSubConfigurationsFromConfig() {
try {
String[] params = { serviceName, parentConfig.getComponentName() };
amModel.logEvent("ATTEMPT_READ_GLOBAL_SUB_CONFIGURATION_NAMES", params);
Set names = parentConfig.getSubConfigNames();
if ((names != null) && !names.isEmpty()) {
Collator collator = Collator.getInstance(amModel.getUserLocale());
SortedSet set = new TreeSet(new SMSubConfigComparator(collator));
for (Iterator iter = names.iterator(); iter.hasNext(); ) {
String name = (String) iter.next();
ServiceConfig conf = parentConfig.getSubConfig(name);
String schemaID = conf.getSchemaID();
if (globalSubSchemaNames.contains(schemaID)) {
String displayType = (String) mapServiceSchemaNameToL10NName.get(schemaID);
String localizedName = getLocalizedString(CollectionHelper.getMapAttr(conf.getAttributes(), SMSUtils.I18N_KEY));
ServiceSchema schema = corrSchema.getSubSchema(schemaID);
set.add(new SMSubConfig(conf.getComponentName(), name, displayType, localizedName, schema.isHiddenInConfigUI()));
if (singleInstanceGlobalSubSchemas.contains(schemaID)) {
creatableGlobalSubSchemas.remove(schemaID);
}
}
}
if (!set.isEmpty()) {
globalSubConfigurations = new ArrayList(set.size());
globalSubConfigurations.addAll(set);
}
}
amModel.logEvent("SUCCEED_READ_GLOBAL_SUB_CONFIGURATION_NAMES", params);
} catch (SSOException e) {
String[] paramsEx = { serviceName, parentConfig.getComponentName(), amModel.getErrorString(e) };
amModel.logEvent("SSO_EXCEPTION_READ_GLOBAL_SUB_CONFIGURATION_NAMES", paramsEx);
AMModelBase.debug.error("SubConfigMeta.getSubConfigurations", e);
} catch (SMSException e) {
String[] paramsEx = { serviceName, parentConfig.getComponentName(), amModel.getErrorString(e) };
amModel.logEvent("SMS_EXCEPTION_READ_GLOBAL_SUB_CONFIGURATION_NAMES", paramsEx);
AMModelBase.debug.error("SubConfigMeta.getSubConfigurations", e);
}
}
use of java.text.Collator in project Klyph by jonathangerbaud.
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;
}
Aggregations