## xbase
Class XbaseIndex

    java.lang.Object
      |
      +--xbase.XbaseIndex

Direct Known Subclasses:
  NTXIndex

public abstract class XbaseIndex
extends java.lang.Object

Interface for traversing an index. Implementations have their own current pointer into the index file. There can be multiple instances per XbaseFile. This class should only be created in XbaseFile.getIndex().

See Also:
  `NTXIndex`, `XbaseFile.getIndex(int)`

Field Summary
`protected int` `debug`
`static int` `EQ` In read(), find an index key exactly equal.
`static int` `GE` In read(), find an index key greater than or equal.
`static int` `LE` In read(), find an index key less than or equal.

Constructor Summary
`XbaseIndex(XbaseFile xfile, XbaseKey keyDescription, int keyNo)` Constructor.

Method Summary
`protected abstract int` `bottom()` Position to the bottom/last record.
`boolean` `first(XbaseRecord rec)` Go to the first record of the index.
`XbaseFile` `getFile()` Get the file associated with this index.
`int` `getIndexKeyNo()` Get the key number associated with this index.
`abstract int` `getRecordNumber()` Get the current record number.
`boolean` `last(XbaseRecord rec)` Go to the last record of the index.
`protected abstract int` `next()` Position to the next record.
`boolean` `next(XbaseRecord rec)` Go to the next record of the index.
`protected abstract int` `previous()` Position to the previous record.
`boolean` `previous(XbaseRecord rec)` Go to the previous record of the index.
`boolean` `read(XbaseRecord rec)` Read the record for the exact key.
`boolean` `read(XbaseRecord rec, int mode)` Read the record for the key and the given mode.
`protected abstract int` `seek(java.lang.String key, int mode)` Position to the specified key.
`void` `setDebug(int level)` Set the debug level.
`protected abstract int` `top()` Position to the top/first record.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### debug

    protected int debug

### LE

    public static final int LE

  In read(), find an index key less than or equal.

### EQ

    public static final int EQ

  In read(), find an index key exactly equal.

### GE

    public static final int GE

  In read(), find an index key greater than or equal.

Constructor Detail

### XbaseIndex

    public XbaseIndex(XbaseFile xfile,
                      XbaseKey keyDescription,
                      int keyNo)

  Constructor.
  Parameters:
    `xfile` - The file containing the actual records.
    `keyDescription` - Used to retrieve the index key from the XbaseRecord.
    `keyNo` - An assigned key number. From XbaseFile.addIndex/getIndex.

Method Detail

### getRecordNumber

    public abstract int getRecordNumber()

  Get the current record number.
  Returns:
    The current record number from zero.

### top

    protected abstract int top()
                        throws java.io.IOException

  Position to the top/first record.
  Returns:
    The record number.

### bottom

    protected abstract int bottom()
                           throws java.io.IOException

  Position to the bottom/last record.
  Returns:
    The record number.

### next

    protected abstract int next()
                         throws java.io.IOException

  Position to the next record.
  Returns:
    The record number, -1 if no valid record.

### previous

    protected abstract int previous()
                             throws java.io.IOException

  Position to the previous record.
  Returns:
    The record number, -1 if no valid record.

### seek

    protected abstract int seek(java.lang.String key,
                                int mode)
                         throws java.io.IOException

  Position to the specified key.
  Returns:
    The record number, -1 if no valid record.

### setDebug

    public void setDebug(int level)

  Set the debug level. Debug information goes to stdout.
  Parameters:
    `level` - Debug level 0=none, 2=all.

### read

    public boolean read(XbaseRecord rec)
                 throws java.io.IOException

  Read the record for the exact key. The key value is in the correct field inside the XbaseRecord rec.
  Parameters:
    `rec` - The record to get the key information from, and to fill in if the read is successful.
  Returns:
    true if the record was found.

### read

    public boolean read(XbaseRecord rec,
                        int mode)
                 throws java.io.IOException

  Read the record for the key and the given mode. The key value is in the correct field inside the XbaseRecord rec.
  Parameters:
    `rec` - The record to get the key information from, and to fill in if the read is successful.
    `mode` - The read mode: XbaseIndex.LE - read the given key or a key less than, XbaseIndex.EQ - read the exact key only, XbaseIndex.GE - read the given key or greater.
  Returns:
    true if a record was found.

### first

    public boolean first(XbaseRecord rec)
                  throws java.io.IOException

  Go to the first record of the index.
  Parameters:
    `rec` - The record to fill in if the read is successful.
  Returns:
    true if a record was found.

### last

    public boolean last(XbaseRecord rec)
                 throws java.io.IOException

  Go to the last record of the index.
  Parameters:
    `rec` - The record to fill in if the read is successful.
  Returns:
    true if a record was found.

### next

    public boolean next(XbaseRecord rec)
                 throws java.io.IOException

  Go to the next record of the index. This XbaseIndex object maintains the state to record the current position in the index.
  Parameters:
    `rec` - The record to fill in if the read is successful.
  Returns:
    true if a record was found.

### previous

    public boolean previous(XbaseRecord rec)
                     throws java.io.IOException

  Go to the previous record of the index. This XbaseIndex object maintains the state to record the current position in the index.
  Parameters:
    `rec` - The record to fill in if the read is successful.
  Returns:
    true if a record was found.

### getIndexKeyNo

    public int getIndexKeyNo()

  Get the key number associated with this index. This is the value used in XbaseFile.addIndex().
  Returns:
    The key number.

### getFile

    public XbaseFile getFile()

  Get the file associated with this index.
  Returns:
    The XbaseFile used by this index.