    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 behaviour.
    027 * <p>
    028 * Methods are forwarded directly to the decorated list.
    029 *
    030 * @param <E> the type of the elements in the list
    031 * @since 3.0
    032 */
    033public abstract class AbstractListDecorator<E> extends AbstractCollectionDecorator<E>
    034        implements List<E> {
    035
    036    /** Serialization version--necessary in an abstract class? */
    037    private static final long serialVersionUID = 4500739654952315623L;
    038
    039    /**
    040     * Constructor only used in deserialization, do not use otherwise.
    041     * @since 3.1
    042     */
    043    protected AbstractListDecorator() {
    044        super();
    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    /**
    058     * Gets the list being decorated.
    059     *
    060     * @return the decorated list
    061     */
    062    @Override
    063    protected List<E> decorated() {
    064        return (List<E>) super.decorated();
    065    }
    066
    067    @Override
    068    public boolean equals(final Object object) {
    069        return object == this || decorated().equals(object);
    070    }
    071
    072    @Override
    073    public int hashCode() {
    074        return decorated().hashCode();
    075    }
    076
    077    //-----------------------------------------------------------------------
    078
    079    @Override
    080    public void add(final int index, final E object) {
    081        decorated().add(index, object);
    082    }
    083
    084    @Override
    085    public boolean addAll(final int index, final Collection<? extends E> coll) {
    086        return decorated().addAll(index, coll);
    087    }
    088
    089    @Override
    090    public E get(final int index) {
    091        return decorated().get(index);
    092    }
    093
    094    @Override
    095    public int indexOf(final Object object) {
    096        return decorated().indexOf(object);
    097    }
    098
    099    @Override
    100    public int lastIndexOf(final Object object) {
    101        return decorated().lastIndexOf(object);
    102    }
    103
    104    @Override
    105    public ListIterator<E> listIterator() {
    106        return decorated().listIterator();
    107    }
    108
    109    @Override
    110    public ListIterator<E> listIterator(final int index) {
    111        return decorated().listIterator(index);
    112    }
    113
    114    @Override
    115    public E remove(final int index) {
    116        return decorated().remove(index);
    117    }
    118
    119    @Override
    120    public E set(final int index, final E object) {
    121        return decorated().set(index, object);
    122    }
    123
    124    @Override
    125    public List<E> subList(final int fromIndex, final int toIndex) {
    126        return decorated().subList(fromIndex, toIndex);
    127    }
    128
    129}