RegisterSign In

API Documentation: Abstract Class FixedSizeSerialSet

Package: com.mckoi.data

A set of fixed sized binary record elements arranged in a sequence over a DataFile. This abstract class provides various facilities for implementing a DataFile structure to manage a collection of fixed size records.

The structure of the file is a simple arrangement of the record elements in ordered sequence. Records may be inserted or removed from any position.

Note that this class does not provide specific functions for reading or writing the content of record data, leaving the record format up to the implementation. It does provide convenience methods for collating and searching the records, however.

Also note this class implements a cache on calls to 'searchForRecord' to improve key lookup. If any operations change the result of 'searchForRecord' for any value of 'key' then the cache should be invalidated with a call to 'clearKeyCache'.

Constructors Summary

FixedSizeSerialSet(DataFile data, int record_size)

Methods Summary

DataFile getDataFile()
void positionOn(long record_num)
void insertEmpty(long record_num)
void removeRecordAt(long record_num)
void clearKeyCache()
int getRecordSize()
long size()
long searchForRecord(Object key)
boolean remove(Object key)
boolean contains(Object key)
abstract Object getRecordKey(long record_pos)
abstract int compareRecordTo(long record_pos, Object record_key)

Constructor Details

FixedSizeSerialSet(DataFile data, int record_size)

Constructor.

Method Details

DataFile getDataFile()

Returns the DataFile object for access to the record data.

void positionOn(long record_num)

Moves the position of the DataFile object to the start of the given record location.

void insertEmpty(long record_num)

Inserts an empty record at the given record location ready for new data to be inserted into it.

void removeRecordAt(long record_num)

Removes the record at the given position.

void clearKeyCache()

Clears the key cache.

int getRecordSize()

Returns the size of the records in the file in bytes.

long size()

Returns the number of records in this set.

long searchForRecord(Object key)

performs a binary search for the given object key in the set. If the record is found then the record position is returned. If the record is not found then a negative value is returned which can be converted into the location at which the record should be inserted into the set to maintain correct ordering, with the calculation -(returned_val + 1).

Calls to this method are backed by an internal cache that maps the key object to the position.

boolean remove(Object key)

Remove the record with the given key from the set. Returns true if the record was found and removed, false otherwise.

boolean contains(Object key)

Returns true if the set contains a record with the given key value.

Object getRecordKey(long record_pos)

Given a position of a record within the set, returns an Object used as collation reference of records within the set.

int compareRecordTo(long record_pos, Object record_key)

Compares the record at the given position in the set with the record key given, and returns a positive number of a > b, 0 if a = b, or a negative number if a < b.

The text on this page is licensed under the Creative Commons Attribution 3.0 License. Java is a registered trademark of Oracle and/or its affiliates.
Mckoi is Copyright © 2000 - 2020 Diehl and Associates, Inc. All rights reserved.