

package lrs.visitor;



import counter.*;

import lrs.*;



public class SetNth implements IAlgo{

  /** @SBGen Singleton Variable   */

  public static SetNth Singleton = new SetNth(); 

  private SetNth(){}

  

  /**

   * @param host 

   * @param param 

   * @return 

   */

  public Object emptyCase(LRStruct host, Object... param) {

    return (null); // No such element exists.

  }

  

  /**

   * @param host 

   * @param param  param[0] = ICounter, param[1] = data 

   * @return 

   */

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

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

  }

  

  

  private static final ICounterAlgo counterAlgo = new ICounterAlgo(){

    /**

     * @param host 

     * @param param param[0] = LRStruct host, param[1] = data

     * @return 

     */

    public Object zeroCase(ICounter chost, Object... param) {

      ((LRStruct)param[0]).setFirst(param[1]);

      return null;

    }

    

    /**

     * @param host 

     * @param param param[0] = LRStruct host, param[1] = data

     * @return 

     */

    public Object nonZeroCase(ICounter chost, Object... param) {

      return ((LRStruct)param[0]).getRest().execute(SetNth.Singleton, chost.decrement(), param[1]);

    }

  };    

}



