|
Berkeley DB version 4.3.29 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.sleepycat.collections.StoredIterator
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 close()
. The static method 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, previous()
and hasPrevious()
. Other list iterator methods are always
supported for lists, but for other types of collections are only supported
under certain conditions. See nextIndex()
, previousIndex()
,
add(java.lang.Object)
and set(java.lang.Object)
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.
Method Summary | |
void |
add(Object value)
Inserts the specified element into the list or inserts a duplicate into other types of collections (optional operation). |
void |
close()
Closes this iterator. |
static void |
close(Iterator i)
Closes the given iterator using close() if it is a StoredIterator . |
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(). |
StoredCollection |
getCollection()
Returns the collection associated with this iterator. |
boolean |
hasNext()
Returns true if this iterator has more elements when traversing in the forward direction. |
boolean |
hasPrevious()
Returns true if this iterator has more elements when traversing in the reverse direction. |
boolean |
isReadModifyWrite()
Returns whether write-locks will be obtained when reading with this cursor. |
Object |
next()
Returns the next element in the iteration. |
int |
nextIndex()
Returns the index of the element that would be returned by a subsequent call to next. |
Object |
previous()
Returns the next element in the iteration. |
int |
previousIndex()
Returns the index of the element that would be returned by a subsequent call to previous. |
void |
remove()
Removes the last element that was returned by next or previous (optional operation). |
void |
set(Object value)
Replaces the last element returned by next or previous with the specified element (optional operation). |
void |
setReadModifyWrite(boolean lockForWrite)
Changes whether write-locks will be obtained when reading with this cursor. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static void close(Iterator i)
close()
if it is a StoredIterator
. If the given iterator is not a StoredIterator
,
this method does nothing.
i
- is the iterator to close.
RuntimeExceptionWrapper
- if a DatabaseException
is thrown.public final boolean isReadModifyWrite()
public void setReadModifyWrite(boolean lockForWrite)
lockForWrite
- the write-lock setting.public boolean hasNext()
Iterator.hasNext()
interface.
hasNext
in interface ListIterator
next()
will succeed.
RuntimeExceptionWrapper
- if a DatabaseException
is thrown.public boolean hasPrevious()
ListIterator.hasPrevious()
interface.
hasPrevious
in interface ListIterator
previous()
will succeed.
RuntimeExceptionWrapper
- if a DatabaseException
is thrown.public Object next()
Iterator.next()
interface.
next
in interface ListIterator
RuntimeExceptionWrapper
- if a DatabaseException
is
thrown.public Object previous()
ListIterator.previous()
interface.
previous
in interface ListIterator
RuntimeExceptionWrapper
- if a DatabaseException
is
thrown.public int nextIndex()
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.
nextIndex
in interface ListIterator
UnsupportedOperationException
- if this iterator's collection does
not use record number keys.
RuntimeExceptionWrapper
- if a DatabaseException
is
thrown.public int previousIndex()
ListIterator.previousIndex()
interface.
previousIndex
in interface ListIterator
UnsupportedOperationException
- if this iterator's collection does
not use record number keys.
RuntimeExceptionWrapper
- if a DatabaseException
is
thrown.public void set(Object value)
ListIterator.set(java.lang.Object)
interface.
set
in interface ListIterator
value
- the new value.
UnsupportedOperationException
- if the collection is a StoredKeySet
(the set returned by Map.keySet()
), or if
duplicates are sorted since this would change the iterator position, or
if the collection is indexed, or if the collection is read-only.
IllegalArgumentException
- if an entity value binding is used and
the primary key of the value given is different than the existing stored
primary key.
RuntimeExceptionWrapper
- if a DatabaseException
is
thrown.public void remove()
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.
remove
in interface ListIterator
UnsupportedOperationException
- if the collection is a sublist, or
if the collection is read-only.
RuntimeExceptionWrapper
- if a DatabaseException
is
thrown.public void add(Object value)
ListIterator.add(java.lang.Object)
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.
add
in interface ListIterator
value
- the new value.
UnsupportedOperationException
- if the collection is a sublist, or
if the collection is indexed, or if the collection is read-only, or if
the collection is a list and the RECNO-RENUMBER access method was not
used, or if the collection is not a list and duplicates are not allowed.
IllegalStateException
- if the collection is empty and is not a
list with RECNO-RENUMBER access.
IllegalArgumentException
- if a duplicate value is being added
that already exists and duplicates are sorted.
RuntimeExceptionWrapper
- if a DatabaseException
is
thrown.public int count()
IllegalStateException
- if next() or previous() has not been
called for this iterator, or if remove() or add() were called after
the last call to next() or previous().public void close()
Iterator
or ListIterator
interfaces.
After being closed, only the hasNext()
and hasPrevious()
methods may be called and these will return false. close()
may also be called again and will do nothing. If other
methods are called a NullPointerException
will generally be
thrown.
RuntimeExceptionWrapper
- if a DatabaseException
is
thrown.public final StoredCollection getCollection()
Iterator
or ListIterator
interfaces.
|
Berkeley DB version 4.3.29 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |