View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.collections4.list;
18  
19  import java.util.Collection;
20  import java.util.List;
21  import java.util.ListIterator;
22  
23  import org.apache.commons.collections4.collection.AbstractCollectionDecorator;
24  
25  /**
26   * Decorates another {@link List} to provide additional behavior.
27   * <p>
28   * Methods are forwarded directly to the decorated list.
29   * </p>
30   *
31   * @param <E> the type of the elements in the list.
32   * @since 3.0
33   */
34  public abstract class AbstractListDecorator<E> extends AbstractCollectionDecorator<E> implements List<E> {
35  
36      /** Serialization version--necessary in an abstract class? */
37      private static final long serialVersionUID = 4500739654952315623L;
38  
39      /**
40       * Constructor only used in deserialization, do not use otherwise.
41       * @since 3.1
42       */
43      protected AbstractListDecorator() {
44      }
45  
46      /**
47       * Constructor that wraps (not copies).
48       *
49       * @param list  the list to decorate, must not be null
50       * @throws NullPointerException if list is null
51       */
52      protected AbstractListDecorator(final List<E> list) {
53          super(list);
54      }
55  
56      @Override
57      public void add(final int index, final E object) {
58          decorated().add(index, object);
59      }
60  
61      @Override
62      public boolean addAll(final int index, final Collection<? extends E> coll) {
63          return decorated().addAll(index, coll);
64      }
65  
66      /**
67       * Gets the list being decorated.
68       *
69       * @return the decorated list
70       */
71      @Override
72      protected List<E> decorated() {
73          return (List<E>) super.decorated();
74      }
75  
76      @Override
77      public boolean equals(final Object object) {
78          return object == this || decorated().equals(object);
79      }
80  
81      @Override
82      public E get(final int index) {
83          return decorated().get(index);
84      }
85  
86      @Override
87      public int hashCode() {
88          return decorated().hashCode();
89      }
90  
91      @Override
92      public int indexOf(final Object object) {
93          return decorated().indexOf(object);
94      }
95  
96      @Override
97      public int lastIndexOf(final Object object) {
98          return decorated().lastIndexOf(object);
99      }
100 
101     @Override
102     public ListIterator<E> listIterator() {
103         return decorated().listIterator();
104     }
105 
106     @Override
107     public ListIterator<E> listIterator(final int index) {
108         return decorated().listIterator(index);
109     }
110 
111     @Override
112     public E remove(final int index) {
113         return decorated().remove(index);
114     }
115 
116     @Override
117     public E set(final int index, final E object) {
118         return decorated().set(index, object);
119     }
120 
121     @Override
122     public List<E> subList(final int fromIndex, final int toIndex) {
123         return decorated().subList(fromIndex, toIndex);
124     }
125 
126 }