@studyportals/sp-hs-misc
Version:
Miscellaneous code used in HouseStark's projects
57 lines • 1.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TreeNode = void 0;
/**
* A tree node.
*/
class TreeNode {
_parent;
_children;
/**
* Gets or sets the node's content.
*/
content;
/**
* Initializes a new TreeNode<T> instance.
*
* @param parent The node's parent.
*/
constructor(parent) {
this._parent = parent || null;
this._children = [];
}
/**
* Gets the node's parent.
*/
get parent() {
return this._parent;
}
/**
* Gets the node's children.
*/
get children() {
return this._children;
}
/**
* Adds the specified node to the current node's children collection.
*
* @param child The node that is to be appended to the current node's children collection.
*/
addChild(child) {
this.children.push(child);
}
/**
* Gets a value that specifies whether the node is a root.
*/
isRoot() {
return null == this.parent;
}
/**
* Gets a value that specifies whether the node is a leaf.
*/
isLeaf() {
return 0 === this.children.length;
}
}
exports.TreeNode = TreeNode;
//# sourceMappingURL=tree-node.class.js.map