001 package lrs.visitor; 002 003 import lrs.IAlgo; 004 import lrs.LRStruct; 005 006 /** 007 * Clears this LRStruct. 008 * 009 * @author Mathias Ricken 010 */ 011 public class Clear implements IAlgo { 012 /// singleton instance 013 public static final Clear Singleton = new Clear(); 014 015 /// private singleton ctor 016 private Clear() { 017 } 018 019 /** 020 * Operates on an empty LRStruct host, given an input object. 021 * 022 * @param host an empty LRStruct. 023 * @param inp not used 024 * 025 * @return the empty LRStruct 026 */ 027 public Object emptyCase(LRStruct host, Object inp) { 028 // done 029 return host; 030 } 031 032 /** 033 * Operates on a non-empty LRStruct host, given an input object. 034 * 035 * @param host a non-empty LRStruct. 036 * @param inp input object needed by this IAlgo. 037 * 038 * @return an appropriate output object. 039 */ 040 public Object nonEmptyCase(LRStruct host, Object inp) { 041 // set rest to empty 042 host.setRest(new LRStruct()); 043 // remove front 044 host.removeFront(); 045 return host; 046 } 047 }