package rpi.goldsd.container; /** * The ListNode class represents a single node of the * LinkedList container class by implementing the Linkable * interface. Note that the Comparable interface is also implemented * by simply invoking the underlying interface of the Comparable * object that is stored in this ListNode. * * @see LinkedList * @see Linkable * @see Comparable * @version 1.3, 4/16/98 * @author David Goldschmidt */ public class ListNode implements Comparable, Linkable { /** * The constructor contains a single required argument that represents * the Comparable object to be stored in this ListNode. * @param data the Comparable object to be stored in this * ListNode. */ public ListNode( Comparable data ) { this.data = data; this.next = this.previous = null; } /** The default constructor is not to be invoked. */ protected ListNode() {} /** * Returns the Comparable object stored in this ListNode. * @return the Comparable object stored in this ListNode. */ public Comparable getData() { return data; } /** * Returns a reference to the next Linkable object that follows * this ListNode. * @return a reference to the next Linkable object that follows * this ListNode. */ public Linkable getNext() { return next; } /** * Returns a reference to the previous Linkable object that * precedes this ListNode. * @return a reference to the previous Linkable object that * precedes this ListNode. */ public Linkable getPrevious() { return previous; } /** * Compares this ListNode to either another ListNode * object or to another Comparable object (presumably of the * same type of the data associated with this ListNode). * @return true if this ListNode is determined to be * equal to the Comparable argument C; * false otherwise. */ public boolean isEqualTo( Comparable C ) { if ( C instanceof ListNode ) return ( data.isEqualTo( ((ListNode)C).getData() ) ); else return ( data.isEqualTo( C ) ); } /** * Compares this ListNode to either another ListNode * object or to another Comparable object (presumably of the * same type of the data associated with this ListNode). * @return true if this ListNode is determined to be * less than the Comparable argument C; * false otherwise. */ public boolean isLessThan( Comparable C ) { if ( C instanceof ListNode ) return ( data.isLessThan( ((ListNode)C).getData() ) ); else return ( data.isLessThan( C ) ); } /** * Sets the Comparable object stored in this ListNode. * @param data the Comparable object to be stored in this * ListNode. */ public void setData( Comparable data ) { this.data = data; } /** * Establishes a link to the next Linkable object in the list. * @param node the Linkable object to be linked as the next * Linkable object after this ListNode. */ public void setNext( Linkable node ) { next = (ListNode)node; } /** * Establishes a link to the previous Linkable object in the list. * @param node the Linkable object to be linked as the previous * Linkable object to this ListNode. */ public void setPrevious( Linkable node ) { previous = (ListNode)node; } /** * The toString() is the default method used to display this * ListNode object in the form of a String object. * @return a String representing this ListNode. */ public String toString() { return ( "" + data ); } /** * The data associated with this ListNode must implement the * Comparable interface. */ protected Comparable data; /** * Identifies the next ListNode object in the corresponding * LinkedList object. */ protected ListNode next; /** * Identifies the previous ListNode object in the corresponding * LinkedList object. */ protected ListNode previous; }