Interface TreeAdapter<N>
-
- Type Parameters:
N- Node class.
public interface TreeAdapter<N>Interface giving access to a lightweight directed tree.Edges are not represented as objects.
It is the responsibility of implementation to ensure that the tree is consistent.- Author:
- Damien Carbonne
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default 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.Iterable<N>getChildren(N node)Returns an Iterable of children nodes.default intgetDepth(N node)Returns the depth of a node.default NgetFirstCommonAncestor(N node1, N node2)Returns the first common ancestor of 2 nodes.default intgetHeight(N node)Returns the height of the tree under a node.default intgetIndex(N node)Returns the index of a child node in its parent's children.NgetParent(N node)Returns the parent node of this node, possiblynull.default N[]getPath(N node)default int[]getQIndex(N node)Returns the qualified index of a node.default NodeRelativePositiongetRelativePosition(N node1, N node2)Returns the relative position of 2 nodes.default NgetRoot(N node)Returns the root of a node.booleanhasChildren(N node)Returnstruewhen a node has children.default booleanisLeaf(N node)Returnstruewhen 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 booleanisRoot(N node)Returnstruewhen 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 Detail
-
getParent
N getParent(N node)
Returns the parent node of this node, possiblynull.- Parameters:
node- The node. MUST NOT benull.- Returns:
- The parent of node, or null.
-
getChildren
Iterable<N> getChildren(N node)
Returns an Iterable of children nodes.- Parameters:
node- The node. MUST NOT benull.- Returns:
- An Iterable of children nodes.
-
hasChildren
boolean hasChildren(N node)
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
default N getRoot(N node)
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
default boolean isRoot(N node)
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
default boolean isLeaf(N node)
Returnstruewhen a node is a leaf node.It is non null and has no children.
- Parameters:
node- The node.- Returns:
truewhennodeis a leaf.
-
getDepth
default int getDepth(N node)
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
default int getHeight(N node)
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
default int getIndex(N node)
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
default int[] getQIndex(N node)
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
default N getFirstCommonAncestor(N node1, N node2)
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
default boolean isOverOrEqual(N node1, N node2)
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
default boolean isStrictlyOver(N node1, N node2)
Returnstruewhen a first node is strictly over a second node.- Parameters:
node1- The first node.node2- The second node.- Returns:
truewhennode1is strictly overnode2.
-
isOver
default boolean isOver(N node1, N node2, Strictness strictness)
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
default boolean isUnderOrEqual(N node1, N node2)
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
default boolean isStrictlyUnder(N node1, N node2)
Returnstruewhen a first node is strictly under a second node.- Parameters:
node1- The first node.node2- The second node.- Returns:
truewhennode1strictly undernode2.
-
isUnder
default boolean isUnder(N node1, N node2, Strictness strictness)
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.
-
areRelated
default boolean areRelated(N node1, N node2, Strictness strictness)
-
getRelativePosition
default NodeRelativePosition getRelativePosition(N node1, N node2)
Returns the relative position of 2 nodes.- Parameters:
node1- The first nodenode2- The second node.- Returns:
- The position of
node1relatively tonode2.
-
canSetParent
default boolean canSetParent(N node, N candidateParent)
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.
-
-