|
| 1 | +packageDevUtils.Nodes; |
| 2 | + |
| 3 | +/** |
| 4 | + * Simple TreeNode extension that holds references |
| 5 | + * to two child Nodes (left and right). |
| 6 | + * |
| 7 | + * @param <E> The type of the data held in the Node. |
| 8 | + * |
| 9 | + * @author <a href="https://github.com/aitorfi">aitorfi</a> |
| 10 | + */ |
| 11 | +publicclassSimpleTreeNode<E>extendsTreeNode<E> { |
| 12 | +/** Refrence to the child Node on the left. */ |
| 13 | +privateSimpleTreeNode<E>leftNode; |
| 14 | +/** Refrence to the child Node on the right. */ |
| 15 | +privateSimpleTreeNode<E>rightNode; |
| 16 | + |
| 17 | +/** Empty contructor. */ |
| 18 | +publicSimpleTreeNode() { |
| 19 | +super(); |
| 20 | + } |
| 21 | + |
| 22 | +/** |
| 23 | + * Initializes the Nodes' data. |
| 24 | + * |
| 25 | + * @param data Value to which data will be initialized. |
| 26 | + * @see TreeNode#TreeNode(Object) |
| 27 | + */ |
| 28 | +publicSimpleTreeNode(Edata) { |
| 29 | +super(data); |
| 30 | + } |
| 31 | + |
| 32 | +/** |
| 33 | + * Initializes the Nodes' data and parent node reference. |
| 34 | + * |
| 35 | + * @param data Value to which data will be initialized. |
| 36 | + * @param parentNode Value to which the nodes' parent reference will be set. |
| 37 | + * @see TreeNode#TreeNode(Object, Node) |
| 38 | + */ |
| 39 | +publicSimpleTreeNode(Edata,SimpleTreeNode<E>parentNode) { |
| 40 | +super(data,parentNode); |
| 41 | + } |
| 42 | + |
| 43 | +/** |
| 44 | + * Initializes the Nodes' data and parent and child nodes references. |
| 45 | + * |
| 46 | + * @param data Value to which data will be initialized. |
| 47 | + * @param parentNode Value to which the nodes' parent reference will be set. |
| 48 | + * @param leftNode Value to which the nodes' left child reference will be set. |
| 49 | + * @param rightNode Value to which the nodes' right child reference will be set. |
| 50 | + */ |
| 51 | +publicSimpleTreeNode(Edata,SimpleTreeNode<E>parentNode,SimpleTreeNode<E>leftNode,SimpleTreeNode<E>rightNode) { |
| 52 | +super(data,parentNode); |
| 53 | +this.leftNode =leftNode; |
| 54 | +this.rightNode =rightNode; |
| 55 | + } |
| 56 | + |
| 57 | +/** |
| 58 | + * @return True if the node is a leaf node, otherwise false. |
| 59 | + * @see TreeNode#isLeafNode() |
| 60 | + */ |
| 61 | +@Override |
| 62 | +publicbooleanisLeafNode() { |
| 63 | +return (leftNode ==null &&rightNode ==null); |
| 64 | + } |
| 65 | + |
| 66 | +publicSimpleTreeNode<E>getLeftNode() { |
| 67 | +returnleftNode; |
| 68 | + } |
| 69 | + |
| 70 | +publicvoidsetLeftNode(SimpleTreeNode<E>leftNode) { |
| 71 | +this.leftNode =leftNode; |
| 72 | + } |
| 73 | + |
| 74 | +publicSimpleTreeNode<E>getRightNode() { |
| 75 | +returnrightNode; |
| 76 | + } |
| 77 | + |
| 78 | +publicvoidsetRightNode(SimpleTreeNode<E>rightNode) { |
| 79 | +this.rightNode =rightNode; |
| 80 | + } |
| 81 | +} |