use of lucee.runtime.type.comparator.NumberSortRegisterComparator in project Lucee by lucee.
the class QueryImpl method sort.
private void sort(QueryColumn column, int order) throws PageException {
int type = column.getType();
SortRegister[] arr = ArrayUtil.toSortRegisterArray(column);
Arrays.sort(arr, (type == Types.BIGINT || type == Types.BIT || type == Types.INTEGER || type == Types.SMALLINT || type == Types.TINYINT || type == Types.DECIMAL || type == Types.DOUBLE || type == Types.NUMERIC || type == Types.REAL) ? (Comparator) new NumberSortRegisterComparator(order == ORDER_ASC) : (Comparator) new SortRegisterComparator(null, order == ORDER_ASC, true, true));
for (int i = 0; i < columns.length; i++) {
column = columns[i];
int len = column.size();
QueryColumnImpl newCol = new QueryColumnImpl(this, columnNames[i], columns[i].getType(), len);
for (int y = 1; y <= len; y++) {
newCol.set(y, column.get(arr[y - 1].getOldPosition() + 1, null));
}
columns[i] = newCol;
}
}
use of lucee.runtime.type.comparator.NumberSortRegisterComparator in project Lucee by lucee.
the class StructSort method call.
public static Array call(PageContext pc, Struct base, String sortType, String sortOrder, String pathToSubElement) throws PageException {
boolean isAsc = true;
PageException ee = null;
if (sortOrder.equalsIgnoreCase("asc"))
isAsc = true;
else if (sortOrder.equalsIgnoreCase("desc"))
isAsc = false;
else
throw new ExpressionException("invalid sort order type [" + sortOrder + "], sort order types are [asc and desc]");
Collection.Key[] keys = CollectionUtil.keys(base);
SortRegister[] arr = new SortRegister[keys.length];
boolean hasSubDef = pathToSubElement != null;
for (int i = 0; i < keys.length; i++) {
Object value = base.get(keys[i], null);
if (hasSubDef) {
value = VariableInterpreter.getVariable(pc, Caster.toCollection(value), pathToSubElement);
}
arr[i] = new SortRegister(i, value);
}
ExceptionComparator comp = null;
// text
if (sortType.equalsIgnoreCase("text"))
comp = new SortRegisterComparator(pc, isAsc, false, true);
else // text no case
if (sortType.equalsIgnoreCase("textnocase"))
comp = new SortRegisterComparator(pc, isAsc, true, true);
else // numeric
if (sortType.equalsIgnoreCase("numeric"))
comp = new NumberSortRegisterComparator(isAsc);
else {
throw new ExpressionException("invalid sort type [" + sortType + "], sort types are [text, textNoCase, numeric]");
}
Arrays.sort(arr, 0, arr.length, comp);
ee = comp.getPageException();
if (ee != null) {
throw ee;
}
Array rtn = new ArrayImpl();
for (int i = 0; i < arr.length; i++) {
rtn.append(keys[arr[i].getOldPosition()].getString());
}
return rtn;
}
Aggregations