Class DefaultTreeNode<Self extends DefaultTreeNode<Self>>
java.lang.Object
org.keycloak.models.map.storage.tree.DefaultTreeNode<Self>
- All Implemented Interfaces:
TreeNode<Self>
- Direct Known Subclasses:
ModelCriteriaNode
,TreeStorageNodeInstance
,TreeStorageNodePrescription
public class DefaultTreeNode<Self extends DefaultTreeNode<Self>>
extends Object
implements TreeNode<Self>
Generic implementation of a node in a tree.
Any method that is not purely on tree or nodes should go into a specialized subclass of this class!
- Author:
- hmlnarik
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.keycloak.models.map.storage.tree.TreeNode
TreeNode.PathOrientation
-
Field Summary
Modifier and TypeFieldDescription -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a node as a child of this node, and sets the parent of thenode
to this node.void
Adds a node as a child of this node, and sets the parent of thenode
to this node.<RNode extends TreeNode<? super RNode>>
RNodeboolean
findFirstBfs
(Predicate<Self> visitor) Breadth-first search for a node.findFirstBottommostDfs
(Predicate<Self> visitor) Depth-first search for a node that is bottommost from those matching DFS.findFirstDfs
(Predicate<Self> visitor) Depth-first search for a node.void
forEachParent
(Consumer<Self> visitor) Calls the givenvisitor
on each node laying on the path from this node (exclusive) to the root of the tree (inclusive).Returns a node by ID.Returns the children of the current node.Parent-to-this-node edge properties.<V> Optional<V>
getEdgeProperty
(String key, Class<V> clazz) Convenience method for obtaining a single parent-to-this-node edge property.getId()
Returns ID of the node, which could match e.g.protected String
getLabel()
Properties of the this node.<V> Optional<V>
getNodeProperty
(String key, Class<V> clazz) Convenience method for obtaining a single property of this node.Returns parent node or an emptyOptional
if this node is a root node.Returns a stream of the nodes laying on the path from this node (exclusive) to the root of the tree (inclusive).getPathToRoot
(TreeNode.PathOrientation orientation) Returns the path (list of nodes) from this node to root node.Properties of the whole tree.<V> Optional<V>
getTreeProperty
(String key, Class<V> clazz) Convenience method for obtaining a single property of tree that this node belongs to.boolean
int
hashCode()
boolean
int
removeChild
(Predicate<Self> shouldRemove) Removes child nodes satisfying the given predicate.removeChild
(Self node) Removes the given child node.void
setEdgeProperty
(String property, Object value) void
void
setNodeProperty
(String property, Object value) void
Sets the parent node to the givenparent
.toString()
void
Walks the tree with the given visitor in breadth-first search manner.void
Walks the tree with the given visitor in depth-first search manner.
-
Field Details
-
nodeProperties
-
edgeProperties
-
treeProperties
-
-
Constructor Details
-
DefaultTreeNode
- Parameters:
treeProperties
- Reference to tree properties map. Tree properties are maintained outside of this node.
-
DefaultTreeNode
-
-
Method Details
-
getEdgeProperties
Description copied from interface:TreeNode
Parent-to-this-node edge properties. For example, import/no-import mode or sync mode belongs here.- Specified by:
getEdgeProperties
in interfaceTreeNode<Self extends DefaultTreeNode<Self>>
- Returns:
- Returns properties of the edge from the parent to this node. Never returns
null
.
-
getEdgeProperty
Description copied from interface:TreeNode
Convenience method for obtaining a single parent-to-this-node edge property.- Specified by:
getEdgeProperty
in interfaceTreeNode<Self extends DefaultTreeNode<Self>>
- Returns:
Optional
with a property value if it exists. Never returnsnull
-
setEdgeProperty
-
getNodeProperties
Description copied from interface:TreeNode
Properties of the this node. In storage context, properties of the single map storage represented by this node, for example read-only/read-write flag.- Specified by:
getNodeProperties
in interfaceTreeNode<Self extends DefaultTreeNode<Self>>
- Returns:
- Returns properties of the storage managed in this node. Never returns
null
.
-
getNodeProperty
Description copied from interface:TreeNode
Convenience method for obtaining a single property of this node.- Specified by:
getNodeProperty
in interfaceTreeNode<Self extends DefaultTreeNode<Self>>
- Returns:
Optional
with a property value if it exists. Never returnsnull
-
setNodeProperty
-
getTreeProperties
Description copied from interface:TreeNode
Properties of the whole tree. For example, kind of the stored objects, e.g. realms or clients.- Specified by:
getTreeProperties
in interfaceTreeNode<Self extends DefaultTreeNode<Self>>
- Returns:
- Returns properties of the tree that contains in this node. Never returns
null
.
-
getTreeProperty
Description copied from interface:TreeNode
Convenience method for obtaining a single property of tree that this node belongs to.- Specified by:
getTreeProperty
in interfaceTreeNode<Self extends DefaultTreeNode<Self>>
- Returns:
Optional
with a property value if it exists. Never returnsnull
-
getId
Description copied from interface:TreeNode
Returns ID of the node, which could match e.g. ID of the component with storage definition.- Specified by:
getId
in interfaceTreeNode<Self extends DefaultTreeNode<Self>>
- Returns:
- Node ID
-
setId
-
findFirstDfs
Description copied from interface:TreeNode
Depth-first search for a node.- Specified by:
findFirstDfs
in interfaceTreeNode<Self extends DefaultTreeNode<Self>>
- Parameters:
visitor
- Predicate on nodes, returnstrue
when a search condition is satisfied which terminates the search.- Returns:
- Leftmost first node that matches the predicate,
null
when no node matches.
-
findFirstBottommostDfs
Description copied from interface:TreeNode
Depth-first search for a node that is bottommost from those matching DFS.- Specified by:
findFirstBottommostDfs
in interfaceTreeNode<Self extends DefaultTreeNode<Self>>
- Parameters:
visitor
- Predicate on nodes, returnstrue
when a search condition is satisfied which terminates the search.- Returns:
- Leftmost and bottommost node that matches the predicate,
null
when no node matches.
-
findFirstBfs
Description copied from interface:TreeNode
Breadth-first search for a node.- Specified by:
findFirstBfs
in interfaceTreeNode<Self extends DefaultTreeNode<Self>>
- Parameters:
visitor
- Predicate on nodes, returnstrue
when a search condition is satisfied which terminates the search.- Returns:
- First node that matches the predicate,
null
when no node matches.
-
walkBfs
Description copied from interface:TreeNode
Walks the tree with the given visitor in breadth-first search manner.- Specified by:
walkBfs
in interfaceTreeNode<Self extends DefaultTreeNode<Self>>
-
walkDfs
Description copied from interface:TreeNode
Walks the tree with the given visitor in depth-first search manner.- Specified by:
walkDfs
in interfaceTreeNode<Self extends DefaultTreeNode<Self>>
- Parameters:
visitorUponEntry
- Visitor called upon entry of the node. May benull
, in that case no action is performed.visitorAfterChildrenVisited
- Visitor called before exit of the node. May benull
, in that case no action is performed.
-
forEachParent
Description copied from interface:TreeNode
Calls the givenvisitor
on each node laying on the path from this node (exclusive) to the root of the tree (inclusive).- Specified by:
forEachParent
in interfaceTreeNode<Self extends DefaultTreeNode<Self>>
-
getPathToRoot
Description copied from interface:TreeNode
Returns the path (list of nodes) from this node to root node.- Specified by:
getPathToRoot
in interfaceTreeNode<Self extends DefaultTreeNode<Self>>
- Parameters:
orientation
- Determines order of the nodes in the returned list - either this node is first and the root node is last, (TreeNode.PathOrientation.BOTTOM_FIRST
) or vice versa (TreeNode.PathOrientation.TOP_FIRST
).- Returns:
-
getChildren
Description copied from interface:TreeNode
Returns the children of the current node. Order does matter.- Specified by:
getChildren
in interfaceTreeNode<Self extends DefaultTreeNode<Self>>
- Returns:
- Read-only list of the children. Never returns
null
.
-
hasChildren
public boolean hasChildren() -
hasNoChildren
public boolean hasNoChildren() -
addChild
Description copied from interface:TreeNode
Adds a node as a child of this node, and sets the parent of thenode
to this node.- Specified by:
addChild
in interfaceTreeNode<Self extends DefaultTreeNode<Self>>
- Parameters:
node
- Future child node. Ifnull
or the node is already amongst the children list, no action is done.
-
addChild
Description copied from interface:TreeNode
Adds a node as a child of this node, and sets the parent of thenode
to this node.- Specified by:
addChild
in interfaceTreeNode<Self extends DefaultTreeNode<Self>>
- Parameters:
index
- Index at which the specified element is to be insertednode
- Future child node. Ifnull
or the node is already amongst the children list, no action is done.
-
getChild
Description copied from interface:TreeNode
Returns a node by ID. If there are more nodes with the same ID, any node from those may be returned.- Specified by:
getChild
in interfaceTreeNode<Self extends DefaultTreeNode<Self>>
- Returns:
-
removeChild
Description copied from interface:TreeNode
Removes child nodes satisfying the given predicate.- Specified by:
removeChild
in interfaceTreeNode<Self extends DefaultTreeNode<Self>>
- Returns:
- Number of removed nodes
-
removeChild
Description copied from interface:TreeNode
Removes the given child node.- Specified by:
removeChild
in interfaceTreeNode<Self extends DefaultTreeNode<Self>>
- Parameters:
node
- Node to remove- Returns:
- Removed node
-
getParent
Description copied from interface:TreeNode
Returns parent node or an emptyOptional
if this node is a root node.- Specified by:
getParent
in interfaceTreeNode<Self extends DefaultTreeNode<Self>>
- Returns:
- See description. Never returns
null
.
-
setParent
Description copied from interface:TreeNode
Sets the parent node to the givenparent
. If this node was a child of another node, also removes this node from the children of the previous parent.- Specified by:
setParent
in interfaceTreeNode<Self extends DefaultTreeNode<Self>>
- Parameters:
parent
- New parent node ornull
if this node should be parentless.
-
cloneTree
-
hashCode
public int hashCode() -
equals
-
getParentsStream
Description copied from interface:TreeNode
Returns a stream of the nodes laying on the path from this node (exclusive) to the root of the tree (inclusive).- Specified by:
getParentsStream
in interfaceTreeNode<Self extends DefaultTreeNode<Self>>
- Returns:
-
getLabel
-
toString
-