package binaryTree; /** * Stores data and represents a non-empty state. * @author Dung X. Nguyen - Copyright 1999 - All rights reserved. * @since 11/10/99 */ class DatNode extends ANode { /** * Data Invariant: != null. * @SBGen Variable (,left subtree,,64) */ private BiTree _leftTree = new BiTree (); /** * the stored data element. */ private Object _dat; /** * Data Invariant: != null. * @SBGen Variable (,right subtree,,64) */ private BiTree _rightTree = new BiTree (); /** * Initialize the data element to a given object. * @param dat */ DatNode(Object dat) { _dat = dat; } /** * Gets the root data of the owner Tree. * @param owner the context of the state. * @return the data element of this node. */ Object getRootDat(BiTree owner) { return _dat; } /** * Sets the data element of this node to a given data object. * @param dat * @param owner the context of this state. */ void setRootDat(Object dat, BiTree owner) { _dat = dat; } /** * Gets the left subtree of the owner tree. * @param owner the context of this state. * @return the left subtree of this node. */ BiTree getLeftSubTree(BiTree owner) { return _leftTree; } /** * Gets the right subtree of the owner tree. * @param owner the context of this state. * @return the right subtree of this node. */ BiTree getRightSubTree(BiTree owner) { return _rightTree; } /** * Sets the left subtree of this node to a given tree. * Allows for growing the owner tree. * @param biTree != null. * @param owner the context of this state. */ void setLeftSubTree(BiTree biTree, BiTree owner) { _leftTree = biTree; } /** * Sets the right subtree of this node to a given tree. * Allows for growing the owner tree. * @param biTree != null. * @param owner the context of this state. */ void setRightSubTree(BiTree biTree, BiTree owner) { _rightTree = biTree; } /** * Throws an IllegalStateException because the owner tree is not empty. * @exception IllegaStateException. */ void insertRoot(Object dat, BiTree owner) { throw new IllegalStateException ("DatNode.insertRoot - Tree is not empty."); } /** * Removes and returns the root element from the owner tree by handing the right * subtree to the left subtree to do the job. * @param dat * @param owner the context of this state. * @exception IllegaStateException if the owner has more than one element. */ Object remRoot(BiTree owner) { return _leftTree.remParent (_rightTree, owner); } /** * Throws an IllegalStateException because the owner tree is not empty. * @param oSib * @param oDad */ Object remParent(BiTree oSib, BiTree oDad, BiTree owner) { throw new IllegalStateException ("Tree has more than one element."); } /** * Throws an IllegalStateException because the owner tree is not empty. */ Object remParentNode (BiTree ownerDad, BiTree owner) { throw new IllegalStateException ("Tree has more than one element."); } /** * Calls the visitor's nonNullCase () method to execute the visiting algorithm. * @param algo the visiting algorithm * @param input the input the algorithm needs. * @param owner the context of this node. * @return the output for the nonNullCase() of the algorithm. */ Object execute(IVisitor algo, Object input, BiTree owner) { return algo.nonEmptyCase (owner, input); } }