Package cdc.graphs

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

    Modifier and Type
    Method
    Description
    default boolean
    areRelated(N node1, N node2, Strictness strictness)
     
    default boolean
    areRelatedOrEqual(N node1, N node2)
     
    default boolean
    areStrictlyRelated(N node1, N node2)
     
    default boolean
    areUnrelated(N node1, N node2)
     
    default boolean
    canSetParent(N node, N candidateParent)
    Returns true when a node can be attached as a parent of another node.
    getChildren(N node)
    Returns an Iterable of children nodes.
    default int
    getDepth(N node)
    Returns the depth of a node.
    default N
    getFirstCommonAncestor(N node1, N node2)
    Returns the first common ancestor of 2 nodes.
    default int
    getHeight(N node)
    Returns the height of the tree under a node.
    default int
    getIndex(N node)
    Returns the index of a child node in its parent's children.
    getParent(N node)
    Returns the parent node of this node, possibly null.
    default N[]
    getPath(N node)
     
    default int[]
    getQIndex(N node)
    Returns the qualified index of a node.
    getRelativePosition(N node1, N node2)
    Returns the relative position of 2 nodes.
    default N
    getRoot(N node)
    Returns the root of a node.
    boolean
    hasChildren(N node)
    Returns true when a node has children.
    default boolean
    isLeaf(N node)
    Returns true when a node is a leaf node.
    default boolean
    isOver(N node1, N node2, Strictness strictness)
    Returns true when a first node is loosely or strictly over a second node.
    default boolean
    isOverOrEqual(N node1, N node2)
    Returns true when a first node is over or equal to a second node.
    default boolean
    isRoot(N node)
    Returns true when a node is a root node.
    default boolean
    isStrictlyOver(N node1, N node2)
    Returns true when a first node is strictly over a second node.
    default boolean
    isStrictlyUnder(N node1, N node2)
    Returns true when a first node is strictly under a second node.
    default boolean
    isUnder(N node1, N node2, Strictness strictness)
    Returns true when a first node is loosely or strictly under a second node.
    default boolean
    isUnderOrEqual(N node1, N node2)
    Returns true when a first node is under or equal to a second node.
  • Method Details

    • getParent

      N getParent(N node)
      Returns the parent node of this node, possibly null.
      Parameters:
      node - The node. MUST NOT be null.
      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 be null.
      Returns:
      An Iterable of children nodes.
    • hasChildren

      boolean hasChildren(N node)
      Returns true when a node has children.

      This could be deduced from getChildren(), but may provide a better implementation.

      Parameters:
      node - The node. MUST NOT be null.
      Returns:
      true when 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)
      Returns true when a node is a root node.

      It is non null and has a null parent.

      Parameters:
      node - The node.
      Returns:
      true when node is a root.
    • isLeaf

      default boolean isLeaf(N node)
      Returns true when a node is a leaf node.

      It is non null and has no children.

      Parameters:
      node - The node.
      Returns:
      true when node is 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 -1 if node is 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 node1 and node2.
    • isOverOrEqual

      default boolean isOverOrEqual(N node1, N node2)
      Returns true when a first node is over or equal to a second node.
      Parameters:
      node1 - The first node.
      node2 - The second node.
      Returns:
      true when node1 is over or equal to node2.
    • isStrictlyOver

      default boolean isStrictlyOver(N node1, N node2)
      Returns true when a first node is strictly over a second node.
      Parameters:
      node1 - The first node.
      node2 - The second node.
      Returns:
      true when node1 is strictly over node2.
    • isOver

      default boolean isOver(N node1, N node2, Strictness strictness)
      Returns true when a first node is loosely or strictly over a second node.
      Parameters:
      node1 - The first node.
      node2 - The second node.
      strictness - The strictness.
      Returns:
      true when a node1 is loosely or strictly over node2.
    • isUnderOrEqual

      default boolean isUnderOrEqual(N node1, N node2)
      Returns true when a first node is under or equal to a second node.
      Parameters:
      node1 - The first node.
      node2 - The second node.
      Returns:
      true when node1 is under or equal to node2.
    • isStrictlyUnder

      default boolean isStrictlyUnder(N node1, N node2)
      Returns true when a first node is strictly under a second node.
      Parameters:
      node1 - The first node.
      node2 - The second node.
      Returns:
      true when node1 strictly under node2.
    • isUnder

      default boolean isUnder(N node1, N node2, Strictness strictness)
      Returns true when a first node is loosely or strictly under a second node.
      Parameters:
      node1 - The first node.
      node2 - The second node.
      strictness - The strictness.
      Returns:
      true when a node1 is loosely or strictly under node2.
    • areRelatedOrEqual

      default boolean areRelatedOrEqual(N node1, N node2)
    • areStrictlyRelated

      default boolean areStrictlyRelated(N node1, N node2)
    • areRelated

      default boolean areRelated(N node1, N node2, Strictness strictness)
    • areUnrelated

      default boolean areUnrelated(N node1, N node2)
    • getRelativePosition

      default NodeRelativePosition getRelativePosition(N node1, N node2)
      Returns the relative position of 2 nodes.
      Parameters:
      node1 - The first node
      node2 - The second node.
      Returns:
      The position of node1 relatively to node2.
    • canSetParent

      default boolean canSetParent(N node, N candidateParent)
      Returns true when a node can be attached as a parent of another node.
      Parameters:
      node - The possible child.
      candidateParent - The possible parent.
      Returns:
      true when candidateParent can be set as parent of node.
    • getPath

      default N[] getPath(N node)