The RecordComparator interface is used to compare two records to determine their sorting order. It defines a compare method that returns an integer indicating if the first record precedes, follows, or is equivalent to the second record. The compare method is called by RecordEnumeration to sort records in an application-specified order when retrieving records from a record store.
3. • It is used to comparing two records. Generally it is used to
find the sorting order.
• The return value must indicate the ordering of the two
records.
• The compare method is called by RecordEnumeration to
sort and return records in an application specified order.
For example:
• RecordComparator c = new AddressRecordComparator(); if
(c.compare(recordStore.getRecord(rec1),
recordStore.getRecord(rec2)) ==
RecordComparator.PRECEDES) return rec1;
Interface RecordComparator
10. •
•
try
{
•
•
•
•
•
String[] s = new String[3];
int z = 0;
byte[] by = new byte[300];
ByteArrayInputStream bais =
new ByteArrayInputStream(by);
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
DataInputStream dis =
new DataInputStream(bais);
StringBuffer sb = new StringBuffer();
com = new Comparator2();
r= rec.enumerateRecords(null, com, false);//now RecordEnumeration is build
while (r.hasNextElement())//if there is another record is there in RecordEnumeration, returns true,
//false otherwise
{
rec.getRecord( r.nextRecordId(),by, 0);//it returns the record ID of next record
//present in the RecordEnumeration and copies into by array
sb.append(dis.readUTF());
sb.append(dis.readInt());
sb.append("n");
dis.reset();
}
Interface RecordComparator