T
- The type being iterated.public class SimpleMongoIteratorImpl<T> extends Object implements MongoIterator<T>
BATCH_SIZE_FIELD, CURSOR_ID_FIELD, LIMIT_FIELD, NAME_SPACE_FIELD, SERVER_FIELD
Constructor and Description |
---|
SimpleMongoIteratorImpl(Collection<T> wrapped)
Create a new SimpleMongoIteratorImpl.
|
Modifier and Type | Method and Description |
---|---|
Document |
asDocument()
Returns a
Document that can be used to restart the
cursor/iterator. |
void |
close()
Close the iterator and release any resources it is holding.
|
int |
getBatchSize()
Returns the size for batches of documents that are requested.
|
boolean |
hasNext() |
Iterator<T> |
iterator() |
T |
next() |
void |
remove() |
void |
setBatchSize(int batchSize)
Sets the size for future batch sizes.
|
void |
stop()
Stops the iterator after consuming any received and/or requested batches.
|
Object[] |
toArray()
Consumes all of the elements in the iterator and returns them in a single
array.
|
<S> S[] |
toArray(S[] to)
Consumes all of the elements in the iterator and returns them in a single
array.
|
List<T> |
toList()
Consumes all of the elements in the iterator and returns them in a single
mutable list.
|
public SimpleMongoIteratorImpl(Collection<T> wrapped)
wrapped
- The collection to turn into a MongoIterator
.public Document asDocument()
Document
that can be used to restart the
cursor/iterator.
If this iterator is exhausted or closed then the cursor is also closed on the server and this method will return null.
If the cursor/Find
was not created with out a timeout then
eventually the server will automatically remove the cursor and the
restart will fail.
Returns the active cursor in the form:
{ "ns" : '<database_name>.$lt;collection_name>', "cursor_id" : <cursor_id>, "server" : '<server>', "limit" : <remaining_limit> "batch_size" : <batch_size> }
Overridden to return the null as this cursor cannot be restarted.
asDocument
in interface MongoCursorControl
null
if the server's cursor has been exhausted or
closed.public void close()
Overridden to do nothing.
close
in interface ClosableIterator<T>
close
in interface MongoCursorControl
close
in interface Closeable
close
in interface AutoCloseable
public int getBatchSize()
Overridden to return -1.
getBatchSize
in interface ClosableIterator<T>
getBatchSize
in interface MongoCursorControl
public boolean hasNext()
Overridden to return true if there are more documents.
public T next()
Overridden to return the next document from the query.
next
in interface Iterator<T>
Iterator.next()
public void remove()
Overridden to throw an UnsupportedOperationException
.
remove
in interface Iterator<T>
Iterator.remove()
public void setBatchSize(int batchSize)
Overridden to do nothing as this iterator only supports single batch results.
setBatchSize
in interface ClosableIterator<T>
setBatchSize
in interface MongoCursorControl
batchSize
- The size to request for future batch sizes.public void stop()
WARNING: This will leave the cursor open on the server. Even a
MongoCursorControl.close()
on this object will not close the cursor on the server.
Users should persist the state of the cursor as returned from
MongoCursorControl.asDocument()
and restart the cursor using one of the
MongoClient.restart(com.allanbank.mongodb.bson.DocumentAssignable)
or
MongoClient.restart(StreamCallback, com.allanbank.mongodb.bson.DocumentAssignable)
methods. Use MongoCursorControl.stop()
with extreme caution.
The iterator or stream will naturally stop (
Iterator.hasNext()
will return false or the stream's call
back StreamCallback.done()
method will be called) when the
current batch and any batches already requested are exhausted.
Overridden to do nothing as this iterator only supports single batch results.
stop
in interface MongoCursorControl
public Object[] toArray()
WARNING: This method loads all of the iterator results into memory and
may cause an OutOfMemoryError
.
Overridden to return the remaining elements as a array.
toArray
in interface MongoIterator<T>
public <S> S[] toArray(S[] to)
WARNING: This method loads all of the iterator results into memory and
may cause an OutOfMemoryError
.
Overridden to return the remaining elements as a array.
toArray
in interface MongoIterator<T>
S
- The type of elements in the array.to
- The array to copy into. If not the right size a new array will
be allocated of the right size.public List<T> toList()
WARNING: This method loads all of the iterator results into memory and
may cause an OutOfMemoryError
.
Overridden to return the remaining elements as a list.
toList
in interface MongoIterator<T>
Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.