Package org.gnome.glib
Class Node
java.lang.Object
org.javagi.base.ProxyInstance
org.gnome.glib.Node
-
Constructor Summary
ConstructorsConstructorDescriptionNode()Allocate a new Node.Allocate a new Node.Node(MemorySegment address) Create a Node proxy instance for the provided memory address.Allocate a new Node with the fields set to the provided values.Allocate a new Node with the fields set to the provided values. -
Method Summary
Modifier and TypeMethodDescriptionintchildIndex(@Nullable MemorySegment data) Gets the position of the first child of aGNodewhich contains the given data.intchildPosition(Node child) Gets the position of aGNodewith respect to its siblings.voidchildrenForeach(Set<TraverseFlags> flags, @Nullable NodeForeachFunc func) Calls a function for each of the children of aGNode.voidchildrenForeach(TraverseFlags flags, @Nullable NodeForeachFunc func) Calls a function for each of the children of aGNode.copy()Recursively copies aGNode(but does not deep-copy the data inside the nodes, see g_node_copy_deep() if you need that).Recursively copies aGNodeand its data.intdepth()Gets the depth of aGNode.voiddestroy()Removes this Node and its children from the tree, freeing any memory allocated.find(TraverseType order, Set<TraverseFlags> flags, @Nullable MemorySegment data) Finds aGNodein a tree.find(TraverseType order, TraverseFlags flags, @Nullable MemorySegment data) Finds aGNodein a tree.findChild(Set<TraverseFlags> flags, @Nullable MemorySegment data) Finds the first child of aGNodewith the given data.findChild(TraverseFlags flags, @Nullable MemorySegment data) Finds the first child of aGNodewith the given data.Gets the first sibling of aGNode.static MemoryLayoutThe memory layout of the native struct.getRoot()Gets the root of a tree.Inserts aGNodebeneath the parent at the given position.insertAfter(Node sibling, Node node) Inserts aGNodebeneath the parent after the given sibling.insertBefore(Node sibling, Node node) Inserts aGNodebeneath the parent before the given sibling.booleanisAncestor(Node descendant) Returnstrueif this Node is an ancestor ofdescendant.This is true if node is the parent ofdescendant,or if node is the grandparent ofdescendantetc.Gets the last child of aGNode.Gets the last sibling of aGNode.intGets the maximum height of all branches beneath aGNode.intGets the number of children of aGNode.static Nodenew_(@Nullable MemorySegment data) Creates a newGNodecontaining the given data.intnNodes(Set<TraverseFlags> flags) Gets the number of nodes in a tree.intnNodes(TraverseFlags... flags) Gets the number of nodes in a tree.nthChild(int n) Gets a child of aGNode, using the given index.static voidDeprecated.Inserts aGNodeas the first child of the given parent.static voidpushAllocator(Allocator allocator) Deprecated.Read the value of the fieldchildren.readData()Read the value of the fielddata.readNext()Read the value of the fieldnext.Read the value of the fieldparent.readPrev()Read the value of the fieldprev.voidReverses the order of the children of aGNode.voidtraverse(TraverseType order, Set<TraverseFlags> flags, int maxDepth, @Nullable NodeTraverseFunc func) Traverses a tree starting at the given rootGNode.voidtraverse(TraverseType order, TraverseFlags flags, int maxDepth, @Nullable NodeTraverseFunc func) Traverses a tree starting at the given rootGNode.voidunlink()Unlinks aGNodefrom a tree, resulting in two separate trees.voidwriteChildren(Node children) Write a value in the fieldchildren.voidwriteData(MemorySegment data) Write a value in the fielddata.voidWrite a value in the fieldnext.voidwriteParent(Node parent) Write a value in the fieldparent.voidWrite a value in the fieldprev.Methods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Node
Create a Node proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
Node
Allocate a new Node.- Parameters:
arena- to control the memory allocation scope
-
Node
public Node()Allocate a new Node. The memory is allocated withArena.ofAuto(). -
Node
Allocate a new Node with the fields set to the provided values.- Parameters:
data- value for the fielddatanext- value for the fieldnextprev- value for the fieldprevparent- value for the fieldparentchildren- value for the fieldchildrenarena- to control the memory allocation scope
-
Node
Allocate a new Node with the fields set to the provided values. The memory is allocated withArena.ofAuto().- Parameters:
data- value for the fielddatanext- value for the fieldnextprev- value for the fieldprevparent- value for the fieldparentchildren- value for the fieldchildren
-
-
Method Details
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
readData
Read the value of the fielddata.- Returns:
- The value of the field
data
-
writeData
Write a value in the fielddata.- Parameters:
data- The new value for the fielddata
-
readNext
-
writeNext
Write a value in the fieldnext.- Parameters:
next- The new value for the fieldnext
-
readPrev
-
writePrev
Write a value in the fieldprev.- Parameters:
prev- The new value for the fieldprev
-
readParent
-
writeParent
Write a value in the fieldparent.- Parameters:
parent- The new value for the fieldparent
-
readChildren
Read the value of the fieldchildren.- Returns:
- The value of the field
children
-
writeChildren
Write a value in the fieldchildren.- Parameters:
children- The new value for the fieldchildren
-
new_
Creates a newGNodecontaining the given data. Used to create the first node in a tree.- Parameters:
data- the data of the new node- Returns:
- a new
GNode
-
popAllocator
Deprecated. -
pushAllocator
Deprecated. -
childIndex
Gets the position of the first child of aGNodewhich contains the given data.- Parameters:
data- the data to find- Returns:
- the index of the child of this Node which contains
data,or -1 if the data is not found
-
childPosition
Gets the position of aGNodewith respect to its siblings.childmust be a child ofnode.The first child is numbered 0, the second 1, and so on.- Parameters:
child- a child of this Node- Returns:
- the position of
childwith respect to its siblings
-
childrenForeach
Calls a function for each of the children of aGNode. Note that it doesn't descend beneath the child nodes.funcmust not do anything that would modify the structure of the tree.- Parameters:
flags- which types of children are to be visited, one ofTraverseFlags.ALL,TraverseFlags.LEAVESandTraverseFlags.NON_LEAVESfunc- the function to call for each visited node
-
childrenForeach
Calls a function for each of the children of aGNode. Note that it doesn't descend beneath the child nodes.funcmust not do anything that would modify the structure of the tree.- Parameters:
flags- which types of children are to be visited, one ofTraverseFlags.ALL,TraverseFlags.LEAVESandTraverseFlags.NON_LEAVESfunc- the function to call for each visited node
-
copy
Recursively copies aGNode(but does not deep-copy the data inside the nodes, see g_node_copy_deep() if you need that).- Returns:
- a new
GNodecontaining the same data pointers
-
copyDeep
-
depth
public int depth()Gets the depth of aGNode.If this Node is
nullthe depth is 0. The root node has a depth of 1. For the children of the root node the depth is 2. And so on.- Returns:
- the depth of the
GNode
-
destroy
public void destroy()Removes this Node and its children from the tree, freeing any memory allocated. -
find
Finds aGNodein a tree.- Parameters:
order- the order in which nodes are visited -TraverseType.IN_ORDER,TraverseType.PRE_ORDER,TraverseType.POST_ORDER, orTraverseType.LEVEL_ORDERflags- which types of children are to be searched, one ofTraverseFlags.ALL,TraverseFlags.LEAVESandTraverseFlags.NON_LEAVESdata- the data to find- Returns:
- the found
GNode, ornullif the data is not found
-
find
Finds aGNodein a tree.- Parameters:
order- the order in which nodes are visited -TraverseType.IN_ORDER,TraverseType.PRE_ORDER,TraverseType.POST_ORDER, orTraverseType.LEVEL_ORDERflags- which types of children are to be searched, one ofTraverseFlags.ALL,TraverseFlags.LEAVESandTraverseFlags.NON_LEAVESdata- the data to find- Returns:
- the found
GNode, ornullif the data is not found
-
findChild
Finds the first child of aGNodewith the given data.- Parameters:
flags- which types of children are to be searched, one ofTraverseFlags.ALL,TraverseFlags.LEAVESandTraverseFlags.NON_LEAVESdata- the data to find- Returns:
- the found child
GNode, ornullif the data is not found
-
findChild
Finds the first child of aGNodewith the given data.- Parameters:
flags- which types of children are to be searched, one ofTraverseFlags.ALL,TraverseFlags.LEAVESandTraverseFlags.NON_LEAVESdata- the data to find- Returns:
- the found child
GNode, ornullif the data is not found
-
firstSibling
Gets the first sibling of aGNode. This could possibly be the node itself.- Returns:
- the first sibling of this Node
-
getRoot
-
insert
Inserts aGNodebeneath the parent at the given position.- Parameters:
position- the position to placenodeat, with respect to its siblings If position is -1,nodeis inserted as the last child of this Nodenode- theGNodeto insert- Returns:
- the inserted
GNode
-
insertAfter
-
insertBefore
-
isAncestor
Returnstrueif this Node is an ancestor ofdescendant.This is true if node is the parent ofdescendant,or if node is the grandparent ofdescendantetc.- Parameters:
descendant- aGNode- Returns:
trueif this Node is an ancestor ofdescendant
-
lastChild
Gets the last child of aGNode.- Returns:
- the last child of
node,ornullif this Node has no children
-
lastSibling
Gets the last sibling of aGNode. This could possibly be the node itself.- Returns:
- the last sibling of this Node
-
maxHeight
public int maxHeight()Gets the maximum height of all branches beneath aGNode. This is the maximum distance from theGNodeto all leaf nodes.If this Node is
null, 0 is returned. If this Node has no children, 1 is returned. If this Node has children, 2 is returned. And so on.- Returns:
- the maximum height of the tree beneath this Node
-
nChildren
public int nChildren()Gets the number of children of aGNode.- Returns:
- the number of children of this Node
-
nNodes
Gets the number of nodes in a tree.- Parameters:
flags- which types of children are to be counted, one ofTraverseFlags.ALL,TraverseFlags.LEAVESandTraverseFlags.NON_LEAVES- Returns:
- the number of nodes in the tree
-
nNodes
Gets the number of nodes in a tree.- Parameters:
flags- which types of children are to be counted, one ofTraverseFlags.ALL,TraverseFlags.LEAVESandTraverseFlags.NON_LEAVES- Returns:
- the number of nodes in the tree
-
nthChild
Gets a child of aGNode, using the given index. The first child is at index 0. If the index is too big,nullis returned.- Parameters:
n- the index of the desired child- Returns:
- the child of this Node at index
n
-
prepend
-
reverseChildren
public void reverseChildren()Reverses the order of the children of aGNode. (It doesn't change the order of the grandchildren.) -
traverse
public void traverse(TraverseType order, Set<TraverseFlags> flags, int maxDepth, @Nullable NodeTraverseFunc func) Traverses a tree starting at the given rootGNode. It calls the given function for each node visited. The traversal can be halted at any point by returningtruefromfunc.funcmust not do anything that would modify the structure of the tree.- Parameters:
order- the order in which nodes are visited -TraverseType.IN_ORDER,TraverseType.PRE_ORDER,TraverseType.POST_ORDER, orTraverseType.LEVEL_ORDER.flags- which types of children are to be visited, one ofTraverseFlags.ALL,TraverseFlags.LEAVESandTraverseFlags.NON_LEAVESmaxDepth- the maximum depth of the traversal. Nodes below this depth will not be visited. If max_depth is -1 all nodes in the tree are visited. If depth is 1, only the root is visited. If depth is 2, the root and its children are visited. And so on.func- the function to call for each visitedGNode
-
traverse
public void traverse(TraverseType order, TraverseFlags flags, int maxDepth, @Nullable NodeTraverseFunc func) Traverses a tree starting at the given rootGNode. It calls the given function for each node visited. The traversal can be halted at any point by returningtruefromfunc.funcmust not do anything that would modify the structure of the tree.- Parameters:
order- the order in which nodes are visited -TraverseType.IN_ORDER,TraverseType.PRE_ORDER,TraverseType.POST_ORDER, orTraverseType.LEVEL_ORDER.flags- which types of children are to be visited, one ofTraverseFlags.ALL,TraverseFlags.LEAVESandTraverseFlags.NON_LEAVESmaxDepth- the maximum depth of the traversal. Nodes below this depth will not be visited. If max_depth is -1 all nodes in the tree are visited. If depth is 1, only the root is visited. If depth is 2, the root and its children are visited. And so on.func- the function to call for each visitedGNode
-
unlink
public void unlink()Unlinks aGNodefrom a tree, resulting in two separate trees.
-