Class DoublyNode<T>

java.lang.Object
com.Roukan.datastructures.list.DoublyNode<T>
Type Parameters:
T - the type of value stored in this node

public class DoublyNode<T> extends Object
Represents a node in a doubly linked list. Each node contains a value and references to both the next and previous nodes in the sequence, allowing bidirectional traversal.
Since:
2024
  • Constructor Details

    • DoublyNode

      public DoublyNode(T value)
      Constructs a new doubly node with the specified value and null references for both next and previous nodes. This constructor is typically used for creating isolated nodes or the first node in a list.
      Parameters:
      value - the value to be stored in this node
    • DoublyNode

      public DoublyNode(T value, DoublyNode<T> nextNode, DoublyNode<T> previousNode)
      Constructs a new doubly node with the specified value, next node, and previous node. This constructor is used for creating nodes that are fully connected in both directions.
      Parameters:
      value - the value to be stored in this node
      nextNode - the next node in the sequence
      previousNode - the previous node in the sequence
    • DoublyNode

      public DoublyNode()
      Constructs a new empty doubly node with null value and null references. This constructor creates a node that can be initialized later. Use with caution as the value is null.
  • Method Details

    • getValue

      public T getValue()
      Returns the value stored in this node.
      Returns:
      the value stored in this node, may be null if default constructor was used
    • setValue

      public void setValue(T value)
      Sets a new value for this node.
      Parameters:
      value - the new value to be stored in this node
    • setNextNode

      public void setNextNode(DoublyNode<T> nextNode)
      Sets the reference to the next node in the sequence.
      Parameters:
      nextNode - the next node in the sequence, or null to make this the last node
    • getNextNode

      public DoublyNode<T> getNextNode()
      Returns the next node in the sequence. If this node is the last one in the list, returns null.
      Returns:
      the next node in the sequence, or null if this is the last node
    • getPreviousNode

      public DoublyNode<T> getPreviousNode()
      Returns the previous node in the sequence. If this node is the first one in the list, returns null.
      Returns:
      the previous node in the sequence, or null if this is the first node
    • setPreviousNode

      public void setPreviousNode(DoublyNode<T> previousNode)
      Sets the reference to the previous node in the sequence.
      Parameters:
      previousNode - the previous node in the sequence, or null to make this the first node
    • toString

      public String toString()
      Returns a string representation of this node's value. Calls toString() on the stored value. If the value is null, this method will throw a NullPointerException.
      Overrides:
      toString in class Object
      Returns:
      a string representation of the value stored in this node
      Throws:
      NullPointerException - if the value is null