001    
002    package brs;
003    
004    /**
005     * Represents the empty state of a BiTree.  Uses the singleton pattern to model
006     * the uniqueness of "emptiness".
007     * @author Dung X. Nguyen - Copyright 2002 - All rights reserved.
008     * @author Mathias Ricken - Copyright 2008 - All rights reserved.
009     * @since 03/11/02
010     */
011    class EmptyNode<T> extends ANode<T> {
012        /**
013        * Throws java.util.NoSuchElementException.
014        * @param owner the BiTree holding this EmptyNode.
015        */
016        T getRootDat (BiTree<T> owner) {
017            throw new java.util.NoSuchElementException ("EmptyNode.getRootDat()");
018        }
019    
020        /**
021        * Throws java.util.NoSuchElementException.
022        * @param dat a data Object.
023        * @param owner the BiTree holding this EmptyNode.
024        */
025        void setRootDat (BiTree<T> owner, T dat) {
026            throw new java.util.NoSuchElementException ("EmptyNode.setRootDat()");
027        }
028    
029        /**
030        * Throws java.util.NoSuchElementException.
031        * @param owner the BiTree holding this EmptyNode.
032        */
033        BiTree<T> getLeftSubTree (BiTree<T> owner) {
034            throw new java.util.NoSuchElementException ("EmptyNode.getLeftSubTree()");
035        }
036    
037        /**
038        * Throws java.util.NoSuchElementException.
039        * @param owner the BiTree holding this EmptyNode.
040        */
041        BiTree<T> getRightSubTree(BiTree<T> owner) {
042            throw new java.util.NoSuchElementException ("EmptyNode.getRightSubTree()");
043        }
044    
045        /**
046        * Throws java.util.NoSuchElementException.
047        * @param biTree a given BiTree.
048        * @param owner the BiTree holding this EmptyNode.
049        */
050        void setLeftSubTree(BiTree<T> owner, BiTree<T> biTree) {
051            throw new java.util.NoSuchElementException ("EmptyNode.setLeftSubTree()");
052        }
053    
054        /**
055        * Throws java.util.NoSuchElementException.
056        * @param biTree a given BiTree.
057        * @param owner the BiTree holding this EmptyNode.
058        */
059        void setRightSubTree(BiTree<T> owner, BiTree<T> biTree) {
060            throw new java.util.NoSuchElementException ("EmptyNode.setRightSubTree()");
061        }
062    
063        /**
064        * Asks the owner tree to set the root node to a new DatNode containing dat,
065        * resulting in a state change from empty to non-empty.
066        * @param dat a given data Object.
067        * @param owner the context of this state.
068        */
069        void insertRoot(BiTree<T> owner, T dat) {
070            owner.setRootNode(new DatNode<T>(dat));
071        }
072    
073        /**
074        * Throws java.util.NoSuchElementException.
075        * @param owner the BiTree holding this EmptyNode.
076        */
077        T remRoot (BiTree<T> owner) {
078            throw new java.util.NoSuchElementException ("EmptyNode.remRoot()");
079        }
080    
081        /**
082        * Calls algo's emptyCase () method to execute the algorithm algo.
083        * @param owner the BiTree holding this EmptyNode.
084        * @param algo the visiting algorithm
085        * @param inp the vararg input algo needs.
086        * @return the output for the emptyCase() of algo.
087        */
088        <R,P> R execute(BiTree<T> owner, IVisitor<T,R,P> algo, P... inp) {
089            return algo.emptyCase(owner, inp);
090        }
091    }
092