1 /* 2 * Copyright (C) 2008 Google Inc. 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 17 package com.google.common.collect; 18 19 import com.google.common.annotations.GwtCompatible; 20 21 import java.util.Iterator; 22 import java.util.NoSuchElementException; 23 24 /** 25 * An iterator that supports a one-element lookahead while iterating. 26 * 27 * @author Mick Killianey 28 * @since 2010.01.04 <b>stable</b> (imported from Google Collections Library) 29 */ 30 @GwtCompatible 31 public 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 E next(); 51 52 /** 53 * {@inheritDoc} 54 * 55 * <p>Implementations may or may not support removal when a call to {@link 56 * #peek()} has occurred since the most recent call to {@link #next()}. 57 * 58 * @throws IllegalStateException if there has been a call to {@link #peek()} 59 * since the most recent call to {@link #next()} and this implementation 60 * does not support this sequence of calls (optional) 61 */ 62 void remove(); 63 } 64