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> 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 } 045 046 /** 047 * Constructor that wraps (not copies). 048 * 049 * @param list the list to decorate, must not be null 050 * @throws NullPointerException if list is null 051 */ 052 protected AbstractListDecorator(final List<E> list) { 053 super(list); 054 } 055 056 @Override 057 public void add(final int index, final E object) { 058 decorated().add(index, object); 059 } 060 061 @Override 062 public boolean addAll(final int index, final Collection<? extends E> coll) { 063 return decorated().addAll(index, coll); 064 } 065 066 /** 067 * Gets the list being decorated. 068 * 069 * @return the decorated list 070 */ 071 @Override 072 protected List<E> decorated() { 073 return (List<E>) super.decorated(); 074 } 075 076 @Override 077 public boolean equals(final Object object) { 078 return object == this || decorated().equals(object); 079 } 080 081 @Override 082 public E get(final int index) { 083 return decorated().get(index); 084 } 085 086 @Override 087 public int hashCode() { 088 return decorated().hashCode(); 089 } 090 091 @Override 092 public int indexOf(final Object object) { 093 return decorated().indexOf(object); 094 } 095 096 @Override 097 public int lastIndexOf(final Object object) { 098 return decorated().lastIndexOf(object); 099 } 100 101 @Override 102 public ListIterator<E> listIterator() { 103 return decorated().listIterator(); 104 } 105 106 @Override 107 public ListIterator<E> listIterator(final int index) { 108 return decorated().listIterator(index); 109 } 110 111 @Override 112 public E remove(final int index) { 113 return decorated().remove(index); 114 } 115 116 @Override 117 public E set(final int index, final E object) { 118 return decorated().set(index, object); 119 } 120 121 @Override 122 public List<E> subList(final int fromIndex, final int toIndex) { 123 return decorated().subList(fromIndex, toIndex); 124 } 125 126}