001    /*
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    package org.apache.commons.collections.list;
018    
019    import java.util.Collection;
020    import java.util.List;
021    import java.util.ListIterator;
022    
023    import org.apache.commons.collections.collection.AbstractCollectionDecorator;
024    
025    /**
026     * Decorates another <code>List</code> to provide additional behaviour.
027     * <p>
028     * Methods are forwarded directly to the decorated list.
029     *
030     * @since Commons Collections 3.0
031     * @version $Revision: 646777 $ $Date: 2008-04-10 13:33:15 +0100 (Thu, 10 Apr 2008) $
032     * 
033     * @author Stephen Colebourne
034     */
035    public abstract class AbstractListDecorator extends AbstractCollectionDecorator implements List {
036    
037        /**
038         * Constructor only used in deserialization, do not use otherwise.
039         * @since Commons Collections 3.1
040         */
041        protected AbstractListDecorator() {
042            super();
043        }
044    
045        /**
046         * Constructor that wraps (not copies).
047         * 
048         * @param list  the list to decorate, must not be null
049         * @throws IllegalArgumentException if list is null
050         */
051        protected AbstractListDecorator(List list) {
052            super(list);
053        }
054    
055        /**
056         * Gets the list being decorated.
057         * 
058         * @return the decorated list
059         */
060        protected List getList() {
061            return (List) getCollection();
062        }
063    
064        //-----------------------------------------------------------------------
065        public void add(int index, Object object) {
066            getList().add(index, object);
067        }
068    
069        public boolean addAll(int index, Collection coll) {
070            return getList().addAll(index, coll);
071        }
072    
073        public Object get(int index) {
074            return getList().get(index);
075        }
076    
077        public int indexOf(Object object) {
078            return getList().indexOf(object);
079        }
080    
081        public int lastIndexOf(Object object) {
082            return getList().lastIndexOf(object);
083        }
084    
085        public ListIterator listIterator() {
086            return getList().listIterator();
087        }
088    
089        public ListIterator listIterator(int index) {
090            return getList().listIterator(index);
091        }
092    
093        public Object remove(int index) {
094            return getList().remove(index);
095        }
096    
097        public Object set(int index, Object object) {
098            return getList().set(index, object);
099        }
100    
101        public List subList(int fromIndex, int toIndex) {
102            return getList().subList(fromIndex, toIndex);
103        }
104    
105    }