de.cau.cs.kieler.core.util
Class ConcatenableList<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.AbstractSequentialList<E>
              extended by de.cau.cs.kieler.core.util.ConcatenableList<E>
Type Parameters:
E - type of contained objects
All Implemented Interfaces:
Iterable<E>, Collection<E>, List<E>

public class ConcatenableList<E>
extends AbstractSequentialList<E>

Implementation of doubly linked list that permits concatenation of two lists.

Rating proposed yellow
(2009-12-11) msp

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
ConcatenableList()
          Constructs an empty list.
 
Method Summary
 boolean add(E e)
          
 boolean addAll(Collection<? extends E> c)
          Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator.
 boolean addAll(int index, Collection<? extends E> c)
          Inserts all of the elements in the specified collection into this list, starting at the specified position.
 void addFirst(E e)
          Inserts the specified element at the beginning of this list.
 void addLast(E e)
          Appends the specified element to the end of this list.
 void concatenate(ConcatenableList<E> other)
          Concatenates the receiver with the given list.
 E getFirst()
          Returns the first element in this list.
 E getLast()
          Returns the last element in this list.
 ListIterator<E> listIterator(int index)
          
 E removeFirst()
          Removes and returns the first element from this list.
 E removeLast()
          Removes and returns the last element from this list.
 int size()
          
 
Methods inherited from class java.util.AbstractSequentialList
add, get, iterator, remove, set
 
Methods inherited from class java.util.AbstractList
clear, equals, hashCode, indexOf, lastIndexOf, listIterator, removeRange, subList
 
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Constructor Detail

ConcatenableList

public ConcatenableList()
Constructs an empty list.

Method Detail

listIterator

public ListIterator<E> listIterator(int index)

Specified by:
listIterator in interface List<E>
Specified by:
listIterator in class AbstractSequentialList<E>

size

public int size()

Specified by:
size in interface Collection<E>
Specified by:
size in interface List<E>
Specified by:
size in class AbstractCollection<E>

add

public boolean add(E e)

Specified by:
add in interface Collection<E>
Specified by:
add in interface List<E>
Overrides:
add in class AbstractList<E>

addAll

public boolean addAll(Collection<? extends E> c)
Appends all of the elements in the specified collection to the end of 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.)

Specified by:
addAll in interface Collection<E>
Specified by:
addAll in interface List<E>
Overrides:
addAll in class AbstractCollection<E>
Parameters:
c - collection containing elements to be added to this list
Returns:
true if this list changed as a result of the call

addAll

public boolean addAll(int index,
                      Collection<? extends E> c)
Inserts all of the elements in the specified collection into this list, starting at the specified position. 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 the list in the order that they are returned by the specified collection's iterator.

Specified by:
addAll in interface List<E>
Overrides:
addAll in class AbstractSequentialList<E>
Parameters:
index - index at which to insert the first element from the specified collection
c - collection containing elements to be added to this list
Returns:
true if this list changed as a result of the call

concatenate

public void concatenate(ConcatenableList<E> other)
Concatenates the receiver with the given list. The new elements are appended at the end of this list. The given list is cleared to avoid any inconsistencies.

Parameters:
other - list to concatenate

getFirst

public E getFirst()
Returns the first element in this list.

Returns:
the first element in this list

getLast

public E getLast()
Returns the last element in this list.

Returns:
the last element in this list

addFirst

public void addFirst(E e)
Inserts the specified element at the beginning of this list.

Parameters:
e - the element to add

addLast

public void addLast(E e)
Appends the specified element to the end of this list.

This method is equivalent to add(E).

Parameters:
e - the element to add

removeFirst

public E removeFirst()
Removes and returns the first element from this list.

Returns:
the first element from this list

removeLast

public E removeLast()
Removes and returns the last element from this list.

Returns:
the last element from this list