    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 */
    017package org.apache.commons.collections4.list;
    018
    019import java.util.Collection;
    020import java.util.List;
    021import java.util.ListIterator;
    022
    023import org.apache.commons.collections4.collection.AbstractCollectionDecorator;
    024
    025/**
    026 * Decorates another {@link List} to provide additional behavior.
    027 * <p>
    028 * Methods are forwarded directly to the decorated list.
    029 * </p>
    030 *
    031 * @param <E> the type of the elements in the list
    032 * @since 3.0
    033 */
    034public abstract class AbstractListDecorator<E> extends AbstractCollectionDecorator<E>
    035        implements List<E> {
    036
    037    /** Serialization version--necessary in an abstract class? */
    038    private static final long serialVersionUID = 4500739654952315623L;
    039
    040    /**
    041     * Constructor only used in deserialization, do not use otherwise.
    042     * @since 3.1
    043     */
    044    protected AbstractListDecorator() {
    045    }
    046
    047    /**
    048     * Constructor that wraps (not copies).
    049     *
    050     * @param list  the list to decorate, must not be null
    051     * @throws NullPointerException if list is null
    052     */
    053    protected AbstractListDecorator(final List<E> list) {
    054        super(list);
    055    }
    056
    057    @Override
    058    public void add(final int index, final E object) {
    059        decorated().add(index, object);
    060    }
    061
    062    @Override
    063    public boolean addAll(final int index, final Collection<? extends E> coll) {
    064        return decorated().addAll(index, coll);
    065    }
    066
    067    /**
    068     * Gets the list being decorated.
    069     *
    070     * @return the decorated list
    071     */
    072    @Override
    073    protected List<E> decorated() {
    074        return (List<E>) super.decorated();
    075    }
    076
    077    @Override
    078    public boolean equals(final Object object) {
    079        return object == this || decorated().equals(object);
    080    }
    081
    082    @Override
    083    public E get(final int index) {
    084        return decorated().get(index);
    085    }
    086
    087    @Override
    088    public int hashCode() {
    089        return decorated().hashCode();
    090    }
    091
    092    @Override
    093    public int indexOf(final Object object) {
    094        return decorated().indexOf(object);
    095    }
    096
    097    @Override
    098    public int lastIndexOf(final Object object) {
    099        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}