Package com.coyotegulch.jisp
Class BTreeIterator
- java.lang.Object
-
- com.coyotegulch.jisp.BTreeIterator
-
- All Implemented Interfaces:
IndexIterator
public class BTreeIterator extends java.lang.Object implements IndexIterator
BTreeIteratordefines an object that references a specific object relative to other objects in anObjectIndex. In many ways, aBTreeIteratoris analogous to the "cursors" found in SQL-type databases; it is essentially a movable reference to elements in an index, and it can be moved forward and backward through the list of keys.- See Also:
ObjectIndex,IndexedObjectDatabase
-
-
Constructor Summary
Constructors Constructor Description BTreeIterator(BTreeIndex index)Creates a newBTreeIteratorfor a given index and database.BTreeIterator(BTreeIterator iterator)Creates a newBTreeIteratorthat points to the same location as an existingBtreeIterator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.ObjectgetKey()Returns the keyObjectcurrently associated with this iterator.longgetRecPtr()Returns the reference (usually a file pointer) currently associated with this iterator.voidinvalidate()Sets this iterator's state to invalid.booleanisValid()Checks to see if this iterator is valid.booleanmoveFirst()Moves this iterator to the first key and reference in sequence.booleanmoveLast()Moves this iterator to the last key and reference in sequence.booleanmoveNext()Moves this iterator to the next key and reference in sequence.booleanmovePrevious()Moves this iterator to the previous key and reference in sequence.booleanmoveTo(KeyObject key)Moves this iterator to point to the givenkey.booleanmoveTo(KeyObject key, boolean acceptNext)Moves this iterator to point to the givenkey.
-
-
-
Constructor Detail
-
BTreeIterator
public BTreeIterator(BTreeIndex index) throws java.io.IOException, java.lang.ClassNotFoundException
Creates a newBTreeIteratorfor a given index and database.- Parameters:
index- the index to which this iterator is attached.- Throws:
java.io.IOException- when an I/O exception is thrown by an underlying java.io.* classjava.lang.ClassNotFoundException- for a casting error, usually when a persistent object or index does match the expected type- See Also:
BTreeIndex
-
BTreeIterator
public BTreeIterator(BTreeIterator iterator) throws java.io.IOException, java.lang.ClassNotFoundException
Creates a newBTreeIteratorthat points to the same location as an existingBtreeIterator.- Parameters:
iterator- the iterator to be copied.- Throws:
java.io.IOException- when an I/O exception is thrown by an underlying java.io.* classjava.lang.ClassNotFoundException- for a casting error, usually when a persistent object or index does match the expected type- See Also:
BTreeIndex
-
-
Method Detail
-
getRecPtr
public long getRecPtr() throws java.io.IOExceptionReturns the reference (usually a file pointer) currently associated with this iterator.- Specified by:
getRecPtrin interfaceIndexIterator- Returns:
- the record
Objectcurrently referenced by this iterator, or -1 if the iterator is invalid - Throws:
java.io.IOException
-
getKey
public java.lang.Object getKey() throws java.io.IOExceptionReturns the keyObjectcurrently associated with this iterator.- Specified by:
getKeyin interfaceIndexIterator- Returns:
- the key
Objectcurrently referenced by this iterator, or null if the iterator is invalid - Throws:
java.io.IOException- when an I/O exception is thrown by an underlying java.io.* class
-
moveNext
public boolean moveNext() throws java.io.IOException, java.lang.ClassNotFoundExceptionMoves this iterator to the next key and reference in sequence.- Specified by:
moveNextin interfaceIndexIterator- Returns:
trueif the operation was successful;falseotherwise.- Throws:
java.io.IOException- when an I/O exception is thrown by an underlying java.io.* classjava.lang.ClassNotFoundException- for a casting error, usually when a persistent object or index does match the expected type
-
movePrevious
public boolean movePrevious() throws java.io.IOException, java.lang.ClassNotFoundExceptionMoves this iterator to the previous key and reference in sequence.- Specified by:
movePreviousin interfaceIndexIterator- Returns:
trueif the operation was successful;falseotherwise.- Throws:
java.io.IOException- when an I/O exception is thrown by an underlying java.io.* classjava.lang.ClassNotFoundException- for a casting error, usually when a persistent object or index does match the expected typeBTreeException- when an error occurs during B-Tree processing
-
moveFirst
public boolean moveFirst() throws java.io.IOException, java.lang.ClassNotFoundExceptionMoves this iterator to the first key and reference in sequence.- Specified by:
moveFirstin interfaceIndexIterator- Returns:
trueif the operation was successful;falseotherwise.- Throws:
java.io.IOException- when an I/O exception is thrown by an underlying java.io.* classjava.lang.ClassNotFoundException- for a casting error, usually when a persistent object or index does match the expected typeBTreeException- when an error occurs during B-Tree processing
-
moveLast
public boolean moveLast() throws java.io.IOException, java.lang.ClassNotFoundExceptionMoves this iterator to the last key and reference in sequence.- Specified by:
moveLastin interfaceIndexIterator- Returns:
trueif the operation was successful;falseotherwise.- Throws:
java.io.IOException- when an I/O exception is thrown by an underlying java.io.* classjava.lang.ClassNotFoundException- for a casting error, usually when a persistent object or index does match the expected typeBTreeException- when an error occurs during B-Tree processing
-
moveTo
public boolean moveTo(KeyObject key) throws java.io.IOException, java.lang.ClassNotFoundException
Moves this iterator to point to the givenkey.- Specified by:
moveToin interfaceIndexIterator- Parameters:
key- key identifier to find- Returns:
trueif the operation was successful;falseotherwise.- Throws:
java.io.IOException- when an I/O exception is thrown by an underlying java.io.* classjava.lang.ClassNotFoundException- for a casting error, usually when a persistent object or index does match the expected typeBTreeException- when an error occurs during B-Tree processing
-
moveTo
public boolean moveTo(KeyObject key, boolean acceptNext) throws java.io.IOException, java.lang.ClassNotFoundException
Moves this iterator to point to the givenkey.- Specified by:
moveToin interfaceIndexIterator- Parameters:
key- key identifier to findacceptNext- when true, allows the search to return the next record in sequence if an exact match is not found- Returns:
trueif the operation was successful;falseotherwise.- Throws:
java.io.IOException- when an I/O exception is thrown by an underlying java.io.* classjava.lang.ClassNotFoundException- for a casting error, usually when a persistent object or index does match the expected typeBTreeException- when an error occurs during B-Tree processing
-
isValid
public boolean isValid()
Checks to see if this iterator is valid.- Specified by:
isValidin interfaceIndexIterator- Returns:
trueif the iterator is valid;falseif it is invalid.
-
invalidate
public void invalidate()
Sets this iterator's state to invalid.
-
-