import Server.ProcessHitsCollectionPackage.Hit;

public class Database
{
    //
    // This structure represents the data in a database object
    //
    public static class DBRecordData
    {
        Hit[] data;
        int key;
    }

    private java.util.Vector records_; // Set of records in the database

    public
    Database()
    {
        records_ = new java.util.Vector();
    }

    //
    // Destroy the record specified by `key'
    //
    public boolean
    destroy(int key)
    {
        for(int i = 0 ; i < records_.size() ; i++)
        {
            //
            // Found the record?
            //
            DBRecordData data = (DBRecordData)records_.elementAt(i);
            if(data.key == key)
            {
                //
                // Remove the record from the database
                //
                records_.removeElementAt(i);

                //
                // Return true to indicate that we've found the record
                //
                return true;
            }
        }

        //
        // No record, return false
        //
        return false;
    }

    //
    // Add a record specified by `key'
    //
    public DBRecordData
    add(int key)
    {
        //
        // Add to the database
        //
        DBRecordData data = new DBRecordData();
        records_.addElement(data);

        //
        // Fill in the record data
        //
        data.key = key;
        data.data = null;

        return data;
    }

    //
    // Find the record specified by `key'
    //
    public DBRecordData
    find(int key)
    {
        for(int i = 0 ; i < records_.size() ; i++)
        {
            DBRecordData data = (DBRecordData)records_.elementAt(i);
            if(data.key == key)
                return data;
        }

        return null;
    }

    //
    // Return the record at position i
    //
    public DBRecordData
    recordAt(int i)
    {
        return (DBRecordData)records_.elementAt(i);
    }

    //
    // Return the number of records in database
    //
    public int
    size()
    {
        return records_.size();
    }
}