Record Class TreeNode

java.lang.Object
java.lang.Record
io.github.kaktushose.jdac.internal.register.TreeNode
All Implemented Interfaces:
Iterable<TreeNode>

@Internal public record TreeNode(String name, SlashCommandDefinition command, List<TreeNode> children) extends Record implements Iterable<TreeNode>
Single node inside the CommandTree.
See Also:
  • Constructor Details

    • TreeNode

      public TreeNode(String name, SlashCommandDefinition command)
      Constructs a new TreeNode.
      Parameters:
      name - the name of the command
      command - the SlashCommandDefinition
    • TreeNode

      public TreeNode(String name, SlashCommandDefinition command, List<TreeNode> children)
      Creates an instance of a TreeNode record class.
      Parameters:
      name - the value for the name record component
      command - the value for the command record component
      children - the value for the children record component
  • Method Details

    • addChild

      public void addChild(String[] labels, SlashCommandDefinition command)
      Attempts to add a child TreeNode either as a child of this TreeNode or to one of its children based on the given labels.
      Parameters:
      labels - an Array of all labels, can be empty
      command - the SlashCommandDefinition to add
      Implementation Note:

      Traverses the tree based on the given labels. If more than one label is passed, creates a group note with label[0] as the name and passes the remaining label[1,2] to that note. This process is repeated until only one label is passed which will be added as a leaf node.

      This guarantees to create a CommandTree that respects Subcommands and SubcommandGroups.

    • getChild

      public Optional<TreeNode> getChild(String name)
      Gets a child TreeNode based on its name.
      Parameters:
      name - the label to get the child TreeNode from
      Returns:
      an Optional holding the result
    • toSlashCommandData

      public SlashCommandData toSlashCommandData(LocalizationFunction localization)

      Transforms this TreeNode into SlashCommandData.

      The children of this TreeNode will be added to the SlashCommandData either as SubcommandGroupData or SubcommandData depending on whether the children of this TreeNode also have children.

    • iterator

      public Iterator<TreeNode> iterator()
      Specified by:
      iterator in interface Iterable<TreeNode>
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • name

      public String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • command

      public SlashCommandDefinition command()
      Returns the value of the command record component.
      Returns:
      the value of the command record component
    • children

      public List<TreeNode> children()
      Returns the value of the children record component.
      Returns:
      the value of the children record component