E - The type of the element to storepublic interface Node<E extends Comparable<E>> extends Iterable<Node<E>>, Comparable<Node<E>>
Tree. A node has exactly one parent
(which is null if the node is the Tree.getRootNode() of
the tree) and an arbitrary amount of child nodes.| Modifier and Type | Method and Description |
|---|---|
Node<E> |
addChild(E child)
Adds an element as a child to this node and returns the created node.
|
Node<E> |
findChild(E element)
Searches this node’s children recursively for a node that contains the
given element.
|
Node<E> |
getChild(E element)
Returns the direct child node that contains the given element.
|
Node<E> |
getChild(int index)
Returns the child at the given index.
|
E |
getElement()
Returns the element that is stored in the node.
|
int |
getIndexOfChild(E element)
Returns the index of the child node containing the given element.
|
int |
getIndexOfChild(Node<E> childNode)
Returns the index of the given child node.
|
Node<E> |
getParent()
Returns the parent node of the node.
|
boolean |
hasChild(E element)
Returns whether this node contains a child node containing the given
element.
|
boolean |
hasChild(Node<E> childNode)
Returns whether the given node is a direct child of this node.
|
Iterator<Node<E>> |
iterator() |
void |
removeAllChildren()
Removes all children from this node.
|
void |
removeChild(E child)
Removes the child node that contains the given element.
|
void |
removeChild(int childIndex)
Removes the child at the given index.
|
void |
removeChild(Node<E> childNode)
Remove the given child node from this node.
|
int |
size()
Returns the number of children this node has.
|
void |
sortChildren()
Sorts all children according to their natural order.
|
void |
sortChildren(Comparator<Node<E>> comparator)
Sorts all children with the given comparator.
|
forEach, spliteratorcompareToE getElement()
Node<E> addChild(E child)
child - The child node’s elementint size()
Node<E> getChild(int index)
index - The index of the childNode<E> getChild(E element)
element - The elementnull if this node does not have a child node
containing the given elementboolean hasChild(Node<E> childNode)
childNode - The child nodetrue if the given node is a direct child of this
node, false otherwiseboolean hasChild(E element)
element - The elementtrue if this node contains a direct child node
containing the given element, false otherwiseint getIndexOfChild(Node<E> childNode)
childNode - The child node-1 if the child node
is not a child node of this nodeint getIndexOfChild(E element)
element - The element-1 if the child node
is not a child node of this nodevoid removeChild(Node<E> childNode)
childNode - The child node to removevoid removeChild(E child)
Object.equals(Object).child - The child element to removevoid removeChild(int childIndex)
childIndex - The index of the child to removevoid removeAllChildren()
Node<E> findChild(E element)
element - The element to searchnull if
no node could be foundvoid sortChildren()
void sortChildren(Comparator<Node<E>> comparator)
comparator - The comparator used to sort the childrenCopyright © 2026. All rights reserved.