001 002 003 package lrs.visitor; 004 005 import lrs.*; 006 import counter.*; 007 import javax.swing.*; 008 009 public class LRSPrintN implements IAlgo, ICounterAlgo 010 { 011 JTextArea textArea; 012 /** 013 * @param textArea 014 * @SBGen Constructor assigns textArea 015 */ 016 public LRSPrintN(JTextArea textArea) 017 { 018 // SBgen: Assign variable 019 this.textArea = textArea; 020 } 021 022 public Object emptyCase(LRStruct host, Object... param) 023 { 024 return(null); // Nothing to print here. 025 } 026 027 public Object nonEmptyCase(LRStruct host, Object... param) 028 { 029 return( ((ICounter) param[0]).execute(this, host)); 030 } 031 032 /** 033 * @param host 034 * @param param 035 */ 036 public Object zeroCase(ICounter host, Object... param) 037 { 038 return(null); 039 } 040 041 /** 042 * @param host 043 * @param param 044 */ 045 public Object nonZeroCase(ICounter host, Object... param) 046 { 047 // appends the integer value of the data as a new line onto the TextArea 048 // textArea.append("\t"+((Integer)((LRStruct) param).getFirst()).toString() +'\n'); 049 textArea.append(((LRStruct) param[0]).getFirst().toString() +'\n'); 050 // System.out.println("PRINT: "+((Integer)((LRStruct) param[0]).getFirst()).toString()); 051 // recurse on the rest of the list 052 return (((LRStruct) param[0]).getRest()).execute(this,host.decrement()); 053 } 054 } 055