TreeNode¶
Inherits: object
Module: string_tree
Note
in this class “path” always refers to a string of the titles of each node joined by a period. Example: “Grandparent.Parent.Child” is a path to the “Child” TreeNode
Brief Description¶
A node in the Tree that holds references to this nodes parent, biological and adopted children and this nodes string contents.
Instance Methods¶
| TreeNode | TreeNode ( Tree tree, TreeNode parent, str title, str string ) |
| str | get_path ( ) |
| TreeNode | add_child ( str title, str string ) |
| TreeNode | get_child ( str title ) |
| TreeNode | remove_child ( str title ) |
| list | get_biological_children ( ) |
| None | add_adopted_child ( str path ) |
| list | get_adopted_children ( ) |
| None | remove_adopted_child ( str title ) |
| list | get_lineage ( ) |
| list | remove_lineage ( ) |
Description¶
A node in the Tree that holds references to this nodes parent, biological and adopted children and this nodes string contents.
Instance Variables¶
- Tree tree - The tree that the node belongs to.
- TreeNode parent - The direct TreeNode this node derives from.
- list adoptive_parents - A list of this nodes adoptive parent TreeNodes, these are nodes that are not the direct parent of this node but still are connected as a parent.
- list children - A list of this nodes child TreeNodes.
- str title - The title that describes this node. This is used in the path to access the node. See note
- str string - The contents of this node.
Instance Method Descriptions¶
Creates a TreeNode instance on the tree as a child of the parent with the title and string contents.
- str get_path ( )
Returns the path to this node.
- TreeNode add_child ( str title, str string )
Creates a TreeNode with the title and string and adds it as a
child to this node and appends it to this nodes tree .
- TreeNode get_child ( str title )
Returns the child of this node with the title .
- TreeNode remove_child ( str title )
Removes and returns the child of this node with the title . This will append all of the children of the
removed node as children of this node.
- list get_biological_children ( )
Returns a list of this nodes children that are directly created from this node.
- None add_adopted_child ( str path )
Adds the TreeNode from the path as an adopted child of this node. Adopted children are the same as biological children
except they are not directly made from this parent.
- list get_adopted_children ( )
Returns a list of this nodes children that are adopted. Meaning they are not directly created from this node.
- None remove_adopted_child ( str title )
Removes the child of this node with the title from this nodes children.
- list get_lineage ( )
Returns the lineage of this node. This includes all biological children, their biological children, and so on.
- list remove_lineage ( )
Removes and returns the lineage of this node. This includes all biological children, their biological children, and so on.