//DLListOverride.java

/**
 * A DLList with a debug toString.
 *
 * @author Zach Tomaszewski
 * @version 04 Oct 2004
 */
public class DLListOverride extends DLList {

  /**
   * Returns a version of this list complete with next and previous
   * link information.
   */
  public String toString() {
    /*
     * In order for this method to work:
     * --make sure "head" in the call below matches the first node in your list
     * --make "head" protected rather than private
     */
    return toString(head);
  }
  
  /**
   * Prints the list of nodes (including link data) starting at head.
   */
  protected String toString(DLLNode head){
    /*
     * In order for this method to work:
     * --make any changes below if your DDLNode calls don't match these.
     */
    if (head == null) {
      return "[NULL]";
    }else {
      String prev = (head.getPrev() == null) ? 
                     "[(null) <-- " :
                     "[(" + head.getPrev().getValue() + ") <-- ";
      String val = head.getValue().toString();
      String next = (head.getNext() == null) ? 
                     " --> (null)]" :
                     " --> (" + head.getNext().getValue() + ")]";
      if (head.getNext() == null) {
        return (prev + val + next + "\n");
      }else {  
        return (prev + val + next + "\n" + toString(head.getNext()));
      }
    }                   
  }

}
