/** * @return the next element that will be returned from {@link #next()} without * actually advancing the iterator */ public T peek() { if ( hasFetchedNext ) { return nextObject; } nextObject = fetchNextOrNull(); hasFetchedNext = true; return nextObject; }
/** * @return {@code true} if there is a next item to be returned from the next * call to {@link #next()}. */ @Override public boolean hasNext() { return peek() != null; }
/** * Uses {@link #hasNext()} to try to fetch the next item and returns it * if found, otherwise it throws a {@link NoSuchElementException}. * * @return the next item in the iteration, or throws * {@link NoSuchElementException} if there's no more items to return. */ @Override public T next() { if ( !hasNext() ) { throw new NoSuchElementException(); } T result = nextObject; nextObject = null; hasFetchedNext = false; return result; }
/** * @return {@code true} if there is a next item to be returned from the next * call to {@link #next()}. */ @Override public boolean hasNext() { return peek() != null; }
/** * Uses {@link #hasNext()} to try to fetch the next item and returns it * if found, otherwise it throws a {@link NoSuchElementException}. * * @return the next item in the iteration, or throws * {@link NoSuchElementException} if there's no more items to return. */ @Override public T next() { if ( !hasNext() ) { throw new NoSuchElementException(); } T result = nextObject; nextObject = null; hasFetchedNext = false; return result; }
/** * @return the next element that will be returned from {@link #next()} without * actually advancing the iterator */ public T peek() { if ( hasFetchedNext ) { return nextObject; } nextObject = fetchNextOrNull(); hasFetchedNext = true; return nextObject; }