org.helidb
Interface Cursor<K,V>

All Superinterfaces:
Iterable<Record<K,V>>

public interface Cursor<K,V>
extends Iterable<Record<K,V>>

A cursor is used for navigating through the records of a database. (Unlike ordinary database cursors that are used for navigating through result sets from queries, HeliDB cursors are used for navigating through the entire database.)

The order of the database records that a cursor navigates through is determined by the database backend's search order and if an index is added to the database backend.

The cursor interface extends Iterable. The Iterator returned from the Iterable.iterator() method starts at the current record and iterates forward through the database. There is also a backwardsIterator() method that returns an iterator that iterates backwards in the database (if the database backend supports backwards iteration). The iterators do not modify the state of their parent cursors.

When a client is done with a cursor, it should close it by calling its close() method.

Since:
1.1
Author:
Karl Gustafsson
In_jar:
helidb-core

Method Summary
 Iterator<Record<K,V>> backwardsIterator()
          Get an Iterator that iterates backwards through the database records starting with the currently referenced record.
 void close()
          Close and invalidate the cursor.
 Record<K,V> get()
          Get the record that the cursor is currently referencing.
 K getKey()
          Get the key of the record that the cursor is currently referencing.
 V getValue()
          Get the value of the record that the cursor is currently referencing.
 boolean hasNext()
          Is there a record after the currently referenced record that the cursor can navigate to?
 boolean hasPrevious()
          Is there a record before the currently referenced record that the cursor can navigate to?
 K next()
          Navigate to the next record in the database.
 K previous()
          Navigate to the previous record in the database.
 
Methods inherited from interface java.lang.Iterable
iterator
 

Method Detail

getKey

K getKey()
         throws IllegalStateException,
                ConcurrentModificationException
Get the key of the record that the cursor is currently referencing.

Returns:
The record's key.
Throws:
IllegalStateException - If the cursor has been closed.
ConcurrentModificationException - If the database has been modified after the cursor was created.

getValue

V getValue()
           throws IllegalStateException,
                  ConcurrentModificationException
Get the value of the record that the cursor is currently referencing.

Returns:
The record's value.
Throws:
IllegalStateException - If the cursor has been closed.
ConcurrentModificationException - If the database has been modified after the cursor was created.

get

Record<K,V> get()
                throws IllegalStateException,
                       ConcurrentModificationException
Get the record that the cursor is currently referencing.

Returns:
The record.
Throws:
IllegalStateException - If the cursor has been closed.
ConcurrentModificationException - If the database has been modified after the cursor was created.

hasNext

boolean hasNext()
                throws IllegalStateException,
                       ConcurrentModificationException
Is there a record after the currently referenced record that the cursor can navigate to?

Returns:
true if there is another record after the currently referenced record.
Throws:
IllegalStateException - If the cursor has been closed.
ConcurrentModificationException - If the database has been modified after the cursor was created.

next

K next()
       throws IllegalStateException,
              NoSuchElementException,
              ConcurrentModificationException
Navigate to the next record in the database.

Returns:
The next record's key.
Throws:
IllegalStateException - If the cursor has been closed.
ConcurrentModificationException - If the database has been modified after the cursor was created.
NoSuchElementException - If there is no record after the currently referenced record.

hasPrevious

boolean hasPrevious()
                    throws IllegalStateException,
                           UnsupportedOperationException,
                           ConcurrentModificationException
Is there a record before the currently referenced record that the cursor can navigate to?

Returns:
true if there is a record before the currently referenced record.
Throws:
IllegalStateException - If the cursor has been closed.
ConcurrentModificationException - If the database has been modified after the cursor was created.
UnsupportedOperationException - If the database backend does not support backwards navigation.

previous

K previous()
           throws IllegalStateException,
                  UnsupportedOperationException,
                  ConcurrentModificationException,
                  NoSuchElementException
Navigate to the previous record in the database.

Returns:
The previous record's key.
Throws:
IllegalStateException - If the cursor has been closed.
ConcurrentModificationException - If the database has been modified after the cursor was created.
UnsupportedOperationException - If the database backend does not support backwards navigation.
NoSuchElementException - If there is no record before the currently referenced record.

backwardsIterator

Iterator<Record<K,V>> backwardsIterator()
                                        throws IllegalStateException,
                                               UnsupportedOperationException,
                                               ConcurrentModificationException
Get an Iterator that iterates backwards through the database records starting with the currently referenced record.

The state of this cursor is not modified by using the iterator.

Returns:
An iterator for iterating backwards through the database.
Throws:
IllegalStateException - If the cursor has been closed.
ConcurrentModificationException - If the database has been modified after the cursor was created.
UnsupportedOperationException - If the database backend does not support backwards iteration.

close

void close()
Close and invalidate the cursor.