
package LRSVisitor;

import LRStructure.*;
import Counter.*;
import javax.swing.*;

public class LRSPrintN implements IAlgo, ICounterAlgo
{
	JTextArea textArea;
	/**
	 * @param textArea
	 * @SBGen Constructor assigns textArea
	 */
	public LRSPrintN(JTextArea textArea)
	{
			// SBgen: Assign variable
		this.textArea = textArea;
	}

	public Object nullCase(LRStruct host, Object param)
    {
        return(null);   // Nothing to print here.
    }

	public Object nonNullCase(LRStruct host, Object param)
    {
		return( ((Counter) param).execute(this, host));
    }

	/**
	 * @param host 
	 * @param param 
	 */
	public Object zeroCase(Counter host, Object param)
	{
		return(null);
	}

	/**
	 * @param host 
	 * @param param 
	 */
	public Object nonZeroCase(Counter host, Object param)
	{
		// appends the integer value of the data as a new line onto the TextArea
//		textArea.append("\t"+((Integer)((LRStruct) param).getFirst()).toString() +'\n');
		textArea.append(((Integer)((LRStruct) param).getFirst()).toString() +'\n');
//		System.out.println("PRINT: "+((Integer)((LRStruct) param).getFirst()).toString());
    // recurse on the rest of the list
		return (((LRStruct) param).getRest()).execute(this,host.decrement());
	}
}

