package genLRS; /** * Represents the empty state of a mutable list LRStruct. Uses the * Singleton pattern. * @author Dung X. Nguyen, Stephen B. Wong Copyright 2005 - All rights reserved. */ class EmptyNode extends ANode { /** * Singleton Pattern. */ //final static EmptyNode Singleton = new EmptyNode(); public EmptyNode() { } /** * Throws java.util.NoSuchElementException. */ LRStruct getRest(LRStruct owner) { throw new java.util.NoSuchElementException ("Empty list has no first."); } /** * Throws java.util.NoSuchElementException. */ E getFirst(LRStruct owner) { throw new java.util.NoSuchElementException ("Empty list has no first."); } /** * Throws java.util.NoSuchElementException. */ LRStruct setRest(LRStruct tail, LRStruct owner) { throw new java.util.NoSuchElementException ("Empty list has no tail."); } /** * Throws java.util.NoSuchElementException. */ LRStruct setFirst(EE dat, LRStruct owner) { throw new java.util.NoSuchElementException ("Empty list has no first."); } /** * The owner becomes non-empty and has dat as its first element. */ LRStruct insertFront(E dat, LRStruct owner) { return owner.setHead(new NENode(dat, new LRStruct(this))); } /** * Throws java.util.NoSuchElementException. */ E removeFront(LRStruct owner) { throw new java.util.NoSuchElementException ("Empty list has no front."); } /** * Calls the IAlgo visitor's empty case. */ R execute(LRStruct owner, IAlgo algo, P ... inp) { return algo.emptyCase(owner, inp); } }