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 @Deprecated(forRemoval=true) @SubjectToRemoval(date=JAN_01_2025) public interface CloseableIterator<T> extends Iterator<T>, Closeable
Deprecated, for removal: This API element is subject to removal in a future version.
Will be removed without replacement.
Closeable iterator.

The iterator requires explicit closing, reaching the last element should not result in implicit close. IOException potentially thrown from a delegate Closeable.close() is expected to be wrapped in to an IllegalStateException.

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

    Modifier and Type
    Method
    Description
    default void
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    forward(long maxItems)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Forward this instance by discarding items.
    limit(long limit)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Return a view limiting the returned element count.
    limit(long limit, Consumer<Long> afterLimitReachedOrNull)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Return a view limiting the returned element count.
    default <U> CloseableIterator<U>
    transform(Function<T,U> transformation)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Apply a transformation of the elements of this Iterator.
    default <U> CloseableIterator<U>
    Deprecated, for removal: This API element is subject to removal in a future version.
    Apply a transformation on this Iterator.
    default <U> CloseableIterator<U>
    Deprecated, for removal: This API element is subject to removal in a future version.
    Transform multiple elements into a single element.

    Methods inherited from interface java.util.Iterator

    forEachRemaining, hasNext, next, remove
  • Method Details

    • close

      default void close() throws IllegalStateException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IllegalStateException
    • transform

      default <U> CloseableIterator<U> transform(Function<T,U> transformation)
      Deprecated, for removal: This API element is subject to removal in a future version.
      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)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Forward this instance by discarding items.
      Parameters:
      maxItems - Item count to discard.
      Returns:
      Reference to this instance
    • limit

      default CloseableIterator<T> limit(long limit)
      Deprecated, for removal: This API element is subject to removal in a future version.
      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)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Return a view limiting the returned element count.
      Parameters:
      limit - Max number of elements returned by the view
      afterLimitReachedOrNull - Optional callback to invoke when limit reached. Will be invoked from Iterator.hasNext() the first time it returns false. The role of this callback is to optionally sign that reading elements stopped because of reaching the specified limit. When no call made to Iterator.hasNext() after reaching this limit no callback invocation will be made. Also when when Iterator.next() invoked after reaching the limit it will throw a NoSuchElementException but no callback invocation will be made.
      Returns:
      limiting view
    • transformIterator

      default <U> CloseableIterator<U> transformIterator(Function<Iterator<T>,Iterator<U>> processor)
      Deprecated, for removal: This API element is subject to removal in a future version.
      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)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Transform multiple elements into a single element.
      Type Parameters:
      U - Type of transformed elements
      Parameters:
      constructNext - Function to create next element
      Returns:
      Transformed Iterator