package lrs; /** * Represents the empty state. Singleton pattern. * @author Dung X. Nguyen Copyright 2000 - All rights reserved. * @author Alan L. Cox * @since 02/13/01 */ class EmptyNode extends ANode { /** * Singleton Pattern. */ final static EmptyNode singleton = new EmptyNode(); private EmptyNode() { } /** * @throw java.util.NoSuchElementException. */ Object getFirst(LRStruct owner) { throw new java.util.NoSuchElementException("Empty list has no first."); } /** * @throw java.util.NoSuchElementException. */ void setFirst(Object data, LRStruct owner) { throw new java.util.NoSuchElementException("Empty list has no first."); } /** * @throw java.util.NoSuchElementException. */ LRStruct getRest(LRStruct owner) { throw new java.util.NoSuchElementException("Empty list has no first."); } /** * @throw java.util.NoSuchElementException. */ void setRest(LRStruct tail, LRStruct owner) { throw new java.util.NoSuchElementException("Empty list has no tail."); } /** * Inserts a data object at the front of the LRStruct owner. * * @param data the object to be inserted at the front. * @param owner the LRS referencing this EmptyNode. */ void insertFront(Object data, LRStruct owner) { owner.setHead(new NonEmptyNode(data)); } /** * @throw java.util.NoSuchElementException. */ Object removeFront(LRStruct owner) { throw new java.util.NoSuchElementException("Empty list has no front."); } /** * Executes the visitor's empty case and returns the output. * * @param visitor the algorithm to be executed. * @param input the input needed by the algorithm. * @param owner the LRStruct referencing this EmptyNode. */ Object execute(IAlgo visitor, Object input, LRStruct owner) { return visitor.emptyCase(owner, input); } }