Record Class TreeNode
java.lang.Object
java.lang.Record
com.github.kaktushose.jda.commands.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()
Constructs an empty TreeNode.TreeNode
(@NotNull String name, @Nullable SlashCommandDefinition command) Constructs a new TreeNode.TreeNode
(String name, SlashCommandDefinition command, List<TreeNode> children) Creates an instance of aTreeNode
record class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addChild
(@NotNull String[] labels, @NotNull SlashCommandDefinition command) children()
Returns the value of thechildren
record component.command()
Returns the value of thecommand
record component.final boolean
Indicates whether some other object is "equal to" this one.Gets a childTreeNode
based on its name.Gets all childrenTreeNode
s.Gets theSlashCommandDefinition
of thisTreeNode
.List
<net.dv8tion.jda.api.interactions.commands.build.SlashCommandData> Gets all of the leaf nodes.getName()
Gets the name of theSlashCommandDefinition
of thisTreeNode
.getNames()
Gets all names of the leaf nodes.boolean
Gets whether thisTreeNode
has children.final int
hashCode()
Returns a hash code value for this object.iterator()
name()
Returns the value of thename
record component.toString()
Returns a string representation of this record class.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
TreeNode
public TreeNode()Constructs an empty TreeNode. Should only be used for root nodes. -
TreeNode
Constructs a new TreeNode.- Parameters:
name
- the name of the commandcommand
- theSlashCommandDefinition
-
TreeNode
Creates an instance of aTreeNode
record class.- Parameters:
name
- the value for thename
record componentcommand
- the value for thecommand
record componentchildren
- the value for thechildren
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 thisTreeNode
or to one of its children based on the amount of labels.For instance
labels[0]
will be added as a childTreeNode
to thisTreeNode
,labels[1]
will be added as a child to the childTreeNode
created fromlabels[0]
and so on.This guarantees to create a
CommandTree
that respects Subcommands and SubcommandGroups.- Parameters:
labels
- an Array of all labels, can be emptycommand
- theSlashCommandDefinition
to add
-
getChild
-
getName
Gets the name of theSlashCommandDefinition
of thisTreeNode
.- Returns:
- the name of the
SlashCommandDefinition
-
getChildren
-
hasChildren
-
getCommand
Gets theSlashCommandDefinition
of thisTreeNode
. Returns an emptyOptional
if one or more children exist or if theSlashCommandDefinition
isnull
.- Returns:
- an
Optional
holding the result
-
getNames
-
getCommandData
-
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 thename
record component.- Returns:
- the value of the
name
record component
-
command
Returns the value of thecommand
record component.- Returns:
- the value of the
command
record component
-
children
-