Package com.chemaxon.calculations.io
Interface CloseableIterator<T>
-
- Type Parameters:
T
- iterated type
- All Superinterfaces:
AutoCloseable
,Closeable
,Iterator<T>
- All Known Implementing Classes:
com.chemaxon.calculations.io.CloseableAbstractIterator
,MemoizingIterator
,SmilesMemoizingMoleculeIterator
@Beta @PublicAPI public interface CloseableIterator<T> extends Iterator<T>, Closeable
Closeable iterator. The iterator requires explicit closing, reaching the last element should not result in implicit close.IOException
potentially thrown from a delegateCloseable.close()
is expected to be wrapped in to anIllegalStateException
.For providing an implementation one can use
CloseableIterators.wrap(java.util.Iterator)
,CloseableIterators.wrap(java.util.Iterator, java.io.Closeable)
or .Please note that this interface is marked with @Beta annotation, so it can be subject of incompatible changes or removal in later releases.
-
-
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default void
close()
default CloseableIterator<T>
forward(long maxItems)
Forward this instance by discarding items.default CloseableIterator<T>
limit(long limit)
Return a view limiting the returned element count.default CloseableIterator<T>
limit(long limit, Consumer<Long> afterLimitReachedOrNull)
Return a view limiting the returned element count.default <U> CloseableIterator<U>
transform(Function<T,U> transformation)
Apply a transformation of the elements of this Iterator.default <U> CloseableIterator<U>
transformIterator(Function<Iterator<T>,Iterator<U>> processor)
Apply a transformation on this Iterator.default <U> CloseableIterator<U>
transformMultipleElements(Function<Iterator<T>,U> constructNext)
Transform multiple elements into a single element.-
Methods inherited from interface java.util.Iterator
forEachRemaining, hasNext, next, remove
-
-
-
-
Method Detail
-
close
default void close() throws IllegalStateException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IllegalStateException
-
transform
default <U> CloseableIterator<U> transform(Function<T,U> transformation)
Apply a transformation of the elements of this Iterator.- Type Parameters:
U
- Transformed type- Parameters:
transformation
- Transformation to apply on returned elements- Returns:
- Transformed view of this Iterator
-
forward
default CloseableIterator<T> forward(long maxItems)
Forward this instance by discarding items.- Parameters:
maxItems
- Item count to discard.- Returns:
- Reference to
this
instance
-
limit
default CloseableIterator<T> limit(long limit)
Return a view limiting the returned element count.- Parameters:
limit
- Max number of elements returned by the view- Returns:
- limiting view
-
limit
default CloseableIterator<T> limit(long limit, Consumer<Long> afterLimitReachedOrNull)
Return a view limiting the returned element count.- Parameters:
limit
- Max number of elements returned by the viewafterLimitReachedOrNull
- Optional callback to invoke when limit reached. Will be invoked fromIterator.hasNext()
the first time it returnsfalse
. The role of this callback is to optionally sign that reading elements stopped because of reaching the specified limit. When no call made toIterator.hasNext()
after reaching this limit no callback invocation will be made. Also when whenIterator.next()
invoked after reaching the limit it will throw aNoSuchElementException
but no callback invocation will be made.- Returns:
- limiting view
-
transformIterator
default <U> CloseableIterator<U> transformIterator(Function<Iterator<T>,Iterator<U>> processor)
Apply a transformation on this Iterator.- Type Parameters:
U
- Type of transformed elements- Parameters:
processor
- Function to call on this instance- Returns:
- Transformed Iterator
-
transformMultipleElements
default <U> CloseableIterator<U> transformMultipleElements(Function<Iterator<T>,U> constructNext)
Transform multiple elements into a single element.- Type Parameters:
U
- Type of transformed elements- Parameters:
constructNext
- Function to create next element- Returns:
- Transformed Iterator
-
-