package lrs; /** * Represents the empty state of a mutable list LRStruct. Uses the * Singleton pattern. * @author Dung X. Nguyen and Stephen Wong Copyright 2005 - All rights reserved. * @author Mathias Ricken - Copyright 2008 - All rights reserved. * @since 8/25/05 */ class EmptyNode extends ANode { /** * Throws java.util.NoSuchElementException. */ LRStruct getRest(LRStruct owner) { throw new java.util.NoSuchElementException ("Empty list has no first."); } /** * Throws java.util.NoSuchElementException. */ T 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(T 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(T dat, LRStruct owner) { return owner.setHead(new NENode(dat, new LRStruct(this))); } /** * Throws java.util.NoSuchElementException. */ T 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); } }