001    /*
002     * Copyright (C) 2007 Google Inc.
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    
017    package com.google.common.collect;
018    
019    import com.google.common.annotations.GwtCompatible;
020    
021    import java.util.Collection;
022    import java.util.List;
023    import java.util.ListIterator;
024    
025    import javax.annotation.Nullable;
026    
027    /**
028     * A list which forwards all its method calls to another list. Subclasses should
029     * override one or more methods to modify the behavior of the backing list as
030     * desired per the <a
031     * href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>.
032     *
033     * <p>This class does not implement {@link java.util.RandomAccess}. If the
034     * delegate supports random access, the {@code ForwardingList} subclass should
035     * implement the {@code RandomAccess} interface.
036     *
037     * @author Mike Bostock
038     * @since 2 (imported from Google Collections Library)
039     */
040    @GwtCompatible
041    public abstract class ForwardingList<E> extends ForwardingCollection<E>
042        implements List<E> {
043    
044      /** Constructor for use by subclasses. */
045      protected ForwardingList() {}
046    
047      @Override protected abstract List<E> delegate();
048    
049      public void add(int index, E element) {
050        delegate().add(index, element);
051      }
052    
053      public boolean addAll(int index, Collection<? extends E> elements) {
054        return delegate().addAll(index, elements);
055      }
056    
057      public E get(int index) {
058        return delegate().get(index);
059      }
060    
061      public int indexOf(Object element) {
062        return delegate().indexOf(element);
063      }
064    
065      public int lastIndexOf(Object element) {
066        return delegate().lastIndexOf(element);
067      }
068    
069      public ListIterator<E> listIterator() {
070        return delegate().listIterator();
071      }
072    
073      public ListIterator<E> listIterator(int index) {
074        return delegate().listIterator(index);
075      }
076    
077      public E remove(int index) {
078        return delegate().remove(index);
079      }
080    
081      public E set(int index, E element) {
082        return delegate().set(index, element);
083      }
084    
085      public List<E> subList(int fromIndex, int toIndex) {
086        return delegate().subList(fromIndex, toIndex);
087      }
088    
089      @Override public boolean equals(@Nullable Object object) {
090        return object == this || delegate().equals(object);
091      }
092    
093      @Override public int hashCode() {
094        return delegate().hashCode();
095      }
096    }