Class CloseableIteratorHelper


  • public class CloseableIteratorHelper
    extends Object
    Contains helper methods to work with CloseableIterators
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> Stream<T> asStream​(com.mysema.commons.lang.CloseableIterator<T> iterator)
      Returns a Stream equivalent to the given iterator.
      static <T> com.mysema.commons.lang.CloseableIterator<T> chained​(com.mysema.commons.lang.CloseableIterator<? extends T>... iterators)
      Returns a Stream equivalent to the given iterator
      static <T> com.mysema.commons.lang.CloseableIterator<T> empty()
      Returns an empty CloseableIterator
      static <T> com.mysema.commons.lang.CloseableIterator<T> filtered​(com.mysema.commons.lang.CloseableIterator<T> iterator, Predicate<T> filter)
      Returns a CloseableIterator that skips elements that don't match the given filter
      static <T> com.mysema.commons.lang.CloseableIterator<T> lazy​(Supplier<com.mysema.commons.lang.CloseableIterator<T>> supplier)
      Returns a CloseableIterator that only initializes on hasNext() and next()
      static <T> Pair<T,​com.mysema.commons.lang.CloseableIterator<T>> peekFirst​(com.mysema.commons.lang.CloseableIterator<T> iterator)
      Peeks the first element of an iterator, returning it together with another iterator similar to the given one (also including the first element)
      static <T> com.mysema.commons.lang.CloseableIterator<T> singleton​(T element)
      Returns a CloseableIterator with a single element.
    • Constructor Detail

      • CloseableIteratorHelper

        public CloseableIteratorHelper()
    • Method Detail

      • asStream

        public static <T> Stream<T> asStream​(com.mysema.commons.lang.CloseableIterator<T> iterator)
        Returns a Stream equivalent to the given iterator. The returned Stream doesn't need to be closed after a terminal operation, because it will be wrapped in a Stream.flatMap(java.util.function.Function) call, which by definition closes the stream after a terminal operation.
      • chained

        @SafeVarargs
        public static <T> com.mysema.commons.lang.CloseableIterator<T> chained​(com.mysema.commons.lang.CloseableIterator<? extends T>... iterators)
        Returns a Stream equivalent to the given iterator
      • empty

        public static <T> com.mysema.commons.lang.CloseableIterator<T> empty()
        Returns an empty CloseableIterator
      • filtered

        public static <T> com.mysema.commons.lang.CloseableIterator<T> filtered​(com.mysema.commons.lang.CloseableIterator<T> iterator,
                                                                                Predicate<T> filter)
        Returns a CloseableIterator that skips elements that don't match the given filter
      • lazy

        public static <T> com.mysema.commons.lang.CloseableIterator<T> lazy​(Supplier<com.mysema.commons.lang.CloseableIterator<T>> supplier)
        Returns a CloseableIterator that only initializes on hasNext() and next()
      • peekFirst

        public static <T> Pair<T,​com.mysema.commons.lang.CloseableIterator<T>> peekFirst​(com.mysema.commons.lang.CloseableIterator<T> iterator)
        Peeks the first element of an iterator, returning it together with another iterator similar to the given one (also including the first element)
      • singleton

        public static <T> com.mysema.commons.lang.CloseableIterator<T> singleton​(T element)
        Returns a CloseableIterator with a single element. Closing is no-op.