Parsing Engine

danbikel.util
Class SLNode

java.lang.Object
  extended by danbikel.util.SLNode
All Implemented Interfaces:
Serializable

public class SLNode
extends Object
implements Serializable

Represents a node in a singly-linked list. This class provides low-level and direct access to the nodes of a singly-linked list and to the data objects at those nodes, and is thus intended to be used when efficiency concerns outweigh data abstraction concerns. For example, this class makes no attempt at providing synchronization mechanisms, nor does it attempt to check for concurrent modifications, as do most of the Collections framework classes. Also, zero-length lists are represented implicitly by null, as far as this class is concerned.

See Also:
Serialized Form

Constructor Summary
SLNode()
           
SLNode(Object data, SLNode next)
          Constructs a new SLNode with the specified data object and next node.
 
Method Summary
 Object data()
          Returns the data associated with this node of the list.
 Iterator iterator()
          Returns an iterator to iterate over the elements of this list.
 int length()
          Returns the length of this list.
 SLNode next()
          Returns the next node of this list.
 SLNode set(Object data, SLNode next)
           
 SLNode setData(Object data)
           
 int size()
          Returns the length of this list.
 LinkedList toList()
          Returns a new LinkedList object containing all the data of this list.
 String toString()
          Returns a human- and Sexp-readable version of the singly-linked list headed by this node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SLNode

public SLNode()

SLNode

public SLNode(Object data,
              SLNode next)
Constructs a new SLNode with the specified data object and next node.

Parameters:
data - the data to associate with this node
next - the next object in the singly-linked list, or null if this is the last node in the list
Method Detail

data

public Object data()
Returns the data associated with this node of the list.


next

public SLNode next()
Returns the next node of this list.


set

public SLNode set(Object data,
                  SLNode next)

setData

public SLNode setData(Object data)

length

public int length()
Returns the length of this list. This method begins by counting the current node, traversing next pointers until null is reached.


size

public int size()
Returns the length of this list.


toList

public LinkedList toList()
Returns a new LinkedList object containing all the data of this list.


iterator

public Iterator iterator()
Returns an iterator to iterate over the elements of this list. An alternative and more efficient iteration idiom is as follows:
 for (SLNode curr = <init>; curr.next() != null; curr = curr.next()) {
   Object data = curr.data();
   // operate on data at current node...
 }
 


toString

public String toString()
Returns a human- and Sexp-readable version of the singly-linked list headed by this node.

Overrides:
toString in class Object

Parsing Engine

Author: Dan Bikel.