Class AiccPrerequisiteNode

java.lang.Object
dev.jcputney.elearning.parser.input.aicc.prereq.AiccPrerequisiteNode
All Implemented Interfaces:
Serializable

public final class AiccPrerequisiteNode extends Object implements Serializable
Represents a node in an AICC prerequisite expression tree. Each node has a specific type, an optional value, and may contain child nodes to represent nested expressions.

This class is immutable and thread-safe.

The nodes are categorized by type using the AiccPrerequisiteNodeType, which defines their logical or structural meaning, such as an identifier, logical operators, etc.

Attributes: - `type`: Indicates the type of the node (e.g. IDENTIFIER, AND, OR, NOT). - `value`: Represents the value associated with the node, if applicable (e.g. an identifier for a course/module). - `children`: A list of child nodes used to represent nested logical structures in the prerequisite expression.

Functionalities: - Supports creation of both leaf nodes and tree structures with children. - Provides equality, hash code, and string representation for comparing and describing the node. - Ensures immutability by copying and requiring non-null values for its components during initialization.

See Also:
  • Constructor Details

    • AiccPrerequisiteNode

      public AiccPrerequisiteNode(AiccPrerequisiteNodeType type, String value, List<AiccPrerequisiteNode> children)
      Constructs an instance of AiccPrerequisiteNode representing a node in an AICC prerequisite expression tree. A node can represent various logical operations (e.g., AND, OR, NOT) or a leaf node identified by an identifier value. The node may also have child nodes that define its hierarchical structure within the expression tree.
      Parameters:
      type - the type of the node, defining its role in the prerequisite expression tree. Must not be null.
      value - the value associated with the node. May be null for certain node types that do not require a specific value (e.g., AND, OR, NOT).
      children - the list of child nodes associated with this node. If null is provided, it will be replaced with an empty list.
  • Method Details

    • leaf

      public static AiccPrerequisiteNode leaf(String value)
      Creates a new AiccPrerequisiteNode representing a leaf node in the prerequisite expression tree. The leaf node is identified by the specified value and is of type AiccPrerequisiteNodeType.IDENTIFIER. It has no child nodes.
      Parameters:
      value - the identifier value for the leaf node, representing a specific course or module.
      Returns:
      a new AiccPrerequisiteNode instance of type IDENTIFIER with the specified value and no child nodes.
    • getType

      public AiccPrerequisiteNodeType getType()
      Retrieves the type of this AICC prerequisite node. The type defines the role or behavior of the node within the prerequisite expression tree, such as whether it represents a logical operation (e.g., AND, OR, NOT) or an identifier.
      Returns:
      the AiccPrerequisiteNodeType representing the type of this prerequisite node
    • getValue

      public String getValue()
      Retrieves the value of this AICC prerequisite node. The value typically represents an identifier or specific piece of data associated with the node.
      Returns:
      the value of this node as a non-null string, or null if no value is assigned.
    • getChildren

      public List<AiccPrerequisiteNode> getChildren()
      Retrieves the list of child nodes associated with this AICC prerequisite node. The child nodes represent the subordinate elements in the prerequisite expression hierarchy.
      Returns:
      a list of AiccPrerequisiteNode objects representing the child nodes, or an empty list if this node has no children.
    • 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