1090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/*
21d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Copyright (C) 2008 The Guava Authors
3090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *
4090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * Licensed under the Apache License, Version 2.0 (the "License");
5090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * you may not use this file except in compliance with the License.
6090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * You may obtain a copy of the License at
7090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *
8090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * http://www.apache.org/licenses/LICENSE-2.0
9090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *
10090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * Unless required by applicable law or agreed to in writing, software
11090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS,
12090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * See the License for the specific language governing permissions and
14090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * limitations under the License.
15090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson */
16090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
17090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonpackage com.google.common.collect;
18090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
19090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonimport com.google.common.annotations.GwtCompatible;
20090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
21090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonimport java.util.Iterator;
22090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonimport java.util.NoSuchElementException;
23090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
24090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/**
25090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * An iterator that supports a one-element lookahead while iterating.
267dd252788645e940eada959bdde927426e2531c9Paul Duffin *
277dd252788645e940eada959bdde927426e2531c9Paul Duffin * <p>See the Guava User Guide article on <a href=
287dd252788645e940eada959bdde927426e2531c9Paul Duffin * "http://code.google.com/p/guava-libraries/wiki/CollectionHelpersExplained#PeekingIterator">
297dd252788645e940eada959bdde927426e2531c9Paul Duffin * {@code PeekingIterator}</a>.
30090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *
31090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * @author Mick Killianey
321d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @since 2.0 (imported from Google Collections Library)
33090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson */
34090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson@GwtCompatible
35090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonpublic interface PeekingIterator<E> extends Iterator<E> {
36090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  /**
37090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   * Returns the next element in the iteration, without advancing the iteration.
38090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   *
39090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   * <p>Calls to {@code peek()} should not change the state of the iteration,
40090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   * except that it <i>may</i> prevent removal of the most recent element via
41090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   * {@link #remove()}.
42090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   *
43090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   * @throws NoSuchElementException if the iteration has no more elements
44090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   *     according to {@link #hasNext()}
45090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   */
46090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  E peek();
47090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
48090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  /**
49090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   * {@inheritDoc}
50090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   *
51090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   * <p>The objects returned by consecutive calls to {@link #peek()} then {@link
52090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   * #next()} are guaranteed to be equal to each other.
53090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   */
540888a09821a98ac0680fad765217302858e70fa4Paul Duffin  @Override
55090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  E next();
56090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
57090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  /**
58090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   * {@inheritDoc}
59090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   *
60090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   * <p>Implementations may or may not support removal when a call to {@link
61090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   * #peek()} has occurred since the most recent call to {@link #next()}.
62090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   *
63090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   * @throws IllegalStateException if there has been a call to {@link #peek()}
64090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   *     since the most recent call to {@link #next()} and this implementation
65090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   *     does not support this sequence of calls (optional)
66090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   */
670888a09821a98ac0680fad765217302858e70fa4Paul Duffin  @Override
68090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  void remove();
69090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson}
70