In usual implementations, nodes function as wrappers around a data object. Thus normally they have a value property
which allows access to the value stored in the node.
In contrast to this approach, the ChainNode<T> class is designed to be used as a base class which provides the
tree traversing functionality via inheritance.
Example usage:
private class BasicChainNode extends ChainNode<BasicChainNode> { public BasicChainNode() { super(BasicChainNode.class); } }
| Modifier and Type | Field and Description |
|---|---|
| private @Nullable T | child
This node's child, or null if this node has no child |
| private @Nullable T | parent
This node's parent, or null if this node has no parent |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public Optional | Returns: this node's child T, or an empty Optional if this node has no childReturns this node's child or an empty Optional if this node has no child. |
| public Optional | Returns: this node's parent T, or an empty Optional if this node has no parentReturns this node's parent or an empty Optional if this node has no parent. |
| public boolean | Returns: true if anotherNode is a descendant of this nodenode to test anotherNode)Returns true if this node is an ancestor of the given node. |
| public void | moveTo(T
the new parent target)Removes this node from its parent and makes it a child of the specified node. |
| public void | |
| public T | |
| protected void |
| child | back to summary |
|---|---|
| private @Nullable T child This node's child, or null if this node has no child | |
| parent | back to summary |
|---|---|
| private @Nullable T parent This node's parent, or null if this node has no parent | |
| ChainNode | back to summary |
|---|---|
| public ChainNode(Class<T> derivingClass) Constructs a chain node without parent and no child.
| |
| addAtEnd | back to summary |
|---|---|
| public void addAtEnd(T node) Adds the given node at the end of the chain. E.g., "A > B > C" + "D" -> "A > B > C > D". | |
| getChild | back to summary |
|---|---|
| public Optional Returns this node's child or an empty Optional if this node has no child.
| |
| getParent | back to summary |
|---|---|
| public Optional Returns this node's parent or an empty Optional if this node has no parent.
| |
| isAncestorOf | back to summary |
|---|---|
| public boolean isAncestorOf(T anotherNode) Returns true if this node is an ancestor of the given node. A node is considered an ancestor of itself.
| |
| moveTo | back to summary |
|---|---|
| public void moveTo(T target) Removes this node from its parent and makes it a child of the specified node. In this way the whole subchain based at this node is moved to the given node.
| |
| removeChild | back to summary |
|---|---|
| public void removeChild() Removes the child from this node's child list, giving it an empty parent. | |
| setChild | back to summary |
|---|---|
| public T setChild(T child) Adds the node as the child. Also sets the parent of the given node to this node. The given node is not allowed to already be in a tree (i.e. it has to have no parent).
| |
| setParent | back to summary |
|---|---|
| protected void setParent(@Nullable T parent) Sets the parent node of this node. This method does not set this node as the child of the new parent, nor does it remove this node
from the old parent. You should probably call
| |