package binaryTree; /** * Represents the state of the parent binary tree structure. Union pattern * @author Dung X. Nguyen - Copyright 1999 - All rights reserved. */ abstract class ANode { /** * Gets the root data of the parent tree if it exists. * @param parent the context of the state. * @return the data element of this node if it exists. * @exception NoSuchElementException if the parent is empty. */ abstract Object getRootDat(BiTree parent); /** * Sets the root element of the parent tree to a given data object. * @param dat * @param parent the context of this state. * @exception NoSuchElementException if the parent is empty. */ abstract void setRootDat(Object dat, BiTree parent); /** * Gets the left subtree of the parent tree. * @param parent the context of this state. * @return the left subtree of this node if it exists. * @exception NoSuchElementException if the parent is empty. */ abstract BiTree getLeftSubTree(BiTree parent); /** * Gets the right subtree of the parent tree. * @param parent the context of this state. * @return the right subtree of this node if it exists. * @exception NoSuchElementException if the parent is empty. */ abstract BiTree getRightSubTree(BiTree parent); /** * Sets the left subtree of the parent tree to a given tree. * Allows for growing the parent tree. * @param biTree != null. * @param parent the context of this state. * @exception NoSuchElementException if the parent is empty. */ abstract void setLeftSubTree(BiTree biTree, BiTree parent); /** * Sets the right subtree of the parent tree to a given tree. Allows for growing * the parent tree. * @param biTree != null. * @param parent the context of this state. * @exception NoSuchElementException if the parent is empty. */ abstract void setRightSubTree(BiTree biTree, BiTree parent); /** * Inserts a root element to the parent tree. * Allows for state change from empty to non-empty. * @param dat * @param parent the context of this state. * @exception IllegaStateException if the parent is not empty. */ abstract void insertRoot(Object dat, BiTree parent); /** * Removes and returns the root element from the parent tree. * Allows for state change from non-empty to empty. * @param dat * @param parent the context of this state. * @exception IllegaStateException if the parent has more than one element. */ abstract Object remRoot(BiTree parent); /** * Removes and return the root element of the grandparent of this node, * asking the sibbling of the parent tree to do it if necessary. * @param aunt the sibbling of the parent of this node. * @param grandPo the grand parent of this node. * @param mom the parent (i.e. context) of this node. * @return the root data of the grandparent of this node. */ abstract Object remParent(BiTree aunt, BiTree grandPo, BiTree mom); /** * Removes and return the root element of the grandparent of this node, * knowing that the sibbling of the parent tree is empty. * @param grandParent the grand parent of this BiTree. * @param parent the context of this node. * @return the root data of the grandparent of this node. */ abstract Object remOurParent(BiTree grandParent, BiTree parent); /** * Calls the appropriate visitor's method to execute the visiting algorithm. * @param algo the visiting algorithm * @param input the input the algorithm needs. * @param parent the context of this node. * @return the output for the algorithm. */ abstract Object execute(IVisitor algo, Object input, BiTree parent); }