Programming with the RMS (Cont.)


Comparing My Record with Records in the Record Store
To search for the right record to delete, your application must implement the RecordComparator interface (by providing an implementation to the compare method) to compare two records. The compare method is called by RecordEnumeration to sort and return records in an application specified order. The return value indicates the ordering of the two records. The following code compares two strings that are retrieved from two records.
public  someClass  implements  RecordComparator {
  public int  compare( byte[ ] record1, byte[] record2 ) {
    ByteArrayInputStream  bais1 =
        new ByteArrayInputStream( record1 );
    DataInputStream       dis1  = new  DataInputStream( bais1 );
    ByteArrayInputStream  bais2 =
        new ByteArrayInputStream( record2 );
    DataInputStream       dis2  = new DataInputStream( bais2 );

    String  name1 = dis1.readUTF( );
    String  name2 = dis.readUTF( );
    int  num = name1.compareTo( name2 );
    if ( num > 0 ) {
      return  RecordComparator.FOLLOWS;
    } else if ( num < 0 ) {
      return  recordcomparator.PRECEDES;
    } else {
      return  recordcomparator.EQUIVALENT;
    }
  }
}
The three constants are defined in the RecordComparator interface:
Closing the Record Store
To close the record store, use the closeRecordStore( ) method.