de.upb.hni.vmagic.util
Class ForwardingList<E>

java.lang.Object
  extended by de.upb.hni.vmagic.util.ForwardingList<E>
Type Parameters:
E - the type of the list elements
All Implemented Interfaces:
java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>
Direct Known Subclasses:
ParentSetList

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

Forwarding implementation of the List interface. This class is used to easily implement lists which delegate most of its functions to another list and only change some functions.


Constructor Summary
ForwardingList(java.util.List<E> list)
          Creates a forwarding list.
 
Method Summary
 boolean add(E e)
          Adds an element to this list.
 void add(int index, E element)
          Adds an element to a specific position in this list.
 boolean addAll(java.util.Collection<? extends E> c)
          Adds all elements of a collection to this list.
 boolean addAll(int index, java.util.Collection<? extends E> c)
          Adds all elements of a collection to a specific index in this list.
 void clear()
          Clears this list.
 boolean contains(java.lang.Object o)
          Returns if this list contains the given object.
 boolean containsAll(java.util.Collection<?> c)
          Returns if this list contains all elements of thie given collection.
 E get(int index)
          Returns the element at the given index.
 int indexOf(java.lang.Object o)
          Returns the index of the fist occurence of an object.
 boolean isEmpty()
          Returns if this list is empty.
 java.util.Iterator<E> iterator()
          Returns an iterator for this list.
 int lastIndexOf(java.lang.Object o)
          Return the index of the last occurence of an object.
 java.util.ListIterator<E> listIterator()
          Returns a list iterator for this list.
 java.util.ListIterator<E> listIterator(int index)
          Returns a list iterator with a start index.
 E remove(int index)
          Removes the element at a given index.
 boolean remove(java.lang.Object o)
          Removes an object from this list.
 boolean removeAll(java.util.Collection<?> c)
          Removes all elements in a collection from this list.
 boolean retainAll(java.util.Collection<?> c)
          Removes all elements that are not in the given collection from this list.
 E set(int index, E element)
          Sets the element at the given index.
 int size()
          Returns the size of this list.
 java.util.List<E> subList(int fromIndex, int toIndex)
          Returns a sub list of this list.
 java.lang.Object[] toArray()
          Converts this list to an array.
<T> T[]
toArray(T[] a)
          Converts this list to an array with a specific type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.List
equals, hashCode
 

Constructor Detail

ForwardingList

public ForwardingList(java.util.List<E> list)
Creates a forwarding list.

Parameters:
list - the list
Method Detail

size

public int size()
Returns the size of this list.

Specified by:
size in interface java.util.Collection<E>
Specified by:
size in interface java.util.List<E>
Returns:
the size

isEmpty

public boolean isEmpty()
Returns if this list is empty.

Specified by:
isEmpty in interface java.util.Collection<E>
Specified by:
isEmpty in interface java.util.List<E>
Returns:
true, if the list is empty

contains

public boolean contains(java.lang.Object o)
Returns if this list contains the given object.

Specified by:
contains in interface java.util.Collection<E>
Specified by:
contains in interface java.util.List<E>
Parameters:
o - the object
Returns:
true, if the list contains the give object

iterator

public java.util.Iterator<E> iterator()
Returns an iterator for this list.

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:
the iterator

toArray

public java.lang.Object[] toArray()
Converts this list to an array.

Specified by:
toArray in interface java.util.Collection<E>
Specified by:
toArray in interface java.util.List<E>
Returns:
the array

toArray

public <T> T[] toArray(T[] a)
Converts this list to an array with a specific type.

Specified by:
toArray in interface java.util.Collection<E>
Specified by:
toArray in interface java.util.List<E>
Type Parameters:
T - the type
Parameters:
a - the array
Returns:
the array

add

public boolean add(E e)
Adds an element to this list.

Specified by:
add in interface java.util.Collection<E>
Specified by:
add in interface java.util.List<E>
Parameters:
e - the element
Returns:
true

remove

public boolean remove(java.lang.Object o)
Removes an object from this list.

Specified by:
remove in interface java.util.Collection<E>
Specified by:
remove in interface java.util.List<E>
Parameters:
o - the object
Returns:
true, if the object was removed

containsAll

public boolean containsAll(java.util.Collection<?> c)
Returns if this list contains all elements of thie given collection.

Specified by:
containsAll in interface java.util.Collection<E>
Specified by:
containsAll in interface java.util.List<E>
Parameters:
c - the collection
Returns:
true, if the list contains all elements

addAll

public boolean addAll(java.util.Collection<? extends E> c)
Adds all elements of a collection to this list.

Specified by:
addAll in interface java.util.Collection<E>
Specified by:
addAll in interface java.util.List<E>
Parameters:
c - the collection
Returns:
true, if this list was changed

addAll

public boolean addAll(int index,
                      java.util.Collection<? extends E> c)
Adds all elements of a collection to a specific index in this list.

Specified by:
addAll in interface java.util.List<E>
Parameters:
index - the index
c - the collection
Returns:
true, if this list was changed

removeAll

public boolean removeAll(java.util.Collection<?> c)
Removes all elements in a collection from this list.

Specified by:
removeAll in interface java.util.Collection<E>
Specified by:
removeAll in interface java.util.List<E>
Parameters:
c - the collection
Returns:
true, if this list was changed

retainAll

public boolean retainAll(java.util.Collection<?> c)
Removes all elements that are not in the given collection from this list.

Specified by:
retainAll in interface java.util.Collection<E>
Specified by:
retainAll in interface java.util.List<E>
Parameters:
c - the collection
Returns:
true, if this list was changed

clear

public void clear()
Clears this list.

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

get

public E get(int index)
Returns the element at the given index.

Specified by:
get in interface java.util.List<E>
Parameters:
index - the index
Returns:
the element

set

public E set(int index,
             E element)
Sets the element at the given index.

Specified by:
set in interface java.util.List<E>
Parameters:
index - the index
element - the new element
Returns:
the old element

add

public void add(int index,
                E element)
Adds an element to a specific position in this list.

Specified by:
add in interface java.util.List<E>
Parameters:
index - the index
element - the element

remove

public E remove(int index)
Removes the element at a given index.

Specified by:
remove in interface java.util.List<E>
Parameters:
index - the index
Returns:
the removed element

indexOf

public int indexOf(java.lang.Object o)
Returns the index of the fist occurence of an object.

Specified by:
indexOf in interface java.util.List<E>
Parameters:
o - the object
Returns:
the index or -1 if the object is not in the list

lastIndexOf

public int lastIndexOf(java.lang.Object o)
Return the index of the last occurence of an object.

Specified by:
lastIndexOf in interface java.util.List<E>
Parameters:
o - the object
Returns:
the index or -1 if the object is not in the list

listIterator

public java.util.ListIterator<E> listIterator()
Returns a list iterator for this list.

Specified by:
listIterator in interface java.util.List<E>
Returns:
the list iterator

listIterator

public java.util.ListIterator<E> listIterator(int index)
Returns a list iterator with a start index.

Specified by:
listIterator in interface java.util.List<E>
Parameters:
index - the index
Returns:
the list iterator

subList

public java.util.List<E> subList(int fromIndex,
                                 int toIndex)
Returns a sub list of this list.

Specified by:
subList in interface java.util.List<E>
Parameters:
fromIndex - the first index
toIndex - the last index
Returns:
the sub list