Class CircularNode<T>

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

public class CircularNode<T> extends Object
Represents a node in a circular linked list. Each node contains a value and references to both next and previous nodes, forming a circular structure where the last node points back to the first.
Since:
2024
  • Constructor Details

    • CircularNode

      public CircularNode()
      Constructs an empty circular node with null value and null references. This constructor creates a node that can be initialized later with setter methods. Useful for placeholder nodes or delayed initialization.
    • CircularNode

      public CircularNode(T value)
      Constructs a new circular node with the specified value and null references. This constructor is typically used when creating new nodes that will be linked into the circular structure later.
      Parameters:
      value - the value to be stored in this node
  • Method Details

    • getNext

      public CircularNode<T> getNext()
      Returns the next node in the circular sequence. In a properly formed circular list, this should never be null.
      Returns:
      the next node in the sequence
    • setNext

      public void setNext(CircularNode<T> next)
      Sets the reference to the next node in the circular sequence. This method is used to maintain the circular structure of the list.
      Parameters:
      next - the next node in the sequence
    • getPrevious

      public CircularNode<T> getPrevious()
      Returns the previous node in the circular sequence. In a properly formed circular list, this should never be null.
      Returns:
      the previous node in the sequence
    • setPrevious

      public void setPrevious(CircularNode<T> previous)
      Sets the reference to the previous node in the circular sequence. This method is used to maintain the circular structure of the list.
      Parameters:
      previous - the previous node in the sequence
    • getValue

      public T getValue()
      Returns the value stored in this node.
      Returns:
      the value stored in this node, may be null if empty 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
    • toString

      public String toString()
      Returns a string representation of this node's value. Returns "null" if the value is null, otherwise returns the string representation of the value by calling its toString() method.

      This method is safe to use even when the value might be null.

      Overrides:
      toString in class Object
      Returns:
      a string representation of the value stored in this node, or "null" if the value is null