/**
 * File: Node.java
 * Author: Goodrich & Tamassia. A variation of definition on page 116, 4E
 * Description: Represents a node in a singly linked list of Objects.
 */
public class Node {

    protected Object element;   // Any object can be stored in this list
    protected Node next;

    /** Default constructor creates a null node */
    public Node() {
	this(null, null);
    }

    /** 
     * Constructor creates a node form Object e 
     * @param the Object being stored in the node
     * @param a pointer to the next node
     */
    public Node(Object e, Node n) {
	element = e;
	next = n;
    }

    /** 
     * Accessor method getElement() returns the node's Object  
     * @return the Object being stored in this node.
     */
    public Object getElement() {
	return element;
    }

    /**  
     * getNext() returns the node's pointer
     * @return a pointer to the next node
     */
    public Node getNext() {
	return next;
    }
    
    /** 
     * Modifier  method setElement() changes a node's element  
     * @param the Object being stored in this node.
     */
    public void setElement(Object newElem) {
	element = newElem;
    }

    /** 
     * Modifier  method setNext() changes a node's next pointer  
     * @param a pointer to the next node
     */
    public void setNext(Node newNext) {
	next = newNext;
    }

    /** 
     * Two nodes are equal if their elements are eqaul 
     * @param the Node being compared to this node.
     */
    public boolean equals(Node node) {
	return this.getElement().equals(node.getElement());
    }
} 
