org.ws4d.java.structures
Class LinkedList

java.lang.Object
  extended by org.ws4d.java.structures.DataStructure
      extended by org.ws4d.java.structures.List
          extended by org.ws4d.java.structures.LinkedList

public class LinkedList
extends List

Implementation of a double linked list. Class is not synchronized.


Constructor Summary
LinkedList()
          Constructor.
 
Method Summary
 void add(int index, java.lang.Object obj)
          Adds element between the previous and the old element at the specified index position.
 boolean add(java.lang.Object obj)
          Adds object at the end of the linked list
 boolean addAll(DataStructure c)
          Add all elements within the data structure at the end of the linked list.
 boolean addAll(int index, DataStructure data)
          Add all elements of the given data structure into the list.
 void addFirst(java.lang.Object o)
          Adds the given element at the beginning of this list.
 void clear()
          Removes all of the elements from this list.
 java.lang.Object get(int index)
           
 java.lang.Object getFirst()
          Returns the first element in this list.
 java.lang.Object getLast()
          Returns the last element in this list.
 Iterator iterator()
          Returns an iterator over all items stored within this data structure instance.
 ListIterator listIterator(int index)
          Returns a list iterator of the list.
 java.lang.Object remove(int index)
          Removes the element at the specified position in this list.
 java.lang.Object removeFirst()
          Removes the first element of list and returns it.
 java.lang.Object removeLast()
          Removes and returns the last element from this list.
 java.lang.Object set(int index, java.lang.Object element)
           
 java.lang.Object[] toArray()
          Returns an array containing all items stored within this data structure.
 java.lang.Object[] toArray(java.lang.Object[] array)
          Fills array with the elements of this list.
 
Methods inherited from class org.ws4d.java.structures.List
equals, getClassShortName, indexOf, lastIndexOf, listIterator, size, subList
 
Methods inherited from class org.ws4d.java.structures.DataStructure
contains, containsAll, hashCode, isEmpty, remove, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LinkedList

public LinkedList()
Constructor.

Method Detail

add

public void add(int index,
                java.lang.Object obj)
         throws java.lang.IndexOutOfBoundsException
Adds element between the previous and the old element at the specified index position.

Overrides:
add in class List
Parameters:
index - position of element to add ( 0==head, size==end of list).
obj - object to add
Throws:
java.lang.IndexOutOfBoundsException

add

public boolean add(java.lang.Object obj)
Adds object at the end of the linked list

Overrides:
add in class List
Parameters:
obj - object to add
Returns:
true if the object was actually added, false in any other case (e.g. adding an object to a set which already contains the same object in terms of java.lang.Object.equals(Object))

addAll

public boolean addAll(DataStructure c)
Add all elements within the data structure at the end of the linked list.

Overrides:
addAll in class List
Parameters:
c - elements to add.
Returns:
true if at least one object from data was actually added, i.e. a modification was made to this instance, false in any other case (e.g. adding objects to a set which already contains them in terms of java.lang.Object.equals(Object))

addAll

public boolean addAll(int index,
                      DataStructure data)
               throws java.lang.IndexOutOfBoundsException
Add all elements of the given data structure into the list. The elements are added at the given index position, which will add the elements with given index 0 at the beginning of the list. Adding the data structure at index == size, will add all elements at the end of the list.

Overrides:
addAll in class List
Parameters:
index - Index of position to add the new elements at.
data - data structure to add.
Returns:
true if this list changed as a result of the call.
Throws:
java.lang.IndexOutOfBoundsException - if the specified index is out of range

addFirst

public void addFirst(java.lang.Object o)
Adds the given element at the beginning of this list.

Parameters:
o - element to add.

clear

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

Overrides:
clear in class DataStructure

get

public java.lang.Object get(int index)
                     throws java.lang.IndexOutOfBoundsException
Specified by:
get in class List
Throws:
java.lang.IndexOutOfBoundsException

getFirst

public java.lang.Object getFirst()
Returns the first element in this list.

Returns:
first element.

getLast

public java.lang.Object getLast()
Returns the last element in this list.

Returns:
last element

iterator

public Iterator iterator()
Description copied from class: DataStructure
Returns an iterator over all items stored within this data structure instance. The iterator will walk through the items in the natural order of this data structure; i.e. for a list-like structure this will be the same order as the one defined by the list.

Overrides:
iterator in class List
Returns:
an iterator over all stored objects

listIterator

public ListIterator listIterator(int index)
                          throws java.lang.IndexOutOfBoundsException
Returns a list iterator of the list. It starts at the given index.

Overrides:
listIterator in class List
Parameters:
index - index to start.
Throws:
java.lang.IndexOutOfBoundsException - thrown if (index < 0) or (index > size)

remove

public java.lang.Object remove(int index)
                        throws java.lang.IndexOutOfBoundsException
Removes the element at the specified position in this list.

Overrides:
remove in class List
Parameters:
index - index
Throws:
java.lang.IndexOutOfBoundsException - thrown if (index < 0) or (index >= size)

removeFirst

public java.lang.Object removeFirst()
                             throws java.util.NoSuchElementException
Removes the first element of list and returns it.

Returns:
the removed element.
Throws:
java.util.NoSuchElementException - thrown if no element is in list

removeLast

public java.lang.Object removeLast()
                            throws java.util.NoSuchElementException
Removes and returns the last element from this list.

Returns:
the removed last element
Throws:
java.util.NoSuchElementException

set

public java.lang.Object set(int index,
                            java.lang.Object element)
                     throws java.lang.IndexOutOfBoundsException
Overrides:
set in class List
Throws:
java.lang.IndexOutOfBoundsException

toArray

public java.lang.Object[] toArray()
Description copied from class: DataStructure
Returns an array containing all items stored within this data structure. The array will be of length DataStructure.size(), i.e. for an empty data structure an array of length zero is returned (rather than null).

Overrides:
toArray in class DataStructure
Returns:
an array of all objects contained within this data structure instance; this method never returns null

toArray

public java.lang.Object[] toArray(java.lang.Object[] array)
Fills array with the elements of this list. If the given array is too short or is null, a new array with the length of the list size will be created and filled.

Overrides:
toArray in class DataStructure
Parameters:
array - the array to store this data structure's content to
Returns:
the filled array