gishur.core
Class CursorAdapter

java.lang.Object
  |
  +--gishur.core.CursorAdapter
All Implemented Interfaces:
Cursor, java.util.Enumeration
Direct Known Subclasses:
GraphCursor

public abstract class CursorAdapter
extends java.lang.Object
implements Cursor

A basic class implementing the Cursor-interface. The methods defining movement functionality for a Cursor are implemented, while methods for access to the structure, like Cursor.element(), have been left abstract. A class which shall be a "pure" Cursor, i.e. which has not to implement further functionality of another class, should be derived from CursorAdapter. The CursorAdapter treats its underlying structure like a ring of elements, where there's an invalid position between the last and the first element. That means, if you call next() while the cursor is set to an invalid position, you will reach the first element, and with prev() the last.

Version:
1.0
Author:
Christoph Sachse

Constructor Summary
protected CursorAdapter()
          Default Constructor.
 
Method Summary
 void bottom()
          Sets the Cursor to the last element.
 java.lang.Object getBookmark()
          Returns a bookmark-object.
 boolean hasMoreElements()
          Tests if this enumeration contains more elements.
 void next()
          Moves the Cursor on to the next position in forward direction (which is possibly invalid !).
 void next(int step)
          Moves the Cursor step elements in forward direction.
 java.lang.Object nextElement()
          Returns the next element of this enumeration if this enumeration object has at least one more element to provide (in fact it does the same as Cursor.element(), because the "next" element is the one the curosr points on, but after getting the element, nextElement() moves the cursor position on).
 void prev()
          Moves the Cursor on to the next position in backward direction (which is possibly invalid !).
 void prev(int step)
          Moves the Cursor step elements in backward direction.
 void set(int index)
          Sets the Cursor to the index-th position from the first element.
 void set(java.lang.Object bookmark)
          Sets the cursor to a bookmarked position.
 void top()
          Sets the Cursor to the first element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gishur.core.Cursor
element, invalidate, length, relative, valid
 

Constructor Detail

CursorAdapter

protected CursorAdapter()
Default Constructor. The newly created Cursor should point to the first element.
Method Detail

top

public void top()
Sets the Cursor to the first element.
Specified by:
top in interface Cursor

bottom

public void bottom()
Sets the Cursor to the last element.
Specified by:
bottom in interface Cursor

next

public void next(int step)
Moves the Cursor step elements in forward direction. It is possible, that the Cursor ends up on an invalid position because there were not step valid positions left.
Specified by:
next in interface Cursor
Parameters:
step - the number of elements to move in forward direction

prev

public void prev(int step)
Moves the Cursor step elements in backward direction. It is possible, that the Cursor ends up on an invalid position because there were not step valid positions left.
Specified by:
prev in interface Cursor
Parameters:
step - the number of elements to move in backward direction

next

public void next()
Moves the Cursor on to the next position in forward direction (which is possibly invalid !).
Specified by:
next in interface Cursor

prev

public void prev()
Moves the Cursor on to the next position in backward direction (which is possibly invalid !).
Specified by:
prev in interface Cursor

set

public void set(int index)
Sets the Cursor to the index-th position from the first element.
Specified by:
set in interface Cursor
Parameters:
index - the index-th element starting with the first one will be the Cursor's new position

getBookmark

public java.lang.Object getBookmark()
Returns a bookmark-object. If this function is not supported, a FunctionNotSupportedException will be thrown.
Specified by:
getBookmark in interface Cursor
Returns:
a bookmark-object.
See Also:
set(int)

set

public void set(java.lang.Object bookmark)
Sets the cursor to a bookmarked position. If this function is not supported, a FunctionNotSupportedException will be thrown.
Specified by:
set in interface Cursor
Parameters:
bookmark - a bookmark-object
See Also:
getBookmark()

hasMoreElements

public boolean hasMoreElements()
Tests if this enumeration contains more elements.
Specified by:
hasMoreElements in interface java.util.Enumeration
Returns:
true if and only if this enumeration object contains at least one more element to provide; false otherwise.

nextElement

public java.lang.Object nextElement()
Returns the next element of this enumeration if this enumeration object has at least one more element to provide (in fact it does the same as Cursor.element(), because the "next" element is the one the curosr points on, but after getting the element, nextElement() moves the cursor position on).
Specified by:
nextElement in interface java.util.Enumeration
Returns:
the next element of this enumeration.
Throws:
java.util.NoSuchElementException - if no more elements exist.