T
- the type of elements returned by the iteratorpublic abstract class CloseableIterator<T> extends CloseableResource<Iterator<T>> implements Iterator<T>
CloseableIterator<T>
is an iterator which requires cleanup when it is no longer in use.
When the user creates CloseableIterator
, the closeResource()
method needs to be
implemented to define how the resource can be closed.
The iterator is not necessarily Closeable
so we do not provide a default implementation
for closeResource()
.
Users are required to use the factory methods instead of the constructors to create instances.Modifier and Type | Method and Description |
---|---|
static <T> CloseableIterator<T> |
concat(CloseableIterator<T> a,
CloseableIterator<T> b)
Combines two iterators into a single iterator.
|
static <T> CloseableIterator<T> |
concat(List<CloseableIterator<T>> iterators)
Concatenates iterators.
|
static <T> CloseableIterator<T> |
create(Iterator<? extends T> iterator,
java.util.function.Consumer<Void> closeAction)
Wrap around an iterator with a resource to close.
|
boolean |
hasNext() |
T |
next() |
static <T> CloseableIterator<T> |
noopCloseable(Iterator<? extends T> iterator)
Wraps around an iterator with no resource to close.
|
static int |
size(CloseableIterator<?> iter)
Consumes the iterator, closes it, and returns its size.
|
close, closeResource, get
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEachRemaining, remove
public static <T> CloseableIterator<T> create(Iterator<? extends T> iterator, java.util.function.Consumer<Void> closeAction)
T
- the type of the iterableiterator
- the iterator to wrap aroundcloseAction
- the callback to properly clean up the resourcepublic static <T> CloseableIterator<T> noopCloseable(Iterator<? extends T> iterator)
T
- the type of the iterableiterator
- the iterator to wrap aroundpublic static <T> CloseableIterator<T> concat(CloseableIterator<T> a, CloseableIterator<T> b)
T
- type of iteratora
- an iteratorb
- another iteratorpublic static <T> CloseableIterator<T> concat(List<CloseableIterator<T>> iterators)
T
- type of iteratoriterators
- a list of iteratorspublic static int size(CloseableIterator<?> iter)
iter
- the iter to get the size ofCopyright © 2023. All Rights Reserved.