Package sk.iway.iwcm.database.nestedsets
Class JpaNode<T extends NodeInfo>
java.lang.Object
sk.iway.iwcm.database.nestedsets.JpaNode<T>
A decorator for a
NodeInfo
implementation that enriches it with the
full API of a node in a nested set tree.-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds a node as the last child of this node.void
delete()
Deletes the node and all its descendants from the tree.Gets all ancestors of this node.Gets the children children of the node (direct descendants).Gets the descendants of this node.getDescendants
(int depth) Gets descendants of this node, up to a certain depth.Gets the first child node of this node.int
getId()
Gets the last child node of this node.int
int
getLevel()
int
Gets the number of children (direct descendants) of this node.int
Gets the number of descendants (children and their children etc.) of this node.Gets the parent node of this node.int
int
boolean
Tests if the node has any children.boolean
Tests if the node has a parent.boolean
isDescendantOf
(Node<T> subj) Determines if this node is a descendant of the given node.boolean
isLeaf()
Determines if the node is a leaf node.boolean
isRoot()
Tests if this node is a root node.boolean
isValid()
Tests whether the node is a valid node.void
makeRoot
(int newRootId) Makes this node a root node.void
moveAsFirstChildOf
(Node<T> dest) Moves this node in the tree, positioning it as the first child of the given node.void
moveAsLastChildOf
(Node<T> dest) Moves this node in the tree, positioning it as the last child of the given node.void
moveAsNextSiblingOf
(Node<T> dest) Moves this node in the tree, positioning it as the successive sibling of the given node.void
moveAsPrevSiblingOf
(Node<T> dest) Moves this node as the previous sibling of the given node.void
setLeftValue
(int value) void
setLevel
(int level) void
setOfflineNode
(boolean offlineNode) void
setRightValue
(int value) void
setRootValue
(int value) toString()
unwrap()
Unwraps the node, returning the wrapped object.
-
Constructor Details
-
JpaNode
-
-
Method Details
-
getId
public int getId() -
getLeftValue
public int getLeftValue()- Specified by:
getLeftValue
in interfaceNodeInfo
-
getRightValue
public int getRightValue()- Specified by:
getRightValue
in interfaceNodeInfo
-
getLevel
public int getLevel() -
getRootValue
public int getRootValue()- Specified by:
getRootValue
in interfaceNodeInfo
-
setRootValue
public void setRootValue(int value) - Specified by:
setRootValue
in interfaceNodeInfo
-
setLeftValue
public void setLeftValue(int value) - Specified by:
setLeftValue
in interfaceNodeInfo
-
setRightValue
public void setRightValue(int value) - Specified by:
setRightValue
in interfaceNodeInfo
-
setLevel
public void setLevel(int level) -
toString
-
hasChildren
public boolean hasChildren()Tests if the node has any children.- Specified by:
hasChildren
in interfaceNode<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. -
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. -
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. -
getChildren
Gets the children children of the node (direct descendants).- Specified by:
getChildren
in interfaceNode<T extends NodeInfo>
- Returns:
- The children of the node.
-
getParent
Gets the parent node of this node. -
getDescendants
Gets the descendants of this node.- Specified by:
getDescendants
in interfaceNode<T extends NodeInfo>
- Returns:
- The descendants of this node.
-
getDescendants
Gets descendants of this node, up to a certain depth.- Specified by:
getDescendants
in interfaceNode<T extends NodeInfo>
- Returns:
- The descendants of the node, up to the specified depth.
-
addChild
Adds a node as the last child of this node. -
delete
public void delete()Deletes the node and all its descendants from the tree. -
unwrap
Unwraps the node, returning 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
Gets the first child node of this node.- Specified by:
getFirstChild
in interfaceNode<T extends NodeInfo>
- Returns:
- The first child node of this node.
-
getLastChild
Gets the last child node of this node.- Specified by:
getLastChild
in interfaceNode<T extends NodeInfo>
- Returns:
- The last child node.
-
getAncestors
Gets all ancestors of this node.- Specified by:
getAncestors
in interfaceNode<T extends NodeInfo>
- Returns:
- The ancestors of the node.
-
isDescendantOf
Determines if this node is a descendant of the given node.- Specified by:
isDescendantOf
in interfaceNode<T extends NodeInfo>
- Returns:
- TRUE if this node is a descendant of the given node, FALSE otherwise.
-
getPath
-
moveAsPrevSiblingOf
Moves this node as the previous sibling of the given node.- Specified by:
moveAsPrevSiblingOf
in interfaceNode<T extends NodeInfo>
-
moveAsNextSiblingOf
Moves this node in the tree, positioning it as the successive sibling of the given node.- Specified by:
moveAsNextSiblingOf
in interfaceNode<T extends NodeInfo>
-
moveAsFirstChildOf
Moves this node in the tree, positioning it as the first child of the given node.- Specified by:
moveAsFirstChildOf
in interfaceNode<T extends NodeInfo>
-
moveAsLastChildOf
Moves this node in the tree, positioning it as the last child of the given node.- Specified by:
moveAsLastChildOf
in interfaceNode<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)
-