Class GridSorter
java.lang.Object
com.codename1.ui.table.GridSorter
The sort a DataGrid orders its rows with, for any other list of rows.
It orders positions rather than data: each sort key is read once per row into an array before sorting, so a comparison never goes back to the model, and the sort is stable, so rows that compare equal keep the order they came in. A million rows cost a million reads per key.
String[] names = {"dana", "Ann", "carl"};
int n = names.length;
Object[][] keys = new Object[1][n];
for (int i = 0; i < n; i++) {
keys[0][i] = names[i];
}
int[] order = GridSorter.order(n, keys, null, new boolean[]{true});
// order[k] is the position that sorts k-th
-
Method Summary
Modifier and TypeMethodDescriptionstatic intcompare(Comparator comparator, Object a, Object b) Compares two values the wayorderdoes for an ascending key.static int[]order(int count, Object[][] keys, Comparator[] comparators, boolean[] ascending) Orders the positions0..count-1by their keys.
-
Method Details
-
order
public static int[] order(int count, Object[][] keys, Comparator[] comparators, boolean[] ascending) Orders the positions
0..count-1by their keys.Parameters
count: how many positions there arekeys:keys[k][i], the value of sort keykat positioni; the first key decides, the next one breaks its ties, and so oncomparators: a comparator per key, or null; a null array or a null entry compares values naturally: numbers by value, dates by time, booleans false first, anything else by its text ignoring caseascending: the direction of each key
A null value sorts before any other, and after them all when its key descends. A comparator is never given a null.
Returns
the positions in sorted order
-
compare
Compares two values the wayorderdoes for an ascending key.
-