fi.joensuu.cs.tra
Class TraLinkedList<E>

java.lang.Object
  extended by fi.joensuu.cs.tra.TraLinkedList

public class TraLinkedList<E>
extends Object


Field Summary
static ListNode EOL
          Denotes the end of the list.
 
Constructor Summary
TraLinkedList()
          Creates an empty list.
 
Method Summary
 ListNode<E> first()
          Returns the first node of this list.
 ListNode<E> getNext(ListNode<E> node)
          Returns the specified ListNodes next ListNode or null if none exists.
 ListNode<E> getPrevious(ListNode<E> node)
          Returns the specified ListNodes previous ListNode or null if none exists.
 ListNode<E> insert(ListNode<E> node, E element)
          Inserts a new ListNode with the specified elementin front of the specified ListNode.
 ListNode<E> insert(ListNode<E> node, ListNode<E> newNode)
          Inserts a ListNode in front of the specified ListNode.
 boolean isEmpty()
          Returns true if this list is empty.
 ListNode<E> last()
          Returns the last node of this list.
 ListNode<E> remove(ListNode<E> node)
          Removes a ListNode from this TraLinkedList.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EOL

public static final ListNode EOL
Denotes the end of the list.

Constructor Detail

TraLinkedList

public TraLinkedList()
Creates an empty list.

Method Detail

isEmpty

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

Returns:
true if this list has no ListNodes.

first

public ListNode<E> first()
Returns the first node of this list.

Returns:
the first ListNode of this list or null if this list is empty.

last

public ListNode<E> last()
Returns the last node of this list.

Returns:
the last ListNode of this list or null if this list is empty.

insert

public ListNode<E> insert(ListNode<E> node,
                          ListNode<E> newNode)
Inserts a ListNode in front of the specified ListNode. If node is EOL, the ListNode will be inserted at the end of the TraLinkedList.

Parameters:
node - the ListNode in front of which newNode will be inserted. If node is EOL, node will be inserted at the end of the TraLinkedList.
newNode - the ListNode to be inserted.
Returns:
the inserted ListNode
Throws:
NullPointerException - if node or newNode is null.

insert

public ListNode<E> insert(ListNode<E> node,
                          E element)
Inserts a new ListNode with the specified elementin front of the specified ListNode. If node is EOL, the ListNode will be inserted at the end of the TraLinkedList.

Parameters:
node - the ListNode in front of which newNode will be inserted. If node is EOL, node will be inserted at the end of the TraLinkedList.
element - the element for the new ListNode
Returns:
the inserted ListNode
Throws:
NullPointerException - if node is null.

remove

public ListNode<E> remove(ListNode<E> node)
Removes a ListNode from this TraLinkedList.

Parameters:
node - the ListNode to be removed.
Returns:
the removed ListNode.
Throws:
NullPointerException - if node is null.
IllegalArgumentException - if node is EOL.

getNext

public ListNode<E> getNext(ListNode<E> node)
Returns the specified ListNodes next ListNode or null if none exists.

Parameters:
node - the ListNode the next ListNode of which is to be returned.
Returns:
the next ListNode of node or null if none exists.
Throws:
NullPointerException - if node is null.

getPrevious

public ListNode<E> getPrevious(ListNode<E> node)
Returns the specified ListNodes previous ListNode or null if none exists.

Parameters:
node - the ListNode the previous ListNode of which is to be returned.
Returns:
the previous ListNode of node or null if none exists.
Throws:
NullPointerException - if node is null.