public final class DMOSorter extends java.lang.Object implements java.util.Comparator<Persistable>
sort criteria
. Each sort criterion specifies an
individual property of the DMO and the sort direction to be applied to that
property. As two DMO instances are compared
, the sort criteria are applied
in order, until a difference in sort order is detected, or the list of
criteria is exhausted, at which point the DMOs are determined to sort
equivalently.Modifier and Type | Class and Description |
---|---|
private static class |
DMOSorter.FieldWorker
Helper comparator implementation which compares a particular property of
a DMO, adjusted for sort direction.
|
Modifier and Type | Field and Description |
---|---|
private java.util.ArrayList<DMOSorter.FieldWorker> |
workers
Workers for each sorted DMO property
|
Constructor and Description |
---|
DMOSorter(Database database,
java.lang.Class<?> dmoIface,
java.util.List<SortCriterion> sortList)
Constructor which specifies DMO type and sort criteria.
|
Modifier and Type | Method and Description |
---|---|
int |
compare(Persistable p1,
Persistable p2)
Compare two
Persistable instances to determine relative
sort order, according to the sort criteria specified for this sorter. |
private final java.util.ArrayList<DMOSorter.FieldWorker> workers
public DMOSorter(Database database, java.lang.Class<?> dmoIface, java.util.List<SortCriterion> sortList)
database
- The associated database.dmoIface
- DMO interface which defines access methods for DMO properties.sortList
- List of sort criteria which define target properties and sort
direction for each property.public int compare(Persistable p1, Persistable p2)
Persistable
instances to determine relative
sort order, according to the sort criteria specified for this sorter.
The sort criteria are applied in order, until a difference in sort order
is detected, or the list of criteria is exhausted, at which point the
DMOs are determined to sort equivalently.
The comparison of each property uses the natural order of the data, except that unknown value always sorts high in an ascending sort. The result is inverted for descending sorts (meaning unknown value sorts low in a descending sort.
compare
in interface java.util.Comparator<Persistable>
p1
- First DMO to compare. Must not be null
.p2
- Second DMO to compare. Must not be null
.p1
> p2
;
negative value if p1
< p2
;
0
if p1
and p2
sort
equivalently.