TreeNode

data class TreeNode<T>(var name: String = "", var attributes: List<T> = listOf())

Parameters

name
  • name of a node

attributes
  • Attributes of a node, null by default

Constructors

Link copied to clipboard
constructor(name: String = "", attributes: List<T> = listOf())

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
var depth: Int
Link copied to clipboard
var index: Int
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
lateinit var treeRef: Tree<T>

Functions

Link copied to clipboard

Add a new single TreeNode to this TreeNode

fun appendChild(name: String, attributes: List<T> = listOf()): TreeNode<T>

Add a new single TreeNode to this TreeNode.

Link copied to clipboard
@JvmName(name = "appendChildrenNodes")
fun appendChildren(children: NodeList<T>): TreeNode<T>

Add children nodes to this node, pass a NodeList

Link copied to clipboard
fun appendEmptyChildren(vararg names: String): TreeNode<T>

Add empty children nodes to this node, pass names

@JvmName(name = "appendChildrenNames")
fun appendEmptyChildren(names: List<String>): TreeNode<T>

Add empty children nodes to this node, pass a List with nodes' names

Link copied to clipboard
fun checkPath(vararg path: Int): Int
fun checkPath(path: List<Int>): Int

Check if a path can be traversed from this node

Link copied to clipboard
fun clone(): TreeNode<T>

Return a new independent instance of this TreeNode (deep copy), uses recursion

Link copied to clipboard

Get all children nodes below the passed node, including this node.

Link copied to clipboard

Get all leaves (nodes that have no children) from below this node.

Link copied to clipboard
fun getNodeOrNull(vararg path: Int): TreeNode<T>?

Get a TreeNode at path starting from this node

Link copied to clipboard
fun getPath(): List<Int>

Get the path from root node to this node in a List, no recursion

Link copied to clipboard

Get the path from root node to this node, uses recursion

Link copied to clipboard

Get the root node of the tree that this node belongs to.

Link copied to clipboard
fun <T> TreeNode<T>.getStringPath(vararg path: Int): String

Get String representation of a path from this node.

Link copied to clipboard

Get a String representation of the path from the tree root to this node.

Link copied to clipboard
fun hasChildAt(index: Int): Boolean

Check if this node has a child at the index

Link copied to clipboard

Check if this node has children

Link copied to clipboard

Check if this node has parent

Link copied to clipboard
fun isValidPath(vararg path: Int): Boolean
Link copied to clipboard
fun setAttributes(vararg attributes: T): TreeNode<T>

Change/add attributes (as List) to this node. Create Tree with type T that you want your attributes to have.

Link copied to clipboard
fun setName(name: String): TreeNode<T>

Change the name of this node.

Link copied to clipboard
fun tryGetNode(vararg path: Int): TreeNode<T>

Get a TreeNode object located at a certain path in hierarchy, pass path as Int indices