/**
 * A single doubly-linked node in a linked list data structure.
 * <p>
 * Like a Node, but also include a reference to the previous node.
 *
 * @author Zach Tomaszewski
 */
public class DLNode<E> {

  private E data;
  private DLNode<E> next;
  private DLNode<E> prev;

  /** 
   * Constructs a new node with the given data and references to the 
   * given previous and next nodes in the linked list structure.
   */
  public DLNode(E data, DLNode<E> prev, DLNode<E> next) {
    this.data = data;
    this.prev = prev;
    this.next = next;
  }

  /** 
   * Constructs a new node containing the given data.  
   * Its previous and next references will be set to null. 
   */
  public DLNode(E data) {
    this(data, null, null);
  }

  /** Returns the item currently stored in this node. */
  public E getData() {
    return data;
  }

  /** Overwrites the item stored in this Node with the given data item. */
  public void setData(E data) {
    this.data = data;
  }

  /** 
   * Returns the Node after this one in the linked list structure.
   * If there is no next Node, returns null. 
   */
  public DLNode<E> getNext() {
    return next;
  }

  /** Causes this Node to point to the given next Node. */
  public void setNext(DLNode<E> next) {
    this.next = next;
  }

  /** 
   * Returns the Node before this one in the linked list structure.
   * If there is no previous Node, returns null. 
   */
  public DLNode<E> getPrevious() {
    return prev;
  }
  
  /** Causes this Node to point to the given previous Node. */
  public void setPrevious(DLNode<E> prev) {
    this.prev = prev;
  }
}
