clarion.tools.linkedlist
Class LinkedList

java.lang.Object
  extended byclarion.tools.linkedlist.LinkedList
All Implemented Interfaces:
java.lang.Cloneable, List

public class LinkedList
extends java.lang.Object
implements List, java.lang.Cloneable


Nested Class Summary
protected static class LinkedList.Node
           
 
Field Summary
protected  int count
           
protected  LinkedList.Node head
           
protected  LinkedList.Node tail
           
 
Constructor Summary
LinkedList()
           
 
Method Summary
 java.lang.Object clone()
          Creates a deep copy of this list.
 boolean equals(java.lang.Object other)
          Checks whether some other object is equal to this one.
 int getCount()
          Counts the number of elements in the list.
 java.lang.Object getFrom(int index)
          Returns the element at the specified position in the list.
 java.lang.Object getHead()
          Returns the first element in the list.
 java.lang.Object getTail()
          Returns the last element in the list.
 int hashCode()
          Computes a hash code value for the list.
 void insertAt(java.lang.Object element, int index)
          Inserts an element at the specified position in the list.
 void insertHead(java.lang.Object element)
          Inserts an element at the beginning of the list.
 void insertTail(java.lang.Object element)
          Inserts an element at the end of the list.
 boolean isEmpty()
          Checks whether the list is empty.
 java.lang.Object removeFrom(int index)
          Removes from the list the element at the specified location.
 java.lang.Object removeHead()
          Removes the first element from the list.
 java.lang.Object removeTail()
          Removes the last element from the list.
 java.lang.String toString()
          Returns a string representation of the list.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

head

protected LinkedList.Node head

tail

protected LinkedList.Node tail

count

protected int count
Constructor Detail

LinkedList

public LinkedList()
Method Detail

isEmpty

public boolean isEmpty()
Checks whether the list is empty.

Specified by:
isEmpty in interface List
Returns:
true if the list is empty, false otherwise.

getCount

public int getCount()
Counts the number of elements in the list.

Specified by:
getCount in interface List
Returns:
the number of elements in the list.

getHead

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

Specified by:
getHead in interface List
Returns:
the first element in the list.

getTail

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

Specified by:
getTail in interface List
Returns:
the last element in the list.

getFrom

public java.lang.Object getFrom(int index)
Returns the element at the specified position in the list.

Specified by:
getFrom in interface List
Parameters:
index - the index of the element to return.
Returns:
the element at the specified position.

toString

public java.lang.String toString()
Returns a string representation of the list.

Returns:
a string representation of the list.

equals

public boolean equals(java.lang.Object other)
Checks whether some other object is equal to this one.

Parameters:
other - the object with which to compare.
Returns:
true if the two objects are equal, false otherwise.

hashCode

public int hashCode()
Computes a hash code value for the list.

Returns:
a hash code value for the list.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Creates a deep copy of this list.

Returns:
a clone of this list.
Throws:
java.lang.CloneNotSupportedException - if some element in the list is not an instance of CloneableListElement.

insertHead

public void insertHead(java.lang.Object element)
Inserts an element at the beginning of the list.

Specified by:
insertHead in interface List
Parameters:
element - the element to be inserted.

insertTail

public void insertTail(java.lang.Object element)
Inserts an element at the end of the list.

Specified by:
insertTail in interface List
Parameters:
element - the element to be inserted.

insertAt

public void insertAt(java.lang.Object element,
                     int index)
Inserts an element at the specified position in the list.

Specified by:
insertAt in interface List
Parameters:
element - the element to be inserted.
index - the position at which the element is to be inserted.

removeHead

public java.lang.Object removeHead()
Removes the first element from the list.

Specified by:
removeHead in interface List
Returns:
the element that was first in the list.

removeTail

public java.lang.Object removeTail()
Removes the last element from the list.

Specified by:
removeTail in interface List
Returns:
the element that was last in the list.

removeFrom

public java.lang.Object removeFrom(int index)
Removes from the list the element at the specified location.

Specified by:
removeFrom in interface List
Parameters:
index - the index of the element to be removed.
Returns:
the element that was at the specified location.