Ordered Traversal: Comparators and Record Enumerations

So far, you've accessed records by their primary index only. But what if you want to sort the journeys in the previous example's travel list by the length of the trip or the date, without requiring that they all be entered in the correct order? For this purpose, RMS provides record enumerations.

Record enumerations let you visit all the records in a record store in a custom order. The first step is to define the custom order. You do so by implementing the compare() method of the RecordComparator interface, which defines an order for the records. The compare() method takes two byte arrays as parameters. It returns one of the constants EQUIVALENT, FOLLOWS, or PRECEDES, depending on the relative ...

Get Java™ 2 Micro Edition Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.