Class Node<T>

java.lang.Object
solver.Node<T>
Type Parameters:
T - represents the moves that can be applied to the states

public class Node<T> extends Object
Represents the nodes of a search graph.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Node(puzzle.State<T> state)
    Creates a Node without a parent, i.e., a root node.
    Node(puzzle.State<T> state, Node<T> parent, T move)
    Creates a Node with a parent node.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    Expands the node by generating all possible next states from the current state.
    Returns the move that created the state from the state of the parent node.
    Returns the parent of the node.
    puzzle.State<T>
    Returns the state represented by the node.
    int
     
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Node

      public Node(puzzle.State<T> state)
      Creates a Node without a parent, i.e., a root node.
      Parameters:
      state - the state represented by the node
    • Node

      public Node(puzzle.State<T> state, Node<T> parent, T move)
      Creates a Node with a parent node.
      Parameters:
      state - the state represented by the node
      parent - the parent of the node
      move - the move that created the state from the parent node
  • Method Details

    • getState

      public puzzle.State<T> getState()
      Returns the state represented by the node.
      Returns:
      the state represented by the node
    • getParent

      public Optional<Node<T>> getParent()
      Returns the parent of the node.
      Returns:
      an Optional describing the parent of the node, or an empty optional if the node does not have a parent
    • getMove

      public Optional<T> getMove()
      Returns the move that created the state from the state of the parent node.
      Returns:
      an Optional describing the move that created the state from the parent node, or an empty Optional if the node does not have a parent
    • expand

      public Set<Node<T>> expand()
      Expands the node by generating all possible next states from the current state.
      Returns:
      a set of nodes representing the next states
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object