Package org.restlet.util
Class WrapperList<E>
- java.lang.Object
-
- 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
,ServiceList
public class WrapperList<E> extends java.lang.Object implements java.util.List<E>, java.lang.Iterable<E>
List wrapper. Modifiable list that delegates all methods to a wrapped list. This allows an easy sub-classing. By default, it wraps a thread-safeVector
instance.- Author:
- Jerome Louvel
- See Also:
- The decorator (aka wrapper) pattern,
Collections
,List
-
-
Constructor Summary
Constructors Constructor Description WrapperList()
Constructor.WrapperList(int initialCapacity)
Constructor.WrapperList(java.util.List<E> delegate)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, E element)
Inserts the specified element at the specified position in this list.boolean
add(E element)
Adds a element at the end of the 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.boolean
addAll(java.util.Collection<? extends E> elements)
Appends all of the elements in the specified collection to the end of this list.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.
-
-
-
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.
-
add
public void add(int index, E element)
Inserts the specified element at the specified position in this list.- Specified by:
add
in interfacejava.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.
-
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 interfacejava.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.
-
contains
public boolean contains(java.lang.Object element)
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.
-
equals
public boolean equals(java.lang.Object o)
Compares the specified object with this list for equality.
-
get
public E get(int index)
Returns the element at the specified position in this list.- Specified by:
get
in interfacejava.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.
-
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 interfacejava.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.
-
iterator
public java.util.Iterator<E> iterator()
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 interfacejava.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 interfacejava.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 interfacejava.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 interfacejava.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.
-
removeAll
public boolean removeAll(java.util.Collection<?> elements)
Removes from this list all the elements that are contained in the specified collection.
-
retainAll
public boolean retainAll(java.util.Collection<?> elements)
RemovesRetains only the elements in this list that are contained in the specified collection.
-
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 interfacejava.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.
-
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 interfacejava.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.
-
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.
-
toString
public java.lang.String toString()
Returns a string representation of the list.- Overrides:
toString
in classjava.lang.Object
- Returns:
- A string representation of the list.
-
-