Interface CloseableIterator<T>

Type Parameters:
T - the type of elements returned by this iterator
All Superinterfaces:
AutoCloseable, Closeable, Iterator<T>

@Evolving public interface CloseableIterator<T> extends Iterator<T>, Closeable
Closeable extension of Iterator
Since:
3.0.0
  • Method Details

    • hasNext

      boolean hasNext()
      Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)
      Specified by:
      hasNext in interface Iterator<T>
      Returns:
      true if the iteration has more elements
      Throws:
      KernelEngineException - For any underlying exception occurs in Engine while trying to execute the operation. The original exception is (if any) wrapped in this exception as cause. E.g. IOException thrown while trying to read from a Delta log file. It will be wrapped in this exception as cause.
      KernelException - When encountered an operation or state that is invalid or unsupported.
    • next

      T next()
      Returns the next element in the iteration.
      Specified by:
      next in interface Iterator<T>
      Returns:
      the next element in the iteration
      Throws:
      NoSuchElementException - if the iteration has no more elements
      KernelEngineException - For any underlying exception occurs in Engine while trying to execute the operation. The original exception is (if any) wrapped in this exception as cause. E.g. IOException thrown while trying to read from a Delta log file. It will be wrapped in this exception as cause.
      KernelException - When encountered an operation or state that is invalid or unsupported in Kernel. For example, trying to read from a Delta table that has advanced features which are not yet supported by Kernel.
    • map

      default <U> CloseableIterator<U> map(Function<T,U> mapper)
    • filter

      default CloseableIterator<T> filter(Function<T,Boolean> mapper)
      Returns a new CloseableIterator that includes only the elements of this iterator for which the given mapper function returns true.
      Parameters:
      mapper - A function that determines whether an element should be included in the resulting iterator.
      Returns:
      A CloseableIterator that includes only the filtered the elements of this iterator.
    • takeWhile

      default CloseableIterator<T> takeWhile(Function<T,Boolean> mapper)
      Returns a new CloseableIterator that includes elements from this iterator as long as the given mapper function returns true. Once the mapper function returns false, the iteration is terminated.
      Parameters:
      mapper - A function that determines whether to include an element in the resulting iterator.
      Returns:
      A CloseableIterator that stops iteration when the condition is not met.
    • breakableFilter

      Returns a new CloseableIterator that applies a CloseableIterator.BreakableFilterResult-based filtering function to determine whether elements of this iterator should be included or excluded, or whether the iteration should terminate.
      Parameters:
      mapper - A function that determines the filtering action for each element: include, exclude, or break.
      Returns:
      A CloseableIterator that applies the specified CloseableIterator.BreakableFilterResult-based logic.
    • combine

      default CloseableIterator<T> combine(CloseableIterator<T> other)
      Combine the current iterator with another iterator. The resulting iterator will return all elements from the current iterator followed by all elements from the other iterator.
      Parameters:
      other - the other iterator to combine with
      Returns:
      a new iterator that combines the current iterator with the other iterator
    • toInMemoryList

      default List<T> toInMemoryList()
      Collects all elements from this CloseableIterator into a List.

      This method iterates through all elements of the iterator, storing them in an in-memory list. Once iteration is complete, the iterator is automatically closed to release any underlying resources.

      Returns:
      A List containing all elements from this iterator.
      Throws:
      UncheckedIOException - If an IOException occurs while closing the iterator.