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 * @author Mathias Ricken - Copyright 2008 - All rights reserved. 008 * @since 8/25/05 009 */ 010 class EmptyNode<T> extends ANode<T> { 011 /** 012 * Throws java.util.NoSuchElementException. 013 */ 014 LRStruct<T> getRest(LRStruct<T> owner) { 015 throw new java.util.NoSuchElementException ("Empty list has no first."); 016 } 017 018 /** 019 * Throws java.util.NoSuchElementException. 020 */ 021 T getFirst(LRStruct<T> owner) { 022 throw new java.util.NoSuchElementException ("Empty list has no first."); 023 } 024 025 /** 026 * Throws java.util.NoSuchElementException. 027 */ 028 LRStruct<T> setRest(LRStruct<T> tail, LRStruct<T> owner) { 029 throw new java.util.NoSuchElementException ("Empty list has no tail."); 030 } 031 032 /** 033 * Throws java.util.NoSuchElementException. 034 */ 035 LRStruct<T> setFirst(T dat, LRStruct<T> owner) { 036 throw new java.util.NoSuchElementException ("Empty list has no first."); 037 } 038 039 /** 040 * The owner becomes non-empty and has dat as its first element. 041 */ 042 LRStruct<T> insertFront(T dat, LRStruct<T> owner) { 043 return owner.setHead(new NENode<T>(dat, new LRStruct<T>(this))); 044 } 045 046 /** 047 * Throws java.util.NoSuchElementException. 048 */ 049 T removeFront(LRStruct<T> owner) { 050 throw new java.util.NoSuchElementException ("Empty list has no front."); 051 } 052 053 /** 054 * Calls the <code>IAlgo</code> visitor's empty case. 055 */ 056 <R,P> R execute(LRStruct<T> owner, IAlgo<T, R, P> algo, P ... inp) { 057 return algo.emptyCase(owner, inp); 058 } 059 } 060