use of org.knime.base.util.StringValueComparator 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);
}
}
Aggregations