Comparators

Comparators control the order of Records in a Set returned by a call to select(). They are directly analogous to SQL's ORDER BY clause. Comparators simply implement java.util.Comparator and should expect to have their compare() method called with two Record objects.

For convenience, a SeriesComparator helper class is provided that allows for the serial combination of multiple Comparators. SeriesComparator applies its Comparators in the order in which they were added to the SeriesComparator. Comparison of any two Records stops when any Comparator in the chain returns a nonzero value. For example, to order search results by last name, then by first name, create a SeriesComparator, then add a Comparator for the lastname field, then a Comparator for the firstname field.

Tip

Some basic Comparators are included with Trivial Persist. See the javadocs for more information.