ist.palcom.base
Class LinkedList

java.lang.Object
  extended by ist.palcom.base.Object
      extended by ist.palcom.base.LinkedList

public class LinkedList
extends Object

LinkedList is a double linked list that supports the interface of both Java LinkedList and typical LinkedList datastructures in the Smalltalk world. The LinkedList class shares interface with the ArrayList class.


Constructor Summary
LinkedList()
           
 
Method Summary
 void add(int index, Object value)
          Inserts the specified value at the specified position in this LinkedList.
 void add(Object value)
          Adds the specified value after the last element of this LinkedList.
 void add(Object value, Link link)
          Adds the specified value before the specified link.
 void addFirst(Object value)
          Adds the specified value before the first element of this LinkedList.
 void addLast(Object value)
          Adds the specified value after the last element of this LinkedList.
 Array asArray()
          Returns an array containing all elements in this LinkedList in the correct order.
 Object at(int index)
          Returns the element at the specified position.
 void at(int index, Object value)
          Replaces the element at the specified position with the specified value.
 void clear()
          Removes all elements from this LinkedList giving an empty list.
 boolean contains(Object value)
          Tests if this LinkedList contains the specified value.
 Object getFirst()
          Returns the first element of this LinkedList
 Object getLast()
          Returns the last element of this LinkedList
 int indexOf(Object value)
          Returns the index of the first occurrence of the specified value in this LinkedList.
 void init()
          Initializes this LinkedList
 boolean isEmpty()
          Tests if this LinkedList is empty.
 int lastIndexOf(Object value)
          Returns the index of the last occurrence of the specified value in this LinkedList.
 Link link(int index)
          Returns the link at specified index
 void remove(Object value)
          Removes on instance of the specified value from this LinkedList.
 void removeAt(index index)
          Removes the element at the specified position
 Object removeFirst()
          Removes the first element of this LinkedList.
 Object removeLast()
          Removes the last element of this LinkedList.
 void removeLink(Link link)
          Removes the specified link from this LinkedList
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LinkedList

public LinkedList()
Method Detail

removeAt

public void removeAt(index index)
Removes the element at the specified position

Parameters:
index - index of the element to remove.

addLast

public void addLast(Object value)
Adds the specified value after the last element of this LinkedList.

Parameters:
value - Object the value to add after last element.

add

public void add(int index,
                Object value)
Inserts the specified value at the specified position in this LinkedList.

Parameters:
index - int the position to insert at.
value - Object the value to insert.

getFirst

public Object getFirst()
Returns the first element of this LinkedList

Returns:
Object first element

at

public void at(int index,
               Object value)
Replaces the element at the specified position with the specified value.

Parameters:
index - int index of element to replace
value - Object new value to store at specified position

removeFirst

public Object removeFirst()
Removes the first element of this LinkedList.

Returns:
Object the removed element.

getLast

public Object getLast()
Returns the last element of this LinkedList

Returns:
Object last element

add

public void add(Object value)
Adds the specified value after the last element of this LinkedList.

Parameters:
value - Object the value to add after last element.

remove

public void remove(Object value)
Removes on instance of the specified value from this LinkedList.

Parameters:
value - Object value to remove.

asArray

public Array asArray()
Returns an array containing all elements in this LinkedList in the correct order.

Returns:
Array an array containing all elements in this LinkedList.

add

public void add(Object value,
                Link link)
Adds the specified value before the specified link.

Parameters:
value - Object the value to add
link - Link the link to add before

contains

public boolean contains(Object value)
Tests if this LinkedList contains the specified value.

Parameters:
value - Object value to search for.
Returns:
boolean true if the value is contained in this LinkedList, false otherwise.

removeLink

public void removeLink(Link link)
Removes the specified link from this LinkedList

Parameters:
link - Link the link to remove

lastIndexOf

public int lastIndexOf(Object value)
Returns the index of the last occurrence of the specified value in this LinkedList. If the value does not exist in this LinkedList, -1 will be returned.

Parameters:
value - Object the value to search for.
Returns:
int the index of the last occurrence of the value.

isEmpty

public boolean isEmpty()
Tests if this LinkedList is empty.

Returns:
boolean true if this LinkedList has no elements, false otherwise

removeLast

public Object removeLast()
Removes the last element of this LinkedList.

Returns:
Object the removed element.

init

public void init()
Initializes this LinkedList


addFirst

public void addFirst(Object value)
Adds the specified value before the first element of this LinkedList.

Parameters:
value - Object the value to add before the first element..

clear

public void clear()
Removes all elements from this LinkedList giving an empty list.


link

public Link link(int index)
Returns the link at specified index

Parameters:
index - int index of link to return.
Returns:
Link link at the specified index.

at

public Object at(int index)
Returns the element at the specified position.

Parameters:
index - int index of element to return.
Returns:
Object element at the specified position.

indexOf

public int indexOf(Object value)
Returns the index of the first occurrence of the specified value in this LinkedList. If the value does not exist in this LinkedList, -1 will be returned.

Parameters:
value - Object the value to search for.
Returns:
int the index of the first occurrence of the value.