Record Class TreeNode

java.lang.Object
java.lang.Record
com.github.kaktushose.jda.commands.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()
      Constructs an empty TreeNode. Should only be used for root nodes.
    • TreeNode

      public TreeNode(@NotNull @NotNull String name, @Nullable @Nullable 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(@NotNull @NotNull String[] labels, @NotNull @NotNull SlashCommandDefinition command)

      Adds a child TreeNode either as a child of this TreeNode or to one of its children based on the amount of labels.

      For instance labels[0] will be added as a child TreeNode to this TreeNode, labels[1] will be added as a child to the child TreeNode created from labels[0] and so on.

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

      Parameters:
      labels - an Array of all labels, can be empty
      command - the SlashCommandDefinition to add
    • 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
    • getName

      public String getName()
      Gets the name of the SlashCommandDefinition of this TreeNode.
      Returns:
      the name of the SlashCommandDefinition
    • getChildren

      public List<TreeNode> getChildren()
      Gets all children TreeNodes.
      Returns:
      all children TreeNodes
    • hasChildren

      public boolean hasChildren()
      Gets whether this TreeNode has children.
      Returns:
      true if this TreeNode has children
    • getCommand

      public Optional<SlashCommandDefinition> getCommand()
      Gets the SlashCommandDefinition of this TreeNode. Returns an empty Optional if one or more children exist or if the SlashCommandDefinition is null.
      Returns:
      an Optional holding the result
    • getNames

      public List<String> getNames()
      Gets all names of the leaf nodes.
      Returns:
      a List of all names of the leaf nodes.
    • getCommandData

      public List<net.dv8tion.jda.api.interactions.commands.build.SlashCommandData> getCommandData()
      Gets all of the leaf nodes.
      Returns:
      a List of SlashCommandData
    • iterator

      @NotNull public @NotNull 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