try {
boolean sortAscending = true;
boolean sortCaseSensitive = true;
boolean sortCustom = false;
if (children.length >= 2) {
ValueHolder options = children[1].evaluate(ctx);
if (options.dataType == DataType.ERROR)
return options;
for (int i = 0; i < options.size; i++) {
String opt = options.getString(i);
if ("[ASCENDING]".equalsIgnoreCase(opt))
sortAscending = true;
else if ("[DESCENDING]".equalsIgnoreCase(opt))
sortAscending = false;
else if ("[CASESENSITIVE]".equalsIgnoreCase(opt))
sortCaseSensitive = true;
else if ("[CASEINSENSITIVE]".equalsIgnoreCase(opt))
sortCaseSensitive = false;
else if ("[CUSTOMSORT]".equalsIgnoreCase(opt))
sortCustom = true;
else if (!"[ACCENTSENSITIVE]".equalsIgnoreCase(opt) && !"[ACCENTINSENSITIVE]".equalsIgnoreCase(opt)
&& !"[PITCHSENSITIVE]".equalsIgnoreCase(opt) && !"[PITCHINSENSITIVE]".equalsIgnoreCase(opt))
throw new IllegalArgumentException("Illegal Option: " + opt);
}
}
Node customSort = null;
if (sortCustom) {
if (children.length < 3)
throw new IllegalArgumentException("Third argument required since option [CUSTOMSORT] present");
customSort = children[2];
}
ValueHolder toSort = children[0].evaluate(ctx);
if (toSort.dataType == DataType.ERROR)
return toSort;
// we must duplicate our valueholder, since it can be Immutable
ValueHolder ret = toSort.newInstance(toSort.size);
ret.addAll(toSort);
doSort(ctx, ret, sortAscending, sortCaseSensitive, customSort);
return ret;
} catch (RuntimeException ex) {
return ValueHolder.valueOf(new EvaluateException(codeLine, codeColumn, ex));
}