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>
35          implements List<E> {
36  
37      /** Serialization version--necessary in an abstract class? */
38      private static final long serialVersionUID = 4500739654952315623L;
39  
40      /**
41       * Constructor only used in deserialization, do not use otherwise.
42       * @since 3.1
43       */
44      protected AbstractListDecorator() {
45      }
46  
47      /**
48       * Constructor that wraps (not copies).
49       *
50       * @param list  the list to decorate, must not be null
51       * @throws NullPointerException if list is null
52       */
53      protected AbstractListDecorator(final List<E> list) {
54          super(list);
55      }
56  
57      @Override
58      public void add(final int index, final E object) {
59          decorated().add(index, object);
60      }
61  
62      @Override
63      public boolean addAll(final int index, final Collection<? extends E> coll) {
64          return decorated().addAll(index, coll);
65      }
66  
67      /**
68       * Gets the list being decorated.
69       *
70       * @return the decorated list
71       */
72      @Override
73      protected List<E> decorated() {
74          return (List<E>) super.decorated();
75      }
76  
77      @Override
78      public boolean equals(final Object object) {
79          return object == this || decorated().equals(object);
80      }
81  
82      @Override
83      public E get(final int index) {
84          return decorated().get(index);
85      }
86  
87      @Override
88      public int hashCode() {
89          return decorated().hashCode();
90      }
91  
92      @Override
93      public int indexOf(final Object object) {
94          return decorated().indexOf(object);
95      }
96  
97      @Override
98      public int lastIndexOf(final Object object) {
99          return decorated().lastIndexOf(object);
100     }
101 
102     @Override
103     public ListIterator<E> listIterator() {
104         return decorated().listIterator();
105     }
106 
107     @Override
108     public ListIterator<E> listIterator(final int index) {
109         return decorated().listIterator(index);
110     }
111 
112     @Override
113     public E remove(final int index) {
114         return decorated().remove(index);
115     }
116 
117     @Override
118     public E set(final int index, final E object) {
119         return decorated().set(index, object);
120     }
121 
122     @Override
123     public List<E> subList(final int fromIndex, final int toIndex) {
124         return decorated().subList(fromIndex, toIndex);
125     }
126 
127 }