org.restlet.util
Class WrapperList<E>

java.lang.Object
  extended by org.restlet.util.WrapperList<E>
All Implemented Interfaces:
java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>
Direct Known Subclasses:
ClientList, ReferenceList, RouteList, Series, ServerList

public class WrapperList<E>
extends java.lang.Object
implements java.util.List<E>

List wrapper. Modifiable list that delegates all methods to a wrapped list. This allows an easy subclassing. By default, it wraps a thread-safe Vector instance.

Author:
Jerome Louvel
See Also:
Collections, List

Constructor Summary
WrapperList()
          Constructor.
WrapperList(int initialCapacity)
          Constructor.
WrapperList(java.util.List<E> delegate)
          Constructor.
 
Method Summary
 boolean add(E element)
          Adds a element at the end of the list.
 void add(int index, E element)
          Inserts the specified element at the specified position in this list.
 boolean addAll(java.util.Collection<? extends E> elements)
          Appends all of the elements in the specified collection to the end of this list.
 boolean addAll(int index, java.util.Collection<? extends E> elements)
          Inserts all of the elements in the specified collection into this list at the specified position.
 void clear()
          Removes all of the elements from this list.
 boolean contains(java.lang.Object element)
          Returns true if this list contains the specified element.
 boolean containsAll(java.util.Collection<?> elements)
          Returns true if this list contains all of the elements of the specified collection.
 boolean equals(java.lang.Object o)
          Compares the specified object with this list for equality.
 E get(int index)
          Returns the element at the specified position in this list.
protected  java.util.List<E> getDelegate()
          Returns the delegate list.
 int hashCode()
          Returns the hash code value for this list.
 int indexOf(java.lang.Object element)
          Returns the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element.
 boolean isEmpty()
          Returns true if this list contains no elements.
 java.util.Iterator<E> iterator()
          Returns an iterator over the elements in this list in proper sequence.
 int lastIndexOf(java.lang.Object element)
          Returns the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element.
 java.util.ListIterator<E> listIterator()
          Returns a list iterator of the elements in this list (in proper sequence).
 java.util.ListIterator<E> listIterator(int index)
          Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list.
 E remove(int index)
          Removes the element at the specified position in this list.
 boolean remove(java.lang.Object element)
          Removes the first occurrence in this list of the specified element.
 boolean removeAll(java.util.Collection<?> elements)
          Removes from this list all the elements that are contained in the specified collection.
 boolean retainAll(java.util.Collection<?> elements)
          RemovesRetains only the elements in this list that are contained in the specified collection.
 E set(int index, E element)
          Replaces the element at the specified position in this list with the specified element.
 int size()
          Returns the number of elements in this list.
 java.util.List<E> subList(int fromIndex, int toIndex)
          Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.
 java.lang.Object[] toArray()
          Returns an array containing all of the elements in this list in proper sequence.
<T> T[]
toArray(T[] a)
          Returns an array containing all of the elements in this list in proper sequence; the runtime type of the returned array is that of the specified array.
 java.lang.String toString()
          Returns a string representation of the list.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WrapperList

public WrapperList()
Constructor. Uses a default initial capacity of 10 items.


WrapperList

public WrapperList(int initialCapacity)
Constructor.

Parameters:
initialCapacity - The initial list capacity.

WrapperList

public WrapperList(java.util.List<E> delegate)
Constructor.

Parameters:
delegate - The delegate list.
Method Detail

add

public boolean add(E element)
Adds a element at the end of the list.

Specified by:
add in interface java.util.Collection<E>
Specified by:
add in interface java.util.List<E>
Returns:
True (as per the general contract of the Collection.add method).

add

public void add(int index,
                E element)
Inserts the specified element at the specified position in this list.

Specified by:
add in interface java.util.List<E>
Parameters:
index - The insertion position.
element - The element to insert.

addAll

public boolean addAll(java.util.Collection<? extends E> elements)
Appends all of the elements in the specified collection to the end of this list.

Specified by:
addAll in interface java.util.Collection<E>
Specified by:
addAll in interface java.util.List<E>
Parameters:
elements - The collection of elements to append.

addAll

public boolean addAll(int index,
                      java.util.Collection<? extends E> elements)
Inserts all of the elements in the specified collection into this list at the specified position.

Specified by:
addAll in interface java.util.List<E>
Parameters:
index - The insertion position.
elements - The collection of elements to insert.

clear

public void clear()
Removes all of the elements from this list.

Specified by:
clear in interface java.util.Collection<E>
Specified by:
clear in interface java.util.List<E>

contains

public boolean contains(java.lang.Object element)
Returns true if this list contains the specified element.

Specified by:
contains in interface java.util.Collection<E>
Specified by:
contains in interface java.util.List<E>
Parameters:
element - The element to find.
Returns:
True if this list contains the specified element.

containsAll

public boolean containsAll(java.util.Collection<?> elements)
Returns true if this list contains all of the elements of the specified collection.

Specified by:
containsAll in interface java.util.Collection<E>
Specified by:
containsAll in interface java.util.List<E>
Parameters:
elements - The collection of elements to find.
Returns:
True if this list contains all of the elements of the specified collection.

equals

public boolean equals(java.lang.Object o)
Compares the specified object with this list for equality.

Specified by:
equals in interface java.util.Collection<E>
Specified by:
equals in interface java.util.List<E>
Overrides:
equals in class java.lang.Object
Parameters:
o - The object to be compared for equality with this list.
Returns:
True if the specified object is equal to this list.

get

public E get(int index)
Returns the element at the specified position in this list.

Specified by:
get in interface java.util.List<E>
Parameters:
index - The element position.
Returns:
The element at the specified position in this list.

getDelegate

protected java.util.List<E> getDelegate()
Returns the delegate list.

Returns:
The delegate list.

hashCode

public int hashCode()
Returns the hash code value for this list.

Specified by:
hashCode in interface java.util.Collection<E>
Specified by:
hashCode in interface java.util.List<E>
Overrides:
hashCode in class java.lang.Object
Returns:
The hash code value for this list.

indexOf

public int indexOf(java.lang.Object element)
Returns the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element.

Specified by:
indexOf in interface java.util.List<E>
Parameters:
element - The element to find.
Returns:
The index of the first occurrence.

isEmpty

public boolean isEmpty()
Returns true if this list contains no elements.

Specified by:
isEmpty in interface java.util.Collection<E>
Specified by:
isEmpty in interface java.util.List<E>

iterator

public java.util.Iterator<E> iterator()
Returns an iterator over the elements in this list in proper sequence.

Specified by:
iterator in interface java.lang.Iterable<E>
Specified by:
iterator in interface java.util.Collection<E>
Specified by:
iterator in interface java.util.List<E>
Returns:
An iterator over the elements in this list in proper sequence.

lastIndexOf

public int lastIndexOf(java.lang.Object element)
Returns the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element.

Specified by:
lastIndexOf in interface java.util.List<E>

listIterator

public java.util.ListIterator<E> listIterator()
Returns a list iterator of the elements in this list (in proper sequence).

Specified by:
listIterator in interface java.util.List<E>
Returns:
A list iterator of the elements in this list (in proper sequence).

listIterator

public java.util.ListIterator<E> listIterator(int index)
Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list.

Specified by:
listIterator in interface java.util.List<E>
Parameters:
index - The starting position.

remove

public E remove(int index)
Removes the element at the specified position in this list.

Specified by:
remove in interface java.util.List<E>
Returns:
The removed element.

remove

public boolean remove(java.lang.Object element)
Removes the first occurrence in this list of the specified element.

Specified by:
remove in interface java.util.Collection<E>
Specified by:
remove in interface java.util.List<E>
Returns:
True if the list was changed.

removeAll

public boolean removeAll(java.util.Collection<?> elements)
Removes from this list all the elements that are contained in the specified collection.

Specified by:
removeAll in interface java.util.Collection<E>
Specified by:
removeAll in interface java.util.List<E>
Parameters:
elements - The collection of element to remove.
Returns:
True if the list changed.

retainAll

public boolean retainAll(java.util.Collection<?> elements)
RemovesRetains only the elements in this list that are contained in the specified collection.

Specified by:
retainAll in interface java.util.Collection<E>
Specified by:
retainAll in interface java.util.List<E>
Parameters:
elements - The collection of element to retain.
Returns:
True if the list changed.

set

public E set(int index,
             E element)
Replaces the element at the specified position in this list with the specified element.

Specified by:
set in interface java.util.List<E>
Parameters:
index - The position of the element to replace.
element - The new element.

size

public int size()
Returns the number of elements in this list.

Specified by:
size in interface java.util.Collection<E>
Specified by:
size in interface java.util.List<E>
Returns:
The number of elements in this list.

subList

public java.util.List<E> subList(int fromIndex,
                                 int toIndex)
Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.

Specified by:
subList in interface java.util.List<E>
Parameters:
fromIndex - The start position.
toIndex - The end position (exclusive).
Returns:
The sub-list.

toArray

public java.lang.Object[] toArray()
Returns an array containing all of the elements in this list in proper sequence.

Specified by:
toArray in interface java.util.Collection<E>
Specified by:
toArray in interface java.util.List<E>
Returns:
An array containing all of the elements in this list in proper sequence.

toArray

public <T> T[] toArray(T[] a)
Returns an array containing all of the elements in this list in proper sequence; the runtime type of the returned array is that of the specified array.

Specified by:
toArray in interface java.util.Collection<E>
Specified by:
toArray in interface java.util.List<E>
Parameters:
a - The sample array.

toString

public java.lang.String toString()
Returns a string representation of the list.

Overrides:
toString in class java.lang.Object
Returns:
A string representation of the list.


Copyright © 2005-2008 Noelios Technologies.