UNPKG

@studyportals/sp-hs-misc

Version:

Miscellaneous code used in HouseStark's projects

73 lines (62 loc) 2.03 kB
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * A tree node. */ //# sourceMappingURL=tree-node.class.js.map var TreeNode = function () { /** * Initializes a new TreeNode<T> instance. * * @param parent The node's parent. */ function TreeNode(parent) { _classCallCheck(this, TreeNode); this._parent = parent || null; this._children = []; } /** * Gets the node's parent. */ _createClass(TreeNode, [{ key: "addChild", /** * 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. */ value: function addChild(child) { this.children.push(child); } /** * Gets a value that specifies whether the node is a root. */ }, { key: "isRoot", value: function isRoot() { return null == this.parent; } /** * Gets a value that specifies whether the node is a leaf. */ }, { key: "isLeaf", value: function isLeaf() { return 0 === this.children.length; } }, { key: "parent", get: function get() { return this._parent; } /** * Gets the node's children. */ }, { key: "children", get: function get() { return this._children; } }]); return TreeNode; }();