Class NaturalSort
Lagged names. A string of the form "name:lag" — exactly one colon,
with the portion after the colon parseable as an integer — is treated as a
lagged node name. Lagged names are grouped in order of decreasing lag
(deepest lag first), and within a lag group are ordered by the natural order
of the name before the colon. All strings that are not valid lagged names
(no colon, more than one colon, or a non-integer suffix) come last,
ordered naturally among themselves. This matches the layout convention for
time-lagged data, where the deepest lag slice is displayed first and the
contemporaneous (unlagged) variables are displayed last.
The comparators here are total on arbitrary strings and never throw: malformed inputs are simply treated as unlagged names.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classRepresents a natural key for a possibly-lagged node name of the form"name"or"name:lag".static final classRepresents a natural key, which consists of a string prefix and an optional numeric suffix. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Comparator<String> A comparator that sorts strings in natural order (e.g. -
Method Summary
Modifier and TypeMethodDescriptionstatic Comparator<String> Returns a comparator over possibly-lagged names that puts unlagged names first, then lagged names in order of increasing lag; within a lag group, and among the unlagged names, ordering is by the natural order of the base name, with the raw string as a final tiebreaker so that distinct names never compare equal.static <T> Comparator<T> Returns a comparator that sorts objects of any type in natural order, using each object'sObject.toString()representation as the sort key.
-
Field Details
-
NATURAL_NAME_COMPARATOR
A comparator that sorts strings in natural order (e.g. "X1", "X2", "X10" rather than "X1", "X10", "X2"). Valid lagged names ("name:lag") are grouped first, in order of decreasing lag, each group ordered by the natural order of the base name; all other strings come last, in natural order. Never throws on malformed input.
-
-
Method Details
-
naturalComparator
Returns a comparator that sorts objects of any type in natural order, using each object'sObject.toString()representation as the sort key. Valid lagged names ("name:lag") group first in order of decreasing lag, then natural order of the base name; everything else comes last in natural order. Never throws on malformed input.- Type Parameters:
T- the type of objects to compare- Returns:
- a natural-order comparator for T
-
lagAscendingComparator
Returns a comparator over possibly-lagged names that puts unlagged names first, then lagged names in order of increasing lag; within a lag group, and among the unlagged names, ordering is by the natural order of the base name, with the raw string as a final tiebreaker so that distinct names never compare equal. This is the display order used by GUI variable lists, where current-time variables belong at the top -- the reverse macro-order ofnaturalComparator(), which puts the deepest lags first for time-ordered listings. A name is treated as lagged under the same definition asNaturalSort.LaggedNaturalKey: exactly one colon with an integer suffix. Anything else, including names with non-integer colon suffixes such as"price:usd", sorts among the unlagged names, so comparison never throws. This replaces ad hoc GUI comparators that compared lag suffixes as strings, which put"X:10"before"X:2".- Returns:
- a comparator imposing the display order described above
-