/* Copyright (C) 1998 H. Conrad Cunningham.  All rights reserved.  */

package SoftwareInterfaces;

/**
 * A class that implements the nodes of the linked list used for the 
 * doubly linked list implementation of the ranked sequence abstract data type.
 *
 * @author H. Conrad Cunningham
 * @version 1 June 1998
 */

class DoubleLink
{
    /**
     * Constructs a node of a doubly linked list.
     *
     * <dt><b>Postcondition:</b> 
     * <dd>node is initialized with null data and links
     */
    public DoubleLink()
    {   elem = null; prev = null; next = null; }


    /**
     * Constructs a node of a doubly linked list.
     *
     * @param e the data element to stored at the node
     * 
     * <dt><b>Postcondition:</b> 
     * <dd>node is initialized with data element <code>e</code> and null links
     */
    public DoubleLink(Object e)
    {   elem = e; prev = null; next = null; }


    /**
     * Constructs a node of a doubly linked list.
     *
     * @param e the data element to stored at the node
     * @param prv a reference to the previous node of the list
     * @param nxt a reference to the next node of the list
     * 
     * <dt><b>Postcondition:</b> 
     * <dd>node is initialized with data element <code>e</code> and previous 
     *     and next links as <code>prv</code> and <code>nxt</code>, 
     *     respectively.
     */
    public DoubleLink(Object e, DoubleLink prv, DoubleLink nxt)
    {   elem = e; prev = prv; next = nxt; }


    /**
     * Sets the data element of the node.
     *
     * @param e the new data object to stored at the node
     * 
     * <dt><b>Postcondition:</b> 
     * <dd>the data element at this node is object <code>e</code>.
     *     the previous and next links are unchanged
     */
    public void setElem(Object e)
    {   elem = e; }


    /**
     * Sets the previous link of the node.
     *
     * @param prv the new value of the previous link
     * 
     * <dt><b>Postcondition:</b> 
     * <dd>the previous link of the node is <code>prv</code>.
     * The data element and next link are unchanged.
     */
    public void setPrev(DoubleLink prv)
    {   prev = prv; }


    /**
     * Sets the next link of the node.
     *
     * @param nxt the new value of the next link
     * 
     * <dt><b>Postcondition:</b> 
     * <dd>the next link of the node is <code>nxt</code>.
     * The data element and previous link are unchanged.
     */
    public void setNext(DoubleLink nxt)
    {   next = nxt; }


    /**
     * Retrieves the data element stored at this node.
     *
     * @return the data element stored at this node
     */
    public Object getElem()
    {   return elem; }


    /**
     * Retrieves the previous link of this node.
     *
     * @return the previous link of this node
     */
    public DoubleLink getPrev()
    {   return prev; }


    /**
     * Retrieves the next link of this node.
     *
     * @return the next link of this node
     */
    public DoubleLink getNext()
    {   return next; }
      
    private Object elem;      // the data
    private DoubleLink prev;  // the previous element of the list
    private DoubleLink next;  // the next element of the list
}
