Class Nodelist

java.lang.Object
  |
  +--Nodelist
All Implemented Interfaces:
java.io.Serializable

public class Nodelist
extends java.lang.Object
implements java.io.Serializable

Nodelist is a manager Object for a linked list. It uses the Node class datastructure as buildingblocks for this list.
Author: Neil Short

See Also:
Serialized Form

Constructor Summary
Nodelist()
          Construct a list with no data elements.
 
Method Summary
 void append(java.lang.Object r)
          Add data r to the end of the linked list.
 void deleteAt(int n)
          Remove the element at position n.
 void deleteNode(Node n)
          Delete the Node arguement from the linked list Nodelist.
 Iterator getIterator()
          Build and return an Iterator that accesses this instance of the linked list.
 int getLength()
          Return the number of elements in the list.
 Node gotopos(int n)
          Return the Node at position n.
 void insertAt(java.lang.Object r, int n)
          Insert a piece of data into the list at position n.
 void makeempty()
          This method empties the linked list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Nodelist

public Nodelist()
Construct a list with no data elements.

Method Detail

makeempty

public void makeempty()
This method empties the linked list. All data elements in the list are lost when this method is called.


getIterator

public Iterator getIterator()
Build and return an Iterator that accesses this instance of the linked list.


append

public void append(java.lang.Object r)
Add data r to the end of the linked list.


gotopos

public Node gotopos(int n)
Return the Node at position n. Use this method with care. Since it returns a Node, the accessing class must be very familiar with the internal workings of Nodelist. There is easy potential for data damage with misuse of this method. It is public to facilitate direct Nodelist manipulation. A piece of data can thus be snatched out of one place in the list without knowledge of the position the data holds in the list. This special use is also the purpose of the deleteNode() method.

One more caution is in order. The position indicated starts counting at 1 and not 0; so the first element in the list is at position 1.

This method was originally private. I still have reservations about making it public.


insertAt

public void insertAt(java.lang.Object r,
                     int n)
Insert a piece of data into the list at position n. Count starts appropriately at 0.


deleteAt

public void deleteAt(int n)
Remove the element at position n. First element is at position 0.


deleteNode

public void deleteNode(Node n)
Delete the Node arguement from the linked list Nodelist. Note that this method takes as an arguement an actual node from the list. That means the class that is passing the arguement has gained access to the Node from the gotopos() method. This method facilitates a quick removal of an element from the list without the need for determining its position in the list. This method works well as long as the Node arguement is in fact an element in the list. If it is not, the result cannot be predicted. Be careful!


getLength

public int getLength()
Return the number of elements in the list.