Chapter 4. Querying Tables

Table of Contents

Named RecordFilters and Comparators

Querying Tables is very simple. The Table class provides three selector methods that return Set objects over which you can iterate. The selector methods are:


returns a Set of all Records in the Table.

select(RecordFilter recordFilter, Comparator comparator)

returns a Set of all Records in the Table that match the specified RecordFilter (see below), sorted by the specified Comparator (see below)

select(String recordFilterName, String comparatorName)

returns a Set of all Records in the Table that match the named RecordFilter (see below), sorted by the named Comparator (see below).


RecordFilters allow fine control over which Records are returned by a call to select(). They are directly analogous to SQL's WHERE clause, and work in the same manner as A RecordFilter is simply an interface that defines a boolean accept(Record record) method that is called for each Record. If the RecordFilter returns true, the specified Record will be included in the resulting Set.

For convenience a SeriesRecordFilter helper class is provided that allows for the serial combination of multiple RecordFilters. SeriesRecordFilter applies its RecordFilters in the order in which they were added to the SeriesRecordFilter. Processing of an individual Record stops when any RecordFilter in the chain returns false.


For best performance, add the RecordFilters that perform the most pruning to the SeriesRecordFilter first. Add the RecordFilters that are most computationally intensive last.


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