Package wt.impact
Class WTChunkedIterator<T extends Persistable>
java.lang.Object
wt.impact.WTChunkedIterator<T>
- All Implemented Interfaces:
AutoCloseable,Iterator<T>
public class WTChunkedIterator<T extends Persistable>
extends Object
implements Iterator<T>, AutoCloseable
WTCollection iterator that inflates and deflates object references in chunks.
This iterator keeps memory usage low when iterating over large, deflated collections.
Supported API: true
Extendable: false
This iterator can only be used in the method server.
It is recommended that this iterator be used as resource in a try-with-resources block to ensure that inflated references are deflated if iteration terminates.
Examples:
WTCollection objects;
:
// objects collection is created and populated with deflated references
:
try (WTChunkedIterator partIter = new WTChunkedIterator(objects, 1000, WTPart.class)) {
while ( partIter.hasNext() ) {
WTPart part = partIter.next();
:
}
}
// All references in the collection that were originally deflated will be
// automatically deflated when the try-with-resources block exits.
// All references in the collection that were originally inflated will remain so.
:
If a try-with-resources block is not used then close() should be called
when the iterator is no longer needed:
WTCollection objects;
:
// objects collection is populated with deflated references
:
WTChunkedIterator partIter = new WTChunkedIterator(objects, 1000, WTPart.class);
while ( partIter.hasNext() ) {
WTPart part = partIter.next();
:
}
partIter.close(); // Deflate references.
:
Supported API: true
Extendable: false
-
Constructor Summary
ConstructorsConstructorDescriptionWTChunkedIterator(WTCollection collection, int chunkSize) Construct a new WTChunkedIterator for all Persistable classes.WTChunkedIterator(WTCollection collection, int chunkSize, Class<T> filter) Construct a new WTChunkedIterator for a filter class and all sub-classes.WTChunkedIterator(WTCollection collection, int chunkSize, Class<T> filter, boolean includeSubclasses) Construct a new WTChunkedIterator for a filter class. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining
-
Constructor Details
-
WTChunkedIterator
Construct a new WTChunkedIterator for all Persistable classes. Inflates objects in chunks to keep memory usage low.This iterator can only be used in the method server.
Supported API: true- Parameters:
collection- Collection of deflated object references.chunkSize- Number of references that are inflated in a chunk.
-
WTChunkedIterator
Construct a new WTChunkedIterator for a filter class and all sub-classes. Inflates objects in chunks to keep memory usage low.This iterator can only be used in the method server.
Supported API: true- Parameters:
collection- Collection of deflated object references.chunkSize- Number of references that are inflated in a chunk.filter- Object class filter.
-
WTChunkedIterator
public WTChunkedIterator(WTCollection collection, int chunkSize, Class<T> filter, boolean includeSubclasses) Construct a new WTChunkedIterator for a filter class. Inflates objects in chunks to keep memory usage low.This iterator can only be used in the method server.
Supported API: true- Parameters:
collection- Collection of deflated object references.chunkSize- Number of references that are inflated in a chunk.filter- Object class filter.includeSubclasses- True to iterated over the filter objects and all of its sub-classes, or false to iterated over only the filter objects.
-
-
Method Details
-
close
public void close()Deflate references and clear chunk collections. Called automatically if iterator is a resource in a try-with-resources block.
Supported API: true- Specified by:
closein interfaceAutoCloseable
-
hasNext
public boolean hasNext()
Supported API: true- Specified by:
hasNextin interfaceIterator<T extends Persistable>- Throws:
WTRuntimeException
-
next
Returns the next Persistable object in the collection. Objects will be inflated and deflated in chunks within next() calls.
Supported API: true- Specified by:
nextin interfaceIterator<T extends Persistable>- Throws:
NoSuchElementException
-