001 002 package brs; 003 004 /** 005 * Represents the state of the owner binary tree structure. Union pattern 006 * @author Dung X. Nguyen - Copyright 2001 - All rights reserved. 007 * @author Mathias Ricken - Copyright 2008 - All rights reserved. 008 */ 009 abstract class ANode<T> { 010 /** 011 * Gets the root data of the owner tree if it exists. 012 * @param owner the BiTree that holds this node. 013 * @return the data element of this node if it exists. 014 * @exception NoSuchElementException if the owner is empty. 015 */ 016 abstract T getRootDat(BiTree<T> owner); 017 018 /** 019 * Sets the root element of the owner tree to a given data object. 020 * @param dat 021 * @param owner the BiTree that holds this node. 022 * @exception NoSuchElementException if the owner is empty. 023 */ 024 abstract void setRootDat(BiTree<T> owner, T dat); 025 026 /** 027 * Gets the left subtree of the owner tree. 028 * @param owner the BiTree that holds this node. 029 * @return the left subtree of this node if it exists. 030 * @exception NoSuchElementException if the owner is empty. 031 */ 032 abstract BiTree<T> getLeftSubTree(BiTree<T> owner); 033 034 /** 035 * Gets the right subtree of the owner tree. 036 * @param owner the BiTree that holds this node. 037 * @return the right subtree of this node if it exists. 038 * @exception NoSuchElementException if the owner is empty. 039 */ 040 abstract BiTree<T> getRightSubTree(BiTree<T> owner); 041 042 /** 043 * Sets the left subtree of the owner tree to a given tree. 044 * @param biTree != null. 045 * @param owner the BiTree that holds this node. 046 * @exception NoSuchElementException if the owner is empty. 047 */ 048 abstract void setLeftSubTree(BiTree<T> owner, BiTree<T> biTree); 049 050 /** 051 * Sets the right subtree of the owner tree to a given tree. 052 * @param biTree != null. 053 * @param owner the BiTree that holds this node. 054 * @exception NoSuchElementException if the owner is empty. 055 */ 056 abstract void setRightSubTree(BiTree<T> owner, BiTree<T> biTree); 057 058 /** 059 * Inserts a root element to the owner tree. Allows the owner tree to change 060 * state from empty to non-empty. 061 * @param dat 062 * @param owner the BiTree that holds this node. 063 * @exception IllegaStateException if the owner is not empty. 064 */ 065 abstract void insertRoot(BiTree<T> owner, T dat); 066 067 /** 068 * Removes and returns the root element from the owner tree. Allows the 069 * owner tree to change state from non-empty to empty. 070 * @param dat 071 * @param owner the BiTree that holds this node. 072 * @exception IllegaStateException if the owner has more than one element. 073 */ 074 abstract T remRoot(BiTree<T> owner); 075 076 /** 077 * Calls the appropriate visitor's method to execute the visiting algorithm. 078 * @param owner the BiTree that holds this node. 079 * @param algo the visiting algorithm 080 * @param inp the vararg input the algorithm needs. 081 * @return the output for the algorithm. 082 */ 083 abstract <R,P> R execute(BiTree<T> owner, IVisitor<T,R,P> algo, P... inp); 084 } 085