Interface CloseableIterator<TYPE>

All Superinterfaces:
AutoCloseable, Iterator<TYPE>
All Known Subinterfaces:
ByteColumnIterator, CharacterColumnIterator, CloseablePrimitiveIterator<TYPE,TYPE_CONSUMER>, CloseablePrimitiveIteratorOfByte, CloseablePrimitiveIteratorOfChar, CloseablePrimitiveIteratorOfDouble, CloseablePrimitiveIteratorOfFloat, CloseablePrimitiveIteratorOfInt, CloseablePrimitiveIteratorOfLong, CloseablePrimitiveIteratorOfShort, ColumnIterator<DATA_TYPE>, DoubleColumnIterator, FloatColumnIterator, IntegerColumnIterator, LongColumnIterator, ObjectColumnIterator<DATA_TYPE>, ShortColumnIterator
All Known Implementing Classes:
ChunkedByteColumnIterator, ChunkedCharacterColumnIterator, ChunkedColumnIterator, ChunkedDoubleColumnIterator, ChunkedFloatColumnIterator, ChunkedIntegerColumnIterator, ChunkedLongColumnIterator, ChunkedObjectColumnIterator, ChunkedShortColumnIterator, SerialByteColumnIterator, SerialCharacterColumnIterator, SerialColumnIterator, SerialDoubleColumnIterator, SerialFloatColumnIterator, SerialIntegerColumnIterator, SerialLongColumnIterator, SerialObjectColumnIterator, SerialShortColumnIterator

public interface CloseableIterator<TYPE> extends Iterator<TYPE>, AutoCloseable
This interface extends Iterator and AutoCloseable in order to allow for iterators that acquire resources that must be released. Such iterators must document this need, and appropriate measures (e.g. a try-with-resources block) should be taken to ensure that they are closed. Methods that return streams over CloseableIterator instances should ensure that closing the resulting Stream, IntStream, LongStream, or DoubleStream will also close the iterator.
  • Field Details

    • EMPTY

      static final CloseableIterator<?> EMPTY
      A re-usable, immutable CloseableIterator with no elements.
  • Method Details

    • stream

      default Stream<TYPE> stream()
      Create a Stream over the remaining elements of this CloseableIterator. Closing the result will close this CloseableIterator.
      Returns:
      A Stream over the remaining contents of this iterator
    • close

      default void close()
      Specified by:
      close in interface AutoCloseable
    • empty

      static <TYPE> CloseableIterator<TYPE> empty()
      Get a CloseableIterator with no elements. The result does not need to be closed.
      Returns:
      A CloseableIterator with no elements
    • of

      @SafeVarargs static <TYPE> CloseableIterator<TYPE> of(@NotNull @NotNull TYPE... values)
      Create a CloseableIterator over an array of int. The result does not need to be closed.
      Parameters:
      values - The elements to iterate
      Returns:
      A CloseableIterator of values
    • repeat

      static <TYPE> CloseableIterator<TYPE> repeat(TYPE value, long repeatCount)
      Create a CloseableIterator that repeats value, repeatCount times. The result does not need to be closed.
      Parameters:
      value - The value to repeat
      repeatCount - The number of repetitions
      Returns:
      A CloseableIterator that repeats value, repeatCount times
    • concat

      @SafeVarargs static <TYPE> CloseableIterator<TYPE> concat(@NotNull @NotNull CloseableIterator<TYPE>... subIterators)
      Create a CloseableIterator that concatenates an array of non-null subIterators. The result only needs to be closed if any of the subIterators require it.
      Parameters:
      subIterators - The iterators to concatenate, none of which should be null. If directly passing an array, ensure that this iterator has full ownership.
      Returns:
      A CloseableIterator concatenating all elements from subIterators
    • maybeConcat

      static <TYPE> CloseableIterator<TYPE> maybeConcat(@Nullable @Nullable CloseableIterator<TYPE> first, @Nullable @Nullable CloseableIterator<TYPE> second, @Nullable @Nullable CloseableIterator<TYPE> third)
      Return a CloseableIterator that concatenates the contents of any non-null CloseableIterator found amongst first, second, and third.
      Parameters:
      first - The first iterator to consider concatenating
      second - The second iterator to consider concatenating
      third - The third iterator to consider concatenating
      Returns:
      A CloseableIterator that concatenates all elements as specified