T
- The type of data returned by the cursorpublic interface Cursor<T> extends Iterable<T>, Closeable
Iterable
for convenience. Cursors are not allowed to
contain null elements.
Note that the Iterable.iterator()
method does not return a fresh
iterator but rather a wrapper of this cursor; it is only present to allow
for-each loops over cursors. After it is exhausted, any iterator returned
will be null.
This class does not implement Iterator
because the 'is-a' relationship
does not hold; cursors must be closed by their clients while iterators do
not have such a requirement.
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the cursor.
|
Iterable<T> |
fast()
Deprecated.
Fast iteration is going away.
|
T |
fastNext()
Deprecated.
Fast iteration is going away
|
int |
getRowCount()
Get an upper bound on the number of rows available from the cursor.
|
boolean |
hasNext()
Query whether the cursor has any more items.
|
T |
next()
Fetch the next item from the cursor.
|
forEach, iterator, spliterator
int getRowCount()
next()
,
or -1 if that count is not available.boolean hasNext()
true
if there remains another item to fetch.@Nonnull T next()
NoSuchElementException
- if there are no more elements.RuntimeException
- if the cursor or its data source have been
closed (optional).@Deprecated @Nonnull T fastNext()
next()
that may mutate and return the same object
avoid excess allocations. Since many loops don't do anything with the
object after the iteration in which it is retrieved, using this iteration
method can improve both speed and memory use.next()
@Deprecated Iterable<T> fast()
Iterator.next()
method is
implemented in terms of fastNext()
.void close()
close()
(although implementations are
not required to enforce this). It is not an error to close a cursor
multiple times.close
in interface AutoCloseable
close
in interface Closeable