| java.lang.Object com.sleepycat.collections.StoredIterator
StoredIterator | public class StoredIterator implements BaseIterator,Cloneable(Code) | | The Iterator returned by all stored collections.
While in general this class conforms to the
Iterator interface,
it is important to note that all iterators for stored collections must be
explicitly closed with
StoredIterator.close() . The static method
StoredIterator.close(java.util.Iterator) allows calling close for all iterators without
harm to iterators that are not from stored collections, and also avoids
casting. If a stored iterator is not closed, unpredictable behavior
including process death may result.
This class implements the
Iterator interface for all stored
iterators. It also implements
ListIterator because some list
iterator methods apply to all stored iterators, for example,
StoredIterator.previous and
StoredIterator.hasPrevious . Other list iterator methods are always
supported for lists, but for other types of collections are only supported
under certain conditions. See
StoredIterator.nextIndex ,
StoredIterator.previousIndex ,
StoredIterator.add and
StoredIterator.set for details.
In addition, this class provides the following methods for stored
collection iterators only. Note that the use of these methods is not
compatible with the standard Java collections interface.
author: Mark Hayes |
Method Summary | |
public void | add(Object value) Inserts the specified element into the list or inserts a duplicate into
other types of collections (optional operation). | public static void | close(Iterator i) Closes the given iterator using
StoredIterator.close() if it is a
StoredIterator . | public void | close() Closes this iterator.
This method does not exist in the standard
Iterator or
ListIterator interfaces.
After being closed, only the
StoredIterator.hasNext and
StoredIterator.hasPrevious methods may be called and these will return false. | public int | count() Returns the number of elements having the same key value as the key
value of the element last returned by next() or previous(). | final public ListIterator | dup() | final public StoredCollection | getCollection() Returns the collection associated with this iterator. | public boolean | hasNext() Returns true if this iterator has more elements when traversing in the
forward direction. | public boolean | hasPrevious() Returns true if this iterator has more elements when traversing in the
reverse direction. | final public boolean | isCurrentData(Object currentData) | final public boolean | isReadModifyWrite() Returns whether write-locks will be obtained when reading with this
cursor. | final public boolean | moveToIndex(int index) | public Object | next() Returns the next element in the iteration. | public int | nextIndex() Returns the index of the element that would be returned by a subsequent
call to next.
This method conforms to the
ListIterator.nextIndex interface
except that it returns Integer.MAX_VALUE for stored lists when
positioned at the end of the list, rather than returning the list size
as specified by the ListIterator interface. | public Object | previous() Returns the next element in the iteration. | public int | previousIndex() Returns the index of the element that would be returned by a subsequent
call to previous. | public void | remove() Removes the last element that was returned by next or previous (optional
operation). | public void | set(Object value) Replaces the last element returned by next or previous with the
specified element (optional operation). | public void | setReadModifyWrite(boolean lockForWrite) Changes whether write-locks will be obtained when reading with this
cursor. |
add | public void add(Object value)(Code) | | Inserts the specified element into the list or inserts a duplicate into
other types of collections (optional operation).
This method conforms to the
ListIterator.add interface when
the collection is a list and the RECNO-RENUMBER access method is used.
Otherwise, this method may only be called when duplicates are allowed.
If duplicates are unsorted, the new value will be inserted in the same
manner as list elements.
If duplicates are sorted, the new value will be inserted in sort order.
Note that for the JE product, RECNO-RENUMBER databases are not
supported, and therefore this method may only be used to add
duplicates.
Parameters: value - the new value. throws: UnsupportedOperationException - if the collection is a sublist, orif the collection is indexed, or if the collection is read-only, or ifthe collection is a list and the RECNO-RENUMBER access method was notused, or if the collection is not a list and duplicates are not allowed. throws: IllegalStateException - if the collection is empty and is not alist with RECNO-RENUMBER access. throws: IllegalArgumentException - if a duplicate value is being addedthat already exists and duplicates are sorted. throws: RuntimeExceptionWrapper - if a DatabaseException isthrown. |
count | public int count()(Code) | | Returns the number of elements having the same key value as the key
value of the element last returned by next() or previous(). If no
duplicates are allowed, 1 is always returned.
This method does not exist in the standard
Iterator or
ListIterator interfaces.
the number of duplicates. throws: IllegalStateException - if next() or previous() has not beencalled for this iterator, or if remove() or add() were called afterthe last call to next() or previous(). |
getCollection | final public StoredCollection getCollection()(Code) | | Returns the collection associated with this iterator.
This method does not exist in the standard
Iterator or
ListIterator interfaces.
the collection associated with this iterator. |
isCurrentData | final public boolean isCurrentData(Object currentData)(Code) | | |
isReadModifyWrite | final public boolean isReadModifyWrite()(Code) | | Returns whether write-locks will be obtained when reading with this
cursor.
Obtaining write-locks can prevent deadlocks when reading and then
modifying data.
the write-lock setting. |
moveToIndex | final public boolean moveToIndex(int index)(Code) | | |
nextIndex | public int nextIndex()(Code) | | Returns the index of the element that would be returned by a subsequent
call to next.
This method conforms to the
ListIterator.nextIndex interface
except that it returns Integer.MAX_VALUE for stored lists when
positioned at the end of the list, rather than returning the list size
as specified by the ListIterator interface. This is because the database
size is not available.
the next index. throws: UnsupportedOperationException - if this iterator's collection doesnot use record number keys. throws: RuntimeExceptionWrapper - if a DatabaseException isthrown. |
remove | public void remove()(Code) | | Removes the last element that was returned by next or previous (optional
operation).
This method conforms to the
ListIterator.remove interface except
that when the collection is a list and the RECNO-RENUMBER access method
is not used, list indices will not be renumbered.
In order to call this method, if the underlying Database is
transactional then a transaction must be active when creating the
iterator.
Note that for the JE product, RECNO-RENUMBER databases are not
supported, and therefore list indices are never renumbered by this
method.
throws: UnsupportedOperationException - if the collection is a sublist, orif the collection is read-only. throws: RuntimeExceptionWrapper - if a DatabaseException isthrown. |
set | public void set(Object value)(Code) | | Replaces the last element returned by next or previous with the
specified element (optional operation).
This method conforms to the
ListIterator.set interface.
In order to call this method, if the underlying Database is
transactional then a transaction must be active when creating the
iterator.
Parameters: value - the new value. throws: UnsupportedOperationException - if the collection is a StoredKeySet (the set returned by java.util.Map.keySet), or ifduplicates are sorted since this would change the iterator position, orif the collection is indexed, or if the collection is read-only. throws: IllegalArgumentException - if an entity value binding is used andthe primary key of the value given is different than the existing storedprimary key. throws: RuntimeExceptionWrapper - if a DatabaseException isthrown. |
setReadModifyWrite | public void setReadModifyWrite(boolean lockForWrite)(Code) | | Changes whether write-locks will be obtained when reading with this
cursor.
Obtaining write-locks can prevent deadlocks when reading and then
modifying data.
Parameters: lockForWrite - the write-lock setting. |
|
|