Skip to content

Commit

Permalink
Document interaction between peek and filter iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-confino committed Jul 16, 2024
1 parent 70daade commit 21f65ff
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public PeekingIterator(final Iterator<? extends E> iterator) {

/**
* Returns the next element in iteration without advancing the underlying iterator.
* If the iterator is already exhausted, null will be returned.
* <p>
* Note that if the underlying iterator is a {@link FilterIterator} or a {@link FilterListIterator}, the underlying predicate
* will <em>not</em> be tested if element() or {@link #peek()} has been called after the most recent invocation of {@link #next()}
*
* @return the next element from the iterator
* @throws NoSuchElementException if the iterator is already exhausted according to {@link #hasNext()}
Expand Down Expand Up @@ -110,6 +112,15 @@ public boolean hasNext() {
return slotFilled || iterator.hasNext();
}

/**
* Returns the next element in iteration.
* <p>
* Note that if the underlying iterator is a {@link FilterIterator} or a {@link FilterListIterator}, the underlying predicate
* will <em>not</em> be tested if {@link #element()} or {@link #peek()} has been called after the most recent invocation of next()
*
* @return the next element from the iterator
* @throws NoSuchElementException if the iterator is already exhausted according to {@link #hasNext()}
*/
@Override
public E next() {
if (!hasNext()) {
Expand All @@ -131,6 +142,9 @@ public E next() {
* <p>
* The rationale behind this is to follow the {@link java.util.Queue} interface
* which uses the same terminology.
* <p>
* Note that if the underlying iterator is a {@link FilterIterator} or a {@link FilterListIterator}, the underlying predicate
* will <em>not</em> be tested if {@link #element()} or peek() has been called after the most recent invocation of {@link #next()}
*
* @return the next element from the iterator
*/
Expand Down

0 comments on commit 21f65ff

Please sign in to comment.