001    package lrs;
002    
003    /**
004     * Represents the empty state of a mutable list LRStruct. Uses the
005     * Singleton pattern.
006     * @author Dung X. Nguyen and Stephen Wong  Copyright 2005 - All rights reserved.
007     * @since 8/25/05
008     */
009    class EmptyNode extends ANode {
010        /**
011         * Singleton Pattern.
012         */
013        final static EmptyNode Singleton = new EmptyNode();
014        private EmptyNode() {}
015    
016        /**
017         * Throws java.util.NoSuchElementException.
018         */
019        LRStruct getRest(LRStruct owner) {
020            throw new java.util.NoSuchElementException ("Empty list has no first.");
021        }
022    
023        /**
024         * Throws java.util.NoSuchElementException.
025         */
026        Object getFirst(LRStruct owner) {
027            throw new java.util.NoSuchElementException ("Empty list has no first.");
028        }
029    
030        /**
031         * Throws java.util.NoSuchElementException.
032         */
033        LRStruct setRest(LRStruct tail, LRStruct owner) {
034            throw new java.util.NoSuchElementException ("Empty list has no tail.");
035        }
036    
037        /**
038         * Throws java.util.NoSuchElementException.
039         */
040        LRStruct setFirst(Object dat, LRStruct owner) {
041            throw new java.util.NoSuchElementException ("Empty list has no first.");
042        }
043    
044        /**
045         * The owner becomes non-empty and has dat as its first element.
046         */
047        LRStruct insertFront(Object dat, LRStruct owner) {
048            return owner.setHead(new NENode(dat, new LRStruct(this)));
049        }
050    
051        /**
052         * Throws java.util.NoSuchElementException.
053         */
054        Object removeFront(LRStruct owner) {
055            throw new java.util.NoSuchElementException ("Empty list has no front.");
056        }
057    
058        /**
059        * Calls the <code>IAlgo</code> visitor's empty case.
060        */
061        Object execute(LRStruct owner, IAlgo algo, Object... inp)  {
062            return algo.emptyCase(owner, inp);
063        }
064    }
065