@Test(expected=NoSuchElementException.class) public void nextOnEmpty() { Iterator<Integer> iterator = onlyEvens(); iterator.next(); }
@Override public T next() { if (state == State.FRESH || state == State.NEXT_RETRIEVED) { advance(); } if (state == State.DONE) { throw new NoSuchElementException(); } assert state == State.NEXT_PENDING : state; state = State.NEXT_RETRIEVED; return next; }
FilteringIterator implements Iterator<T> { @Override public T next() { if (state == State.FRESH || state == State.NEXT_RETRIEVED) { advance(); } if (state == State.DONE) { throw new NoSuchElementException(); } assert state == State.NEXT_PENDING : state; state = State.NEXT_RETRIEVED; return next; } }
FilteringIterator implements Iterator<T> { @Override public T next() { if (state == State.FRESH || state == State.NEXT_RETRIEVED) { advance(); } if (state == State.DONE) { throw new NoSuchElementException(); } assert state == State.NEXT_PENDING : state; state = State.NEXT_RETRIEVED; return next; } FilteringIterator(Iterator<T> delegate, boolean isMutable); }
FilteringIterator implements Iterator<T> { @Override public T next() { if (state == State.FRESH || state == State.NEXT_RETRIEVED) { advance(); } if (state == State.DONE) { throw new NoSuchElementException(); } assert state == State.NEXT_PENDING : state; state = State.NEXT_RETRIEVED; return next; } FilteringIterator(Iterator<T> delegate, boolean isMutable); @Override boolean hasNext(); @Override T next(); @Override void remove(); }
FilteringIterator implements Iterator<T> { @Override public T next() { if (state == State.FRESH || state == State.NEXT_RETRIEVED) { advance(); } if (state == State.DONE) { throw new NoSuchElementException(); } assert state == State.NEXT_PENDING : state; state = State.NEXT_RETRIEVED; return next; } FilteringIterator(Iterator<T> delegate, boolean isMutable); @Override boolean hasNext(); @Override T next(); @Override void remove();  }