Top Description Fields Constructors Methods
org.apache.commons.collections4.list

public abstract Class AbstractListDecorator<E>

extends AbstractCollectionDecorator<E>
implements List<E>
Class Inheritance
All Implemented Interfaces
java.util.List, java.util.SequencedCollection, java.util.Collection, java.lang.Iterable
Known Direct Subclasses
org.apache.commons.collections4.list.AbstractSerializableListDecorator
Type Parameters
<E>
the type of the elements in the list
Imports
java.util.Collection, .List, .ListIterator, org.apache.commons.collections4.collection.AbstractCollectionDecorator

Decorates another List to provide additional behaviour.

Methods are forwarded directly to the decorated list.

Since
3.0

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
protected
AbstractListDecorator()

Constructor only used in deserialization, do not use otherwise.

protected
AbstractListDecorator(final List<E>
the list to decorate, must not be null
list
)

Constructor that wraps (not copies).

Method Summary

Modifier and TypeMethod and Description
public void
add(final int
index at which the specified element is to be inserted
index
,
final E
element to be inserted
object
)

Implements java.util.List.add.

Inserts the specified element at the specified position in this list (optional operation).
public boolean
addAll(final int
index at which to insert the first element from the specified collection
index
,
final Collection<? extends E>
collection containing elements to be added to this list
coll
)

Implements java.util.List.addAll.

Inserts all of the elements in the specified collection into this list at the specified position (optional operation).
protected List<E>

Returns:

the decorated list
decorated
()

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.decorated.

Gets the list being decorated.
public boolean
equals(final Object
the object to be compared for equality with this list
object
)

Overrides java.lang.Object.equals.

Implements java.util.List.equals, java.util.Collection.equals.

Compares the specified object with this list for equality.
public E
get(final int
index of the element to return
index
)

Implements java.util.List.get.

Returns the element at the specified position in this list.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.List.hashCode, java.util.Collection.hashCode.

Returns the hash code value for this list.
public int
indexOf(final Object
element to search for
object
)

Implements java.util.List.indexOf.

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
public int
lastIndexOf(final Object
element to search for
object
)

Implements java.util.List.lastIndexOf.

Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.
public ListIterator<E>
listIterator()

Implements java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence).
public ListIterator<E>
listIterator(final int
index of the first element to be returned from the list iterator (by a call to next)
index
)

Implements java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list.
public E
remove(final int
the index of the element to be removed
index
)

Implements java.util.List.remove.

Removes the element at the specified position in this list (optional operation).
public E
set(final int
index of the element to replace
index
,
final E
element to be stored at the specified position
object
)

Implements java.util.List.set.

Replaces the element at the specified position in this list with the specified element (optional operation).
public List<E>
subList(final int
low endpoint (inclusive) of the subList
fromIndex
,
final int
high endpoint (exclusive) of the subList
toIndex
)

Implements java.util.List.subList.

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.
Inherited from org.apache.commons.collections4.collection.AbstractCollectionDecorator:
addaddAllclearcontainscontainsAllisEmptyiteratorremoveremoveAllremoveIfretainAllsetCollectionsizetoArraytoArraytoString

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.commons.collections4.collection.AbstractCollectionDecorator.serialVersionUID.

Serialization version--necessary in an abstract class?

Constructor Detail

AbstractListDecoratorback to summary
protected AbstractListDecorator()

Constructor only used in deserialization, do not use otherwise.

Since
3.1
AbstractListDecoratorback to summary
protected AbstractListDecorator(final List<E> list)

Constructor that wraps (not copies).

Parameters
list:List<E>

the list to decorate, must not be null

Exceptions
NullPointerException:
if list is null

Method Detail

addback to summary
public void add(final int index, final E object)

Implements java.util.List.add.

Doc from java.util.List.add.

Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

Parameters
index:int

index at which the specified element is to be inserted

object:E

element to be inserted

Annotations
@Override
addAllback to summary
public boolean addAll(final int index, final Collection<? extends E> coll)

Implements java.util.List.addAll.

Doc from java.util.List.addAll.

Inserts all of the elements in the specified collection into this list at the specified position (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in this list in the order that they are returned by the specified collection's iterator. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)

Parameters
index:int

index at which to insert the first element from the specified collection

coll:Collection<? extends E>

collection containing elements to be added to this list

Returns:boolean

true if this list changed as a result of the call

Annotations
@Override
decoratedback to summary
protected List<E> decorated()

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.decorated.

Gets the list being decorated.

Returns:List<E>

the decorated list

Annotations
@Override
equalsback to summary
public boolean equals(final Object object)

Overrides java.lang.Object.equals.

Implements java.util.List.equals, java.util.Collection.equals.

Doc from java.util.List.equals.

Compares the specified object with this list for equality. Returns true if and only if the specified object is also a list, both lists have the same size, and all corresponding pairs of elements in the two lists are equal. (Two elements e1 and e2 are equal if Objects.equals(e1, e2).) In other words, two lists are defined to be equal if they contain the same elements in the same order. This definition ensures that the equals method works properly across different implementations of the List interface.

Parameters
object:Object

the object to be compared for equality with this list

Returns:boolean

true if the specified object is equal to this list

Annotations
@Override
getback to summary
public E get(final int index)

Implements java.util.List.get.

Doc from java.util.List.get.

Returns the element at the specified position in this list.

Parameters
index:int

index of the element to return

Returns:E

the element at the specified position in this list

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.List.hashCode, java.util.Collection.hashCode.

Doc from java.util.List.hashCode.

Returns the hash code value for this list. The hash code of a list is defined to be the result of the following calculation:

int hashCode = 1;
    for (E e : list)
        hashCode = 31*hashCode + (e==null ? 0 : e.hashCode());
This ensures that list1.equals(list2) implies that list1.hashCode()==list2.hashCode() for any two lists, list1 and list2, as required by the general contract of Object#hashCode.
Returns:int

the hash code value for this list

Annotations
@Override
indexOfback to summary
public int indexOf(final Object object)

Implements java.util.List.indexOf.

Doc from java.util.List.indexOf.

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the lowest index i such that Objects.equals(o, get(i)), or -1 if there is no such index.

Parameters
object:Object

element to search for

Returns:int

the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element

Annotations
@Override
lastIndexOfback to summary
public int lastIndexOf(final Object object)

Implements java.util.List.lastIndexOf.

Doc from java.util.List.lastIndexOf.

Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the highest index i such that Objects.equals(o, get(i)), or -1 if there is no such index.

Parameters
object:Object

element to search for

Returns:int

the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element

Annotations
@Override
listIteratorback to summary
public ListIterator<E> listIterator()

Implements java.util.List.listIterator.

Doc from java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence).

Returns:ListIterator<E>

a list iterator over the elements in this list (in proper sequence)

Annotations
@Override
listIteratorback to summary
public ListIterator<E> listIterator(final int index)

Implements java.util.List.listIterator.

Doc from java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list. The specified index indicates the first element that would be returned by an initial call to next. An initial call to previous would return the element with the specified index minus one.

Parameters
index:int

index of the first element to be returned from the list iterator (by a call to next)

Returns:ListIterator<E>

a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list

Annotations
@Override
removeback to summary
public E remove(final int index)

Implements java.util.List.remove.

Doc from java.util.List.remove.

Removes the element at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.

Parameters
index:int

the index of the element to be removed

Returns:E

the element previously at the specified position

Annotations
@Override
setback to summary
public E set(final int index, final E object)

Implements java.util.List.set.

Doc from java.util.List.set.

Replaces the element at the specified position in this list with the specified element (optional operation).

Parameters
index:int

index of the element to replace

object:E

element to be stored at the specified position

Returns:E

the element previously at the specified position

Annotations
@Override
subListback to summary
public List<E> subList(final int fromIndex, final int toIndex)

Implements java.util.List.subList.

Doc from java.util.List.subList.

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are equal, the returned list is empty.) The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa. The returned list supports all of the optional list operations supported by this list.

This method eliminates the need for explicit range operations (of the sort that commonly exist for arrays). Any operation that expects a list can be used as a range operation by passing a subList view instead of a whole list. For example, the following idiom removes a range of elements from a list:

list.subList(from, to).clear();
Similar idioms may be constructed for indexOf and lastIndexOf, and all of the algorithms in the Collections class can be applied to a subList.

The semantics of the list returned by this method become undefined if the backing list (i.e., this list) is structurally modified in any way other than via the returned list. (Structural modifications are those that change the size of this list, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.)

Parameters
fromIndex:int

low endpoint (inclusive) of the subList

toIndex:int

high endpoint (exclusive) of the subList

Returns:List<E>

a view of the specified range within this list

Annotations
@Override