Package nl.vpro.util

Class MaxOffsetIterator<T>

java.lang.Object
nl.vpro.util.MaxOffsetIterator<T>
All Implemented Interfaces:
com.google.common.collect.PeekingIterator<T>, AutoCloseable, Iterator<T>, CloseableIterator<T>, CloseablePeekingIterator<T>
Direct Known Subclasses:
CountedMaxOffsetIterator

public class MaxOffsetIterator<T> extends Object implements CloseablePeekingIterator<T>
An iterator implementing offset and max, for another iterator.
Since:
3.1
Author:
Michiel Meeuwissen
  • Field Details

    • wrapped

      protected final CloseableIterator<T> wrapped
    • peekingWrapped

      protected com.google.common.collect.PeekingIterator<T> peekingWrapped
    • offsetmax

      protected final long offsetmax
      The maximal value of count. I.e. offset + max;
    • count

      protected long count
      The count of the next element. First value will be the supplied value of offset.
    • hasNext

      protected Boolean hasNext
    • next

      protected T next
  • Constructor Details

    • MaxOffsetIterator

      public MaxOffsetIterator(Iterator<T> wrapped, Number max, boolean countNulls)
    • MaxOffsetIterator

      public MaxOffsetIterator(Iterator<T> wrapped, Number max)
    • MaxOffsetIterator

      public MaxOffsetIterator(Iterator<T> wrapped, Number max, Number offset)
    • MaxOffsetIterator

      public MaxOffsetIterator(Iterator<T> wrapped, Number max, Number offset, boolean countNulls)
    • MaxOffsetIterator

      protected MaxOffsetIterator(@NonNull Iterator<T> wrapped, @Nullable Number max, @Nullable Number offset, @Nullable Predicate<T> countPredicate, boolean countNulls, @Nullable List<Runnable> callbacks, boolean autoClose)
  • Method Details

    • effectiveCountPredicate

      protected static <S> Predicate<S> effectiveCountPredicate(Predicate<S> countPredicate, boolean countNulls)
    • callBack

      public MaxOffsetIterator<T> callBack(Runnable run)
    • autoClose

      public MaxOffsetIterator<T> autoClose(AutoCloseable... closeables)
    • autoClose

      public MaxOffsetIterator<T> autoClose()
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<T>
    • peek

      public T peek()
      Specified by:
      peek in interface com.google.common.collect.PeekingIterator<T>
    • next

      public T next()
      Specified by:
      next in interface Iterator<T>
      Specified by:
      next in interface com.google.common.collect.PeekingIterator<T>
    • findNext

      protected boolean findNext()
    • remove

      public void remove()
      Specified by:
      remove in interface Iterator<T>
      Specified by:
      remove in interface com.google.common.collect.PeekingIterator<T>
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • peekingWrapped

      public com.google.common.collect.PeekingIterator<T> peekingWrapped()
      Access to the (peeking) wrapped iterator. This may be used to look 'beyond' max, to check what would have been the next one.
    • countedBuilder

      public static <T> CountedMaxOffsetIterator.Builder<T> countedBuilder()
    • builder

      public static <T> MaxOffsetIterator.Builder<T> builder()
    • getOffset

      public long getOffset()