Interface TreeAdapter<N>
- Type Parameters:
N- Node class.
Edges are not represented as objects.
It is the responsibility of implementation to ensure that the tree is consistent.
- Author:
- Damien Carbonne
-
Method Summary
Modifier and TypeMethodDescriptiondefault booleanareRelated(N node1, N node2, Strictness strictness) default booleanareRelatedOrEqual(N node1, N node2) default booleanareStrictlyRelated(N node1, N node2) default booleanareUnrelated(N node1, N node2) default booleancanSetParent(N node, N candidateParent) Returnstruewhen a node can be attached as a parent of another node.getChildren(N node) Returns an Iterable of children nodes.default intReturns the depth of a node.default NgetFirstCommonAncestor(N node1, N node2) Returns the first common ancestor of 2 nodes.default intReturns the height of the tree under a node.default intReturns the index of a child node in its parent's children.Returns the parent node of this node, possiblynull.default N[]default int[]Returns the qualified index of a node.default NodeRelativePositiongetRelativePosition(N node1, N node2) Returns the relative position of 2 nodes.default NReturns the root of a node.booleanhasChildren(N node) Returnstruewhen a node has children.default booleanReturnstruewhen a node is a leaf node.default booleanisOver(N node1, N node2, Strictness strictness) Returnstruewhen a first node is loosely or strictly over a second node.default booleanisOverOrEqual(N node1, N node2) Returnstruewhen a first node is over or equal to a second node.default booleanReturnstruewhen a node is a root node.default booleanisStrictlyOver(N node1, N node2) Returnstruewhen a first node is strictly over a second node.default booleanisStrictlyUnder(N node1, N node2) Returnstruewhen a first node is strictly under a second node.default booleanisUnder(N node1, N node2, Strictness strictness) Returnstruewhen a first node is loosely or strictly under a second node.default booleanisUnderOrEqual(N node1, N node2) Returnstruewhen a first node is under or equal to a second node.
-
Method Details
-
getParent
Returns the parent node of this node, possiblynull.- Parameters:
node- The node. MUST NOT benull.- Returns:
- The parent of node, or null.
-
getChildren
Returns an Iterable of children nodes.- Parameters:
node- The node. MUST NOT benull.- Returns:
- An Iterable of children nodes.
-
hasChildren
Returnstruewhen a node has children.This could be deduced from getChildren(), but may provide a better implementation.
- Parameters:
node- The node. MUST NOT benull.- Returns:
truewhen node has children.
-
getRoot
Returns the root of a node.It is the highest ancestor that has no parent.
It may be the node itself (when it is a root).- Parameters:
node- The node. MUST NOT be null.- Returns:
- The root of
node.
-
isRoot
Returnstruewhen a node is a root node.It is non null and has a null parent.
- Parameters:
node- The node.- Returns:
truewhennodeis a root.
-
isLeaf
Returnstruewhen a node is a leaf node.It is non null and has no children.
- Parameters:
node- The node.- Returns:
truewhennodeis a leaf.
-
getDepth
Returns the depth of a node.It is the number of edges between the node and the root.
Depth of root node is 0.- Parameters:
node- The node.- Returns:
- The depth of
node.
-
getHeight
Returns the height of the tree under a node.It is the number of edges on the longest downward path between that node and a leaf.
The height of a leaf node is 0.- Parameters:
node- The node. MUST NOT be null.- Returns:
- The height of the tree under
node.
-
getIndex
Returns the index of a child node in its parent's children.- Parameters:
node- The node.- Returns:
- The index of
node, or-1ifnodeis a root.
-
getQIndex
Returns the qualified index of a node.It is the array of indices of the node and its ancestors, excluding the root node.
A root node has an empty qindex.- Parameters:
node- The node.- Returns:
- The qualified index of
node
-
getFirstCommonAncestor
Returns the first common ancestor of 2 nodes.If nodes don't belong to the same tree or are null, returns null.
- Parameters:
node1- The first node.node2- The second node.- Returns:
- The first common ancestor of
node1andnode2.
-
isOverOrEqual
Returnstruewhen a first node is over or equal to a second node.- Parameters:
node1- The first node.node2- The second node.- Returns:
truewhennode1is over or equal tonode2.
-
isStrictlyOver
Returnstruewhen a first node is strictly over a second node.- Parameters:
node1- The first node.node2- The second node.- Returns:
truewhennode1is strictly overnode2.
-
isOver
Returnstruewhen a first node is loosely or strictly over a second node.- Parameters:
node1- The first node.node2- The second node.strictness- The strictness.- Returns:
truewhen anode1is loosely or strictly overnode2.
-
isUnderOrEqual
Returnstruewhen a first node is under or equal to a second node.- Parameters:
node1- The first node.node2- The second node.- Returns:
truewhennode1is under or equal tonode2.
-
isStrictlyUnder
Returnstruewhen a first node is strictly under a second node.- Parameters:
node1- The first node.node2- The second node.- Returns:
truewhennode1strictly undernode2.
-
isUnder
Returnstruewhen a first node is loosely or strictly under a second node.- Parameters:
node1- The first node.node2- The second node.strictness- The strictness.- Returns:
truewhen anode1is loosely or strictly undernode2.
-
areRelatedOrEqual
-
areStrictlyRelated
-
areRelated
-
getRelativePosition
Returns the relative position of 2 nodes.- Parameters:
node1- The first nodenode2- The second node.- Returns:
- The position of
node1relatively tonode2.
-
canSetParent
Returnstruewhen a node can be attached as a parent of another node.- Parameters:
node- The possible child.candidateParent- The possible parent.- Returns:
truewhencandidateParentcan be set as parent ofnode.
-
getPath
-