Class Node

All Implemented Interfaces:
PointerInterface

public class Node extends Record
The #GNode struct represents one node in a [n-ary tree][glib-N-ary-Trees].

https://docs.gtk.org/glib/struct.Node.html

  • Field Details

    • DATA

      public static final String DATA
      contains the actual data of the node.
      See Also:
    • NEXT

      public static final String NEXT
      points to the node's next sibling (a sibling is another
      #GNode with the same parent).
      See Also:
    • PREV

      public static final String PREV
      points to the node's previous sibling.
      See Also:
    • PARENT

      public static final String PARENT
      points to the parent of the #GNode, or is %NULL if the
      #GNode is the root of the tree.
      See Also:
    • CHILDREN

      public static final String CHILDREN
      points to the first child of the #GNode. The other
      children are accessed by using the @next pointer of each
      child.
      See Also:
  • Constructor Details

  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • setFieldData

      public void setFieldData(Pointer data)
      contains the actual data of the node.
    • getFieldData

      public Pointer getFieldData()
      contains the actual data of the node.
    • setFieldNext

      public void setFieldNext(Node next)
      points to the node's next sibling (a sibling is another
      #GNode with the same parent).
    • getFieldNext

      public Node getFieldNext()
      points to the node's next sibling (a sibling is another
      #GNode with the same parent).
    • setFieldPrev

      public void setFieldPrev(Node prev)
      points to the node's previous sibling.
    • getFieldPrev

      public Node getFieldPrev()
      points to the node's previous sibling.
    • setFieldParent

      public void setFieldParent(Node parent)
      points to the parent of the #GNode, or is %NULL if the
      #GNode is the root of the tree.
    • getFieldParent

      public Node getFieldParent()
      points to the parent of the #GNode, or is %NULL if the
      #GNode is the root of the tree.
    • setFieldChildren

      public void setFieldChildren(Node children)
      points to the first child of the #GNode. The other
      children are accessed by using the @next pointer of each
      child.
    • getFieldChildren

      public Node getFieldChildren()
      points to the first child of the #GNode. The other
      children are accessed by using the @next pointer of each
      child.
    • childIndex

      public int childIndex(@Nullable Pointer data)
      Gets the position of the first child of a #GNode
      which contains the given data.
      Parameters:
      data - the data to find
      Returns:
      the index of the child of @node which contains @data, or -1 if the data is not found
    • childPosition

      public int childPosition(@Nonnull Node child)
      Gets the position of a #GNode with respect to its siblings.
      @child must be a child of @node. The first child is numbered 0,
      the second 1, and so on.
      Parameters:
      child - a child of @node
      Returns:
      the position of @child with respect to its siblings
    • childrenForeach

      public void childrenForeach(int flags, Node.OnNodeForeachFunc func, @Nullable Pointer data)
      Calls a function for each of the children of a #GNode. Note that it
      doesn't descend beneath the child nodes. @func must not do anything
      that would modify the structure of the tree.
      Parameters:
      flags - which types of children are to be visited, one of %G_TRAVERSE_ALL, %G_TRAVERSE_LEAVES and %G_TRAVERSE_NON_LEAVES
      func - the function to call for each visited node
      data - user data to pass to the function
    • copy

      public Node copy()
      Recursively copies a #GNode (but does not deep-copy the data inside the
      nodes, see g_node_copy_deep() if you need that).
      Returns:
      a new #GNode containing the same data pointers
    • copyDeep

      public Node copyDeep(Node.OnCopyFunc copy_func, @Nullable Pointer data)
      Recursively copies a #GNode and its data.
      Parameters:
      copy_func - the function which is called to copy the data inside each node, or %NULL to use the original data.
      data - data to pass to @copy_func
      Returns:
      a new #GNode containing copies of the data in @node.
    • depth

      public int depth()
      Gets the depth of a #GNode.

      If @node is %NULL the 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 @root and its children from the tree, freeing any memory
      allocated.
      Overrides:
      destroy in class Record
    • find

      public Node find(int order, int flags, @Nullable Pointer data)
      Finds a #GNode in a tree.
      Parameters:
      order - the order in which nodes are visited - %G_IN_ORDER, %G_PRE_ORDER, %G_POST_ORDER, or %G_LEVEL_ORDER
      flags - which types of children are to be searched, one of %G_TRAVERSE_ALL, %G_TRAVERSE_LEAVES and %G_TRAVERSE_NON_LEAVES
      data - the data to find
      Returns:
      the found #GNode, or %NULL if the data is not found
    • findChild

      public Node findChild(int flags, @Nullable Pointer data)
      Finds the first child of a #GNode with the given data.
      Parameters:
      flags - which types of children are to be searched, one of %G_TRAVERSE_ALL, %G_TRAVERSE_LEAVES and %G_TRAVERSE_NON_LEAVES
      data - the data to find
      Returns:
      the found child #GNode, or %NULL if the data is not found
    • firstSibling

      public Node firstSibling()
      Gets the first sibling of a #GNode.
      This could possibly be the node itself.
      Returns:
      the first sibling of @node
    • getRoot

      public Node getRoot()
      Gets the root of a tree.
      Returns:
      the root of the tree
    • insert

      public Node insert(int position, @Nonnull Node node)
      Inserts a #GNode beneath the parent at the given position.
      Parameters:
      position - the position to place @node at, with respect to its siblings If position is -1, @node is inserted as the last child of @parent
      node - the #GNode to insert
      Returns:
      the inserted #GNode
    • insertAfter

      public Node insertAfter(@Nonnull Node sibling, @Nonnull Node node)
      Inserts a #GNode beneath the parent after the given sibling.
      Parameters:
      sibling - the sibling #GNode to place @node after. If sibling is %NULL, the node is inserted as the first child of @parent.
      node - the #GNode to insert
      Returns:
      the inserted #GNode
    • insertBefore

      public Node insertBefore(@Nonnull Node sibling, @Nonnull Node node)
      Inserts a #GNode beneath the parent before the given sibling.
      Parameters:
      sibling - the sibling #GNode to place @node before. If sibling is %NULL, the node is inserted as the last child of @parent.
      node - the #GNode to insert
      Returns:
      the inserted #GNode
    • isAncestor

      public boolean isAncestor(@Nonnull Node descendant)
      Returns %TRUE if @node is an ancestor of @descendant.
      This is true if node is the parent of @descendant,
      or if node is the grandparent of @descendant etc.
      Parameters:
      descendant - a #GNode
      Returns:
      %TRUE if @node is an ancestor of @descendant
    • lastChild

      public Node lastChild()
      Gets the last child of a #GNode.
      Returns:
      the last child of @node, or %NULL if @node has no children
    • lastSibling

      public Node lastSibling()
      Gets the last sibling of a #GNode.
      This could possibly be the node itself.
      Returns:
      the last sibling of @node
    • maxHeight

      public int maxHeight()
      Gets the maximum height of all branches beneath a #GNode.
      This is the maximum distance from the #GNode to all leaf nodes.

      If @root is %NULL, 0 is returned. If @root has no children,
      1 is returned. If @root has children, 2 is returned. And so on.
      Returns:
      the maximum height of the tree beneath @root
    • nChildren

      public int nChildren()
      Gets the number of children of a #GNode.
      Returns:
      the number of children of @node
    • nNodes

      public int nNodes(int flags)
      Gets the number of nodes in a tree.
      Parameters:
      flags - which types of children are to be counted, one of %G_TRAVERSE_ALL, %G_TRAVERSE_LEAVES and %G_TRAVERSE_NON_LEAVES
      Returns:
      the number of nodes in the tree
    • nthChild

      public Node nthChild(int n)
      Gets a child of a #GNode, using the given index.
      The first child is at index 0. If the index is
      too big, %NULL is returned.
      Parameters:
      n - the index of the desired child
      Returns:
      the child of @node at index @n
    • prepend

      public Node prepend(@Nonnull Node node)
      Inserts a #GNode as the first child of the given parent.
      Parameters:
      node - the #GNode to insert
      Returns:
      the inserted #GNode
    • reverseChildren

      public void reverseChildren()
      Reverses the order of the children of a #GNode.
      (It doesn't change the order of the grandchildren.)
    • traverse

      public void traverse(int order, int flags, int max_depth, Node.OnNodeTraverseFunc func, @Nullable Pointer data)
      Traverses a tree starting at the given root #GNode.
      It calls the given function for each node visited.
      The traversal can be halted at any point by returning %TRUE from @func.
      @func must not do anything that would modify the structure of the tree.
      Parameters:
      order - the order in which nodes are visited - %G_IN_ORDER, %G_PRE_ORDER, %G_POST_ORDER, or %G_LEVEL_ORDER.
      flags - which types of children are to be visited, one of %G_TRAVERSE_ALL, %G_TRAVERSE_LEAVES and %G_TRAVERSE_NON_LEAVES
      max_depth - 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 visited #GNode
      data - user data to pass to the function
    • unlink

      public void unlink()
      Unlinks a #GNode from a tree, resulting in two separate trees.
    • _new

      public static Node _new(@Nullable Pointer data)
      Creates a new #GNode containing the given data.
      Used to create the first node in a tree.
      Parameters:
      data - the data of the new node
      Returns:
      a new #GNode