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.collections.list;
18  
19  import java.util.Collection;
20  import java.util.List;
21  import java.util.ListIterator;
22  
23  import org.apache.commons.collections.collection.AbstractCollectionDecorator;
24  
25  /**
26   * Decorates another {@link List} to provide additional behaviour.
27   * <p>
28   * Methods are forwarded directly to the decorated list.
29   *
30   * @param <E> the type of the elements in the list
31   * @since 3.0
32   * @version $Id: AbstractListDecorator.java 1429905 2013-01-07 17:15:14Z ggregory $
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          super();
46      }
47  
48      /**
49       * Constructor that wraps (not copies).
50       * 
51       * @param list  the list to decorate, must not be null
52       * @throws IllegalArgumentException if list is null
53       */
54      protected AbstractListDecorator(final List<E> list) {
55          super(list);
56      }
57  
58      /**
59       * Gets the list being decorated.
60       * 
61       * @return the decorated list
62       */
63      @Override
64      protected List<E> decorated() {
65          return (List<E>) super.decorated();
66      }
67  
68      //-----------------------------------------------------------------------
69      
70      public void add(final int index, final E object) {
71          decorated().add(index, object);
72      }
73  
74      public boolean addAll(final int index, final Collection<? extends E> coll) {
75          return decorated().addAll(index, coll);
76      }
77  
78      public E get(final int index) {
79          return decorated().get(index);
80      }
81  
82      public int indexOf(final Object object) {
83          return decorated().indexOf(object);
84      }
85  
86      public int lastIndexOf(final Object object) {
87          return decorated().lastIndexOf(object);
88      }
89  
90      public ListIterator<E> listIterator() {
91          return decorated().listIterator();
92      }
93  
94      public ListIterator<E> listIterator(final int index) {
95          return decorated().listIterator(index);
96      }
97  
98      public E remove(final int index) {
99          return decorated().remove(index);
100     }
101 
102     public E set(final int index, final E object) {
103         return decorated().set(index, object);
104     }
105 
106     public List<E> subList(final int fromIndex, final int toIndex) {
107         return decorated().subList(fromIndex, toIndex);
108     }
109 
110 }