/** * A simple implementation of the nodes in a singly-linked list. * * @author Samuel A. Rebelsky * @version 1.0 of March 1998 */ public class Node { // +------------+-------------------------------------------------------- // | Attributes | // +------------+ /** * The value stored in the current node. */ Object value; /** * The next node. Set to null when the node is the last one * in the list. */ Node next; // +--------------+------------------------------------------------------ // | Constructors | // +--------------+ /** * Create a new node with value and next set appropriately. */ public Node(Object value, Node next) { this.value = value; this.next = next; } // Node(Object, Node) /** * Create a new node with a particular value (in effect, a * one-element list). */ public Node(Object value) { this(value,null); } // Node(Object) // +-----------+--------------------------------------------------------- // | Accessors | // +-----------+ /** * Get the value stored in the current node. */ public Object getValue() { return this.value; } // getValue() /** * Get the next node in the list. May return null. */ public Node getNext() { return this.next; } // getNext() // +-----------+--------------------------------------------------------- // | Modifiers | // +-----------+ /** * Set the value stored in the current node. */ public Object setValue(Object value) { Object tmp = this.value; this.value = value; return tmp; } // setValue(Object) /** * Set the next node in the list. The next node may be null */ public Node setNext(Node next) { Node tmp = this.next; this.next = next; return tmp; } // setNext(Node) } // Node