E
- the type of elements in the decorated (and this) listpublic abstract class ListDecorator<E> extends java.lang.Object implements java.util.List<E>
List
can be inherited from this class.
In addition to the delegation of all methods to the underlying list this class provides the empty methods
afterAdd(int, Collection)
, afterReplace(int, Object, Object)
and afterRemove(int, Collection)
that can be overwritten by inherited classes to react to modifications of the underlying list. They are called from
all according methods that modify the contents of this list, including these of related objects like iterators of sublists.
Constructor and Description |
---|
ListDecorator(java.util.List<E> underlyingList)
Creates a new instance of this class.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E element) |
void |
add(int index,
E element) |
boolean |
addAll(java.util.Collection<? extends E> c) |
boolean |
addAll(int index,
java.util.Collection<? extends E> c) |
protected void |
afterAdd(int index,
java.util.Collection<? extends E> addElements)
This method is called at the end of all methods of this list that add elements to it, including
methods called on the results of
or iterators . |
protected void |
afterRemove(int index,
java.util.Collection<? extends E> removedElements)
This method is called at the end of all methods of this list that remove elements from it, including
methods called on the results of
subList(int, int) or iterators. |
protected void |
afterReplace(int index,
E previousElement,
E currentElement)
This method is called at the end of
set(int, Object) to indicate that an element has been
replaced. |
protected void |
beforeAdd(int index,
java.util.Collection<? extends E> addElements)
This method is called at the beginning of all methods of this list that add elements to it (including
methods called on the results of
subList(int, int) or iterators) before the actual inserting
happens. |
protected void |
beforeRemove(int index,
java.util.Collection<java.lang.Object> removedElements)
This method is called at the beginning of all methods of this list that remove elements from it (including
methods called on the results of
subList(int, int) or iterators) before the actual deletion
happens. |
protected void |
beforeReplace(int index,
E currentElement,
E newElement)
This method is called at the beginning of
set(int, Object) to indicate that an element will be
replaced. |
void |
clear() |
boolean |
contains(java.lang.Object element) |
boolean |
containsAll(java.util.Collection<?> c) |
protected java.util.ListIterator<E> |
createDecoratedListIterator(java.util.ListIterator<E> iterator) |
boolean |
equals(java.lang.Object o) |
E |
get(int index) |
protected java.util.List<E> |
getUnderlyingList()
Returns the list that is decorated by this instance.
|
int |
hashCode() |
int |
indexOf(java.lang.Object o) |
boolean |
isEmpty() |
java.util.Iterator<E> |
iterator() |
int |
lastIndexOf(java.lang.Object o) |
java.util.ListIterator<E> |
listIterator() |
java.util.ListIterator<E> |
listIterator(int index) |
E |
remove(int index) |
boolean |
remove(java.lang.Object o) |
boolean |
removeAll(java.util.Collection<?> c) |
boolean |
retainAll(java.util.Collection<?> c) |
E |
set(int index,
E element) |
int |
size() |
java.util.List<E> |
subList(int fromIndex,
int toIndex) |
java.lang.Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
public ListDecorator(java.util.List<E> underlyingList)
underlyingList
- the list to be decoratedprotected java.util.List<E> getUnderlyingList()
protected void beforeAdd(int index, java.util.Collection<? extends E> addElements)
subList(int, int)
or iterators) before the actual inserting
happens. This default implementation is empty and can be overwritten by inherited classes which want
to track modifications of the list.
If more than one element will be add in one operation (e.g. addAll(Collection)
) this method
is only called once before the first elements is inserted.
index
- the index where the first new element will be insertedaddElements
- the elements that shall be add (Always contains at least one element.)protected void afterAdd(int index, java.util.Collection<? extends E> addElements)
or iterators
. This default implementation
is empty and can be overwritten by inherited classes which want to track modifications of the list.
If more than one element is add in one operation (e.g. addAll(Collection)
) this method
is only called once when all elements have been inserted.
Note that this method is not called if an add operation is not successful. In such a case only
beforeAdd(int, Collection)
is called.
index
- the index where the first new element has been insertedaddElements
- the elements that have been add (Always contains at least one element.)protected void beforeReplace(int index, E currentElement, E newElement)
set(int, Object)
to indicate that an element will be
replaced. This default implementation is empty and can be overwritten by inherited classes which want
to track modifications of the list.index
- the index where the element will be replacedcurrentElement
- the element that will be replacednewElement
- the new element that shall replace the current oneprotected void afterReplace(int index, E previousElement, E currentElement)
set(int, Object)
to indicate that an element has been
replaced. This default implementation is empty and can be overwritten by inherited classes which want
to track modifications of the list.index
- the index where the element has been replacedpreviousElement
- the element that was replacedcurrentElement
- the new element that is now contained in the listprotected void beforeRemove(int index, java.util.Collection<java.lang.Object> removedElements)
subList(int, int)
or iterators) before the actual deletion
happens. This default implementation is empty and can be overwritten by inherited classes which want to
track modifications of the list.
If more than one element will be removed in one operation (e.g. retainAll(Collection)
) this method
is only called once before the first element is removed.
removedElements
- the elements that have been removed.protected void afterRemove(int index, java.util.Collection<? extends E> removedElements)
subList(int, int)
or iterators. This default implementation
is empty and can be overwritten by inherited classes which want to track modifications of the list.
If more than one element is removed in one operation (e.g. retainAll(Collection)
) this method
is only called once when all elements have been removed.
Note that this method is not called if an add operation is not successful. In such a case only
#beforeRemove(Collection)
is called.
removedElements
- the elements that have been removed.protected java.util.ListIterator<E> createDecoratedListIterator(java.util.ListIterator<E> iterator)
public boolean addAll(int index, java.util.Collection<? extends E> c)
addAll
in interface java.util.List<E>
public void clear()
public boolean contains(java.lang.Object element)
public boolean containsAll(java.util.Collection<?> c)
public boolean equals(java.lang.Object o)
public int hashCode()
public boolean isEmpty()
public int lastIndexOf(java.lang.Object o)
lastIndexOf
in interface java.util.List<E>
public java.util.ListIterator<E> listIterator()
listIterator
in interface java.util.List<E>
public java.util.ListIterator<E> listIterator(int index)
listIterator
in interface java.util.List<E>
public boolean remove(java.lang.Object o)
public boolean removeAll(java.util.Collection<?> c)
public boolean retainAll(java.util.Collection<?> c)
public int size()
public java.util.List<E> subList(int fromIndex, int toIndex)
subList
in interface java.util.List<E>
public java.lang.Object[] toArray()