Class SkippingIterator<E>

All Implemented Interfaces:
Iterator<E>

public class SkippingIterator<E> extends AbstractIteratorDecorator<E>
Decorates another iterator to skip the first N elements.

In case an offset parameter other than 0 is provided, the decorated iterator is immediately advanced to this position, skipping all elements before that position.

Since:
4.1
  • Field Details

    • offset

      private final long offset
      The offset to bound the first element return
    • pos

      private long pos
      The position of the current element
  • Constructor Details

    • SkippingIterator

      public SkippingIterator(Iterator<E> iterator, long offset)
      Decorates the specified iterator to skip all elements until the iterator reaches the position at offset.

      The iterator is immediately advanced until it reaches the position at offset, incurring O(n) time.

      Parameters:
      iterator - the iterator to be decorated
      offset - the index of the first element of the decorated iterator to return
      Throws:
      NullPointerException - if iterator is null
      IllegalArgumentException - if offset is negative
  • Method Details