1 /* 2 * Copyright (C) 2007 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 import com.google.common.annotations.GwtIncompatible; 21 22 import java.util.Collection; 23 import java.util.List; 24 import java.util.ListIterator; 25 26 import javax.annotation.Nullable; 27 28 /** 29 * A list which forwards all its method calls to another list. Subclasses should 30 * override one or more methods to modify the behavior of the backing list as 31 * desired per the <a 32 * href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>. 33 * 34 * <p>This class does not implement {@link java.util.RandomAccess}. If the 35 * delegate supports random access, the {@code ForwadingList} subclass should 36 * implement the {@code RandomAccess} interface. 37 * 38 * @author Mike Bostock 39 * @since 2010.01.04 <b>stable</b> (imported from Google Collections Library) 40 */ 41 @GwtCompatible 42 public abstract class ForwardingList<E> extends ForwardingCollection<E> 43 implements List<E> { 44 45 @Override protected abstract List<E> delegate(); 46 47 public void add(int index, E element) { 48 delegate().add(index, element); 49 } 50 51 public boolean addAll(int index, Collection<? extends E> elements) { 52 return delegate().addAll(index, elements); 53 } 54 55 public E get(int index) { 56 return delegate().get(index); 57 } 58 59 public int indexOf(Object element) { 60 return delegate().indexOf(element); 61 } 62 63 public int lastIndexOf(Object element) { 64 return delegate().lastIndexOf(element); 65 } 66 67 public ListIterator<E> listIterator() { 68 return delegate().listIterator(); 69 } 70 71 public ListIterator<E> listIterator(int index) { 72 return delegate().listIterator(index); 73 } 74 75 public E remove(int index) { 76 return delegate().remove(index); 77 } 78 79 public E set(int index, E element) { 80 return delegate().set(index, element); 81 } 82 83 @GwtIncompatible("List.subList") 84 public List<E> subList(int fromIndex, int toIndex) { 85 return Platform.subList(delegate(), fromIndex, toIndex); 86 } 87 88 @Override public boolean equals(@Nullable Object object) { 89 return object == this || delegate().equals(object); 90 } 91 92 @Override public int hashCode() { 93 return delegate().hashCode(); 94 } 95 } 96