001/*
002 * Copyright (C) 2007 The Guava Authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package com.google.common.collect;
018
019import com.google.common.annotations.GwtCompatible;
020
021import java.util.Iterator;
022
023/**
024 * An iterator which forwards all its method calls to another iterator.
025 * Subclasses should override one or more methods to modify the behavior of the
026 * backing iterator as desired per the <a
027 * href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>.
028 *
029 * @author Kevin Bourrillion
030 * @since 2.0
031 */
032@GwtCompatible
033public abstract class ForwardingIterator<T> extends ForwardingObject implements Iterator<T> {
034
035  /** Constructor for use by subclasses. */
036  protected ForwardingIterator() {}
037
038  @Override
039  protected abstract Iterator<T> delegate();
040
041  @Override
042  public boolean hasNext() {
043    return delegate().hasNext();
044  }
045
046  @Override
047  public T next() {
048    return delegate().next();
049  }
050
051  @Override
052  public void remove() {
053    delegate().remove();
054  }
055}