Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class GridSorter
- Object
- 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-thMethods
public static int[] order(int count, Object[][] keys, Comparator[] comparators, boolean[] ascending) | Orders the positions 0..count-1 by their keys. |
public static int compare(Comparator comparator, Object a, Object b) | Compares two values the way order does for an ascending key. |
Inherited methods
Method details
order
public static int[] order(int count, Object[][] keys, Comparator[] comparators, boolean[] ascending)Orders the positions
0..count-1 by their keys.Parameters
countint- how many positions there are
keysObject[][]keys[k][i], the value of sort keykat positioni; the first key decides, the next one breaks its ties, and so oncomparatorsComparator[]- 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 case
ascendingboolean[]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
public static int compare(Comparator comparator, Object a, Object b)Compares two values the way
order does for an ascending key.