Record Class TreeNode
java.lang.Object
java.lang.Record
io.github.kaktushose.jdac.internal.register.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 Summary
ConstructorsConstructorDescriptionTreeNode(String name, SlashCommandDefinition command) Constructs a new TreeNode.TreeNode(String name, SlashCommandDefinition command, List<TreeNode> children) Creates an instance of aTreeNoderecord class. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChild(String[] labels, SlashCommandDefinition command) children()Returns the value of thechildrenrecord component.command()Returns the value of thecommandrecord component.final booleanIndicates whether some other object is "equal to" this one.Gets a childTreeNodebased on its name.final inthashCode()Returns a hash code value for this object.iterator()name()Returns the value of thenamerecord component.toSlashCommandData(LocalizationFunction localization) Transforms thisTreeNodeintoSlashCommandData.toString()Returns a string representation of this record class.Methods inherited from interface Iterable
forEach, spliterator
-
Constructor Details
-
TreeNode
Constructs a new TreeNode.- Parameters:
name- the name of the commandcommand- theSlashCommandDefinition
-
TreeNode
Creates an instance of aTreeNoderecord class.- Parameters:
name- the value for thenamerecord componentcommand- the value for thecommandrecord componentchildren- the value for thechildrenrecord component
-
-
Method Details
-
addChild
Attempts to add a childTreeNodeeither as a child of thisTreeNodeor to one of its children based on the given labels.- Parameters:
labels- an Array of all labels, can be emptycommand- theSlashCommandDefinitionto 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
CommandTreethat respects Subcommands and SubcommandGroups.
-
getChild
-
toSlashCommandData
Transforms this
TreeNodeintoSlashCommandData.The children of this
TreeNodewill be added to theSlashCommandDataeither asSubcommandGroupDataorSubcommandDatadepending on whether the children of thisTreeNodealso have children. -
iterator
-
toString
-
hashCode
-
equals
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 withObjects::equals(Object,Object). -
name
Returns the value of thenamerecord component.- Returns:
- the value of the
namerecord component
-
command
Returns the value of thecommandrecord component.- Returns:
- the value of the
commandrecord component
-
children
-