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; 020import com.google.errorprone.annotations.CanIgnoreReturnValue; 021import java.util.ListIterator; 022import org.checkerframework.checker.nullness.qual.Nullable; 023 024/** 025 * A list iterator which forwards all its method calls to another list iterator. Subclasses should 026 * override one or more methods to modify the behavior of the backing iterator as desired per the <a 027 * href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>. 028 * 029 * <p><b>{@code default} method warning:</b> This class forwards calls to <i>only some</i> {@code 030 * default} methods. Specifically, it forwards calls only for methods that existed <a 031 * href="https://docs.oracle.com/javase/7/docs/api/java/util/ListIterator.html">before {@code 032 * default} methods were introduced</a>. For newer methods, like {@code forEachRemaining}, it 033 * inherits their default implementations. When those implementations invoke methods, they invoke 034 * methods on the {@code ForwardingListIterator}. 035 * 036 * @author Mike Bostock 037 * @since 2.0 038 */ 039@GwtCompatible 040public abstract class ForwardingListIterator<E extends @Nullable Object> 041 extends ForwardingIterator<E> implements ListIterator<E> { 042 043 /** Constructor for use by subclasses. */ 044 protected ForwardingListIterator() {} 045 046 @Override 047 protected abstract ListIterator<E> delegate(); 048 049 @Override 050 public void add(@ParametricNullness E element) { 051 delegate().add(element); 052 } 053 054 @Override 055 public boolean hasPrevious() { 056 return delegate().hasPrevious(); 057 } 058 059 @Override 060 public int nextIndex() { 061 return delegate().nextIndex(); 062 } 063 064 @CanIgnoreReturnValue 065 @Override 066 @ParametricNullness 067 public E previous() { 068 return delegate().previous(); 069 } 070 071 @Override 072 public int previousIndex() { 073 return delegate().previousIndex(); 074 } 075 076 @Override 077 public void set(@ParametricNullness E element) { 078 delegate().set(element); 079 } 080}