/** * Decorates the specified iterator to skip all elements until the iterator * reaches the position at {@code offset}. * <p> * The iterator is immediately advanced until it reaches the position at {@code offset}, * incurring O(n) time. * * @param iterator the iterator to be decorated * @param offset the index of the first element of the decorated iterator to return * @throws NullPointerException if iterator is null * @throws IllegalArgumentException if offset is negative */ public SkippingIterator(final Iterator<E> iterator, final long offset) { super(iterator); if (offset < 0) { throw new IllegalArgumentException("Offset parameter must not be negative."); } this.offset = offset; this.pos = 0; init(); }