Class WrapperList<E>

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

public class WrapperList<E> extends Object implements List<E>, 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-safe Vector instance.
Author:
Jerome Louvel
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor.
    WrapperList(int initialCapacity)
    Constructor.
    WrapperList(List<E> delegate)
    Constructor.
  • Method Summary

    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, Collection<? extends E> elements)
    Inserts all of the elements in the specified collection into this list at the specified position.
    boolean
    addAll(Collection<? extends E> elements)
    Appends all of the elements in the specified collection to the end of this list.
    void
    Removes all of the elements from this list.
    boolean
    contains(Object element)
    Returns true if this list contains the specified element.
    boolean
    containsAll(Collection<?> elements)
    Returns true if this list contains all of the elements of the specified collection.
    boolean
    Compares the specified object with this list for equality.
    get(int index)
    Returns the element at the specified position in this list.
    protected List<E>
    Returns the delegate list.
    int
    Returns the hash code value for this list.
    int
    indexOf(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
    Returns true if this list contains no elements.
    Returns an iterator over the elements in this list in proper sequence.
    int
    Returns the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element.
    Returns a list iterator of the elements in this list (in proper sequence).
    listIterator(int index)
    Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list.
    remove(int index)
    Removes the element at the specified position in this list.
    boolean
    remove(Object element)
    Removes the first occurrence in this list of the specified element.
    boolean
    removeAll(Collection<?> elements)
    Removes from this list all the elements that are contained in the specified collection.
    boolean
    retainAll(Collection<?> elements)
    RemovesRetains only the elements in this list that are contained in the specified collection.
    set(int index, E element)
    Replaces the element at the specified position in this list with the specified element.
    int
    Returns the number of elements in this list.
    subList(int fromIndex, int toIndex)
    Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.
    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.
    Returns a string representation of the list.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.util.Collection

    parallelStream, removeIf, stream, toArray

    Methods inherited from interface java.lang.Iterable

    forEach

    Methods inherited from interface java.util.List

    replaceAll, sort, spliterator
  • Constructor Details

    • 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(List<E> delegate)
      Constructor.
      Parameters:
      delegate - The delegate list.
  • Method Details

    • add

      public boolean add(E element)
      Adds a element at the end of the list.
      Specified by:
      add in interface Collection<E>
      Specified by:
      add in interface 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 List<E>
      Parameters:
      index - The insertion position.
      element - The element to insert.
    • addAll

      public boolean addAll(Collection<? extends E> elements)
      Appends all of the elements in the specified collection to the end of this list.
      Specified by:
      addAll in interface Collection<E>
      Specified by:
      addAll in interface List<E>
      Parameters:
      elements - The collection of elements to append.
    • addAll

      public boolean addAll(int index, 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 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 Collection<E>
      Specified by:
      clear in interface List<E>
    • contains

      public boolean contains(Object element)
      Returns true if this list contains the specified element.
      Specified by:
      contains in interface Collection<E>
      Specified by:
      contains in interface List<E>
      Parameters:
      element - The element to find.
      Returns:
      True if this list contains the specified element.
    • containsAll

      public boolean containsAll(Collection<?> elements)
      Returns true if this list contains all of the elements of the specified collection.
      Specified by:
      containsAll in interface Collection<E>
      Specified by:
      containsAll in interface 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(Object o)
      Compares the specified object with this list for equality.
      Specified by:
      equals in interface Collection<E>
      Specified by:
      equals in interface List<E>
      Overrides:
      equals in class 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 List<E>
      Parameters:
      index - The element position.
      Returns:
      The element at the specified position in this list.
    • getDelegate

      protected 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 Collection<E>
      Specified by:
      hashCode in interface List<E>
      Overrides:
      hashCode in class Object
      Returns:
      The hash code value for this list.
    • indexOf

      public int indexOf(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 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 Collection<E>
      Specified by:
      isEmpty in interface List<E>
    • iterator

      public Iterator<E> iterator()
      Returns an iterator over the elements in this list in proper sequence.
      Specified by:
      iterator in interface Collection<E>
      Specified by:
      iterator in interface Iterable<E>
      Specified by:
      iterator in interface List<E>
      Returns:
      An iterator over the elements in this list in proper sequence.
    • lastIndexOf

      public int lastIndexOf(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 List<E>
    • listIterator

      public ListIterator<E> listIterator()
      Returns a list iterator of the elements in this list (in proper sequence).
      Specified by:
      listIterator in interface List<E>
      Returns:
      A list iterator of the elements in this list (in proper sequence).
    • listIterator

      public 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 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 List<E>
      Returns:
      The removed element.
    • remove

      public boolean remove(Object element)
      Removes the first occurrence in this list of the specified element.
      Specified by:
      remove in interface Collection<E>
      Specified by:
      remove in interface List<E>
      Returns:
      True if the list was changed.
    • removeAll

      public boolean removeAll(Collection<?> elements)
      Removes from this list all the elements that are contained in the specified collection.
      Specified by:
      removeAll in interface Collection<E>
      Specified by:
      removeAll in interface List<E>
      Parameters:
      elements - The collection of element to remove.
      Returns:
      True if the list changed.
    • retainAll

      public boolean retainAll(Collection<?> elements)
      RemovesRetains only the elements in this list that are contained in the specified collection.
      Specified by:
      retainAll in interface Collection<E>
      Specified by:
      retainAll in interface 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 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 Collection<E>
      Specified by:
      size in interface List<E>
      Returns:
      The number of elements in this list.
    • subList

      public 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 List<E>
      Parameters:
      fromIndex - The start position.
      toIndex - The end position (exclusive).
      Returns:
      The sub-list.
    • toArray

      public Object[] toArray()
      Returns an array containing all of the elements in this list in proper sequence.
      Specified by:
      toArray in interface Collection<E>
      Specified by:
      toArray in interface 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 Collection<E>
      Specified by:
      toArray in interface List<E>
      Parameters:
      a - The sample array.
    • toString

      public String toString()
      Returns a string representation of the list.
      Overrides:
      toString in class Object
      Returns:
      A string representation of the list.