/** * Decorates the specified iterator to skip the first N elements. * * @param <E> the element type * @param iterator the iterator to decorate * @param offset the first number of elements to skip * @return a new skipping iterator * @throws NullPointerException if the iterator is null * @throws IllegalArgumentException if offset is negative * @since 4.1 */ public static <E> SkippingIterator<E> skippingIterator(final Iterator<E> iterator, final long offset) { return new SkippingIterator<>(iterator, offset); }
/** * 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(); }