1/*
2 * Copyright (C) 2008 The Guava Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.google.common.collect;
18
19import com.google.common.annotations.GwtCompatible;
20
21import java.util.Iterator;
22import java.util.NoSuchElementException;
23
24/**
25 * An iterator that supports a one-element lookahead while iterating.
26 *
27 * @author Mick Killianey
28 * @since 2.0 (imported from Google Collections Library)
29 */
30@GwtCompatible
31public interface PeekingIterator<E> extends Iterator<E> {
32  /**
33   * Returns the next element in the iteration, without advancing the iteration.
34   *
35   * <p>Calls to {@code peek()} should not change the state of the iteration,
36   * except that it <i>may</i> prevent removal of the most recent element via
37   * {@link #remove()}.
38   *
39   * @throws NoSuchElementException if the iteration has no more elements
40   *     according to {@link #hasNext()}
41   */
42  E peek();
43
44  /**
45   * {@inheritDoc}
46   *
47   * <p>The objects returned by consecutive calls to {@link #peek()} then {@link
48   * #next()} are guaranteed to be equal to each other.
49   */
50  @Override
51  E next();
52
53  /**
54   * {@inheritDoc}
55   *
56   * <p>Implementations may or may not support removal when a call to {@link
57   * #peek()} has occurred since the most recent call to {@link #next()}.
58   *
59   * @throws IllegalStateException if there has been a call to {@link #peek()}
60   *     since the most recent call to {@link #next()} and this implementation
61   *     does not support this sequence of calls (optional)
62   */
63  @Override
64  void remove();
65}
66