Class JpaNode<T extends NodeInfo>

java.lang.Object
sk.iway.iwcm.database.nestedsets.JpaNode<T>
All Implemented Interfaces:
Node<T>, NodeInfo

public class JpaNode<T extends NodeInfo> extends Object implements Node<T>
A decorator for a NodeInfo implementation that enriches it with the full API of a node in a nested set tree.
  • Constructor Details

  • Method Details

    • getId

      public int getId()
      Specified by:
      getId in interface NodeInfo
    • getLeftValue

      public int getLeftValue()
      Specified by:
      getLeftValue in interface NodeInfo
    • getRightValue

      public int getRightValue()
      Specified by:
      getRightValue in interface NodeInfo
    • getLevel

      public int getLevel()
      Specified by:
      getLevel in interface NodeInfo
    • getRootValue

      public int getRootValue()
      Specified by:
      getRootValue in interface NodeInfo
    • setRootValue

      public void setRootValue(int value)
      Specified by:
      setRootValue in interface NodeInfo
    • setLeftValue

      public void setLeftValue(int value)
      Specified by:
      setLeftValue in interface NodeInfo
    • setRightValue

      public void setRightValue(int value)
      Specified by:
      setRightValue in interface NodeInfo
    • setLevel

      public void setLevel(int level)
      Specified by:
      setLevel in interface NodeInfo
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hasChildren

      public boolean hasChildren()
      Tests if the node has any children.
      Specified by:
      hasChildren in interface Node<T extends NodeInfo>
      Returns:
      TRUE if the node has children, FALSE otherwise.
    • hasParent

      public boolean hasParent()
      Tests if the node has a parent. If it does not have a parent, it is a root node.
      Specified by:
      hasParent in interface Node<T extends NodeInfo>
      Returns:
      TRUE if this node has a parent node, FALSE otherwise.
    • isValid

      public boolean isValid()
      Tests whether the node is a valid node. A valid node is a node with a valid position in the tree, represented by its left, right and level values.
      Specified by:
      isValid in interface Node<T extends NodeInfo>
      Returns:
      TRUE if the node is valid, FALSE otherwise.
    • getNumberOfChildren

      public int getNumberOfChildren()
      Gets the number of children (direct descendants) of this node.
      Returns:
      The number of children of this node.
    • getNumberOfDescendants

      public int getNumberOfDescendants()
      Gets the number of descendants (children and their children etc.) of this node.
      Returns:
      The number of descendants of this node.
    • isRoot

      public boolean isRoot()
      Tests if this node is a root node.
      Specified by:
      isRoot in interface Node<T extends NodeInfo>
      Returns:
      TRUE if this node is a root node, FALSE otherwise.
    • getChildren

      public List<Node<T>> getChildren()
      Gets the children children of the node (direct descendants).
      Specified by:
      getChildren in interface Node<T extends NodeInfo>
      Returns:
      The children of the node.
    • getParent

      public Node<T> getParent()
      Gets the parent node of this node.
      Specified by:
      getParent in interface Node<T extends NodeInfo>
      Returns:
      The parent node or NULL if there is no parent node.
    • getDescendants

      public List<Node<T>> getDescendants()
      Gets the descendants of this node.
      Specified by:
      getDescendants in interface Node<T extends NodeInfo>
      Returns:
      The descendants of this node.
    • getDescendants

      public List<Node<T>> getDescendants(int depth)
      Gets descendants of this node, up to a certain depth.
      Specified by:
      getDescendants in interface Node<T extends NodeInfo>
      Returns:
      The descendants of the node, up to the specified depth.
    • addChild

      public Node<T> addChild(T child)
      Adds a node as the last child of this node.
      Specified by:
      addChild in interface Node<T extends NodeInfo>
      Parameters:
      child - The child to add.
      Returns:
      The newly inserted child node.
    • delete

      public void delete()
      Deletes the node and all its descendants from the tree.
      Specified by:
      delete in interface Node<T extends NodeInfo>
    • unwrap

      public T unwrap()
      Unwraps the node, returning the wrapped object.
      Specified by:
      unwrap in interface Node<T extends NodeInfo>
      Returns:
      The wrapped object.
    • isLeaf

      public boolean isLeaf()
      Determines if the node is a leaf node.
      Returns:
      TRUE if the node is a leaf, FALSE otherwise.
    • getFirstChild

      public Node<T> getFirstChild()
      Gets the first child node of this node.
      Specified by:
      getFirstChild in interface Node<T extends NodeInfo>
      Returns:
      The first child node of this node.
    • getLastChild

      public Node<T> getLastChild()
      Gets the last child node of this node.
      Specified by:
      getLastChild in interface Node<T extends NodeInfo>
      Returns:
      The last child node.
    • getAncestors

      public List<Node<T>> getAncestors()
      Gets all ancestors of this node.
      Specified by:
      getAncestors in interface Node<T extends NodeInfo>
      Returns:
      The ancestors of the node.
    • isDescendantOf

      public boolean isDescendantOf(Node<T> subj)
      Determines if this node is a descendant of the given node.
      Specified by:
      isDescendantOf in interface Node<T extends NodeInfo>
      Returns:
      TRUE if this node is a descendant of the given node, FALSE otherwise.
    • getPath

      public String getPath(String seperator)
    • moveAsPrevSiblingOf

      public void moveAsPrevSiblingOf(Node<T> dest)
      Moves this node as the previous sibling of the given node.
      Specified by:
      moveAsPrevSiblingOf in interface Node<T extends NodeInfo>
    • moveAsNextSiblingOf

      public void moveAsNextSiblingOf(Node<T> dest)
      Moves this node in the tree, positioning it as the successive sibling of the given node.
      Specified by:
      moveAsNextSiblingOf in interface Node<T extends NodeInfo>
    • moveAsFirstChildOf

      public void moveAsFirstChildOf(Node<T> dest)
      Moves this node in the tree, positioning it as the first child of the given node.
      Specified by:
      moveAsFirstChildOf in interface Node<T extends NodeInfo>
    • moveAsLastChildOf

      public void moveAsLastChildOf(Node<T> dest)
      Moves this node in the tree, positioning it as the last child of the given node.
      Specified by:
      moveAsLastChildOf in interface Node<T extends NodeInfo>
    • makeRoot

      public void makeRoot(int newRootId)
      Makes this node a root node. Only used in multiple-root trees.
      Parameters:
      newRootId -
    • setOfflineNode

      public void setOfflineNode(boolean offlineNode)