



package lrs.visitor;



import lrs.*;

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 emptyCase(LRStruct host, Object... param)

  {

    return(null);   // Nothing to print here.

  }

  

  public Object nonEmptyCase(LRStruct host, Object... param)

  {

    return( ((ICounter) param[0]).execute(this, host));

  }

  

  /**

   * @param host 

   * @param param 

   */

  public Object zeroCase(ICounter host, Object... param)

  {

    return(null);

  }

  

  /**

   * @param host 

   * @param param 

   */

  public Object nonZeroCase(ICounter 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(((LRStruct) param[0]).getFirst().toString() +'\n');

//  System.out.println("PRINT: "+((Integer)((LRStruct) param[0]).getFirst()).toString());

    // recurse on the rest of the list

    return (((LRStruct) param[0]).getRest()).execute(this,host.decrement());

  }

}



