
package LRSVisitor;

import Counter.*;
import LRStructure.*;

/**
 * @dependency LRSVisitor.SetNthDat uses
 */
public class SetNth implements IAlgo, ICounterAlgo
{
	/** @SBGen Singleton Variable   */
	private static SetNth instance = null;	/** @SBGen Constructor   */
	private SetNth()
	{
	}

	/**
	 * @param host 
	 * @param param 
	 * @return 
	 */
	public Object nullCase(LRStruct host, Object param)
	{
		return (null); // No such element exists.
	}

	/**
	 * @param host 
	 * @param param 
	 * @return 
	 */
	public Object nonNullCase(LRStruct host, Object param)
	{
		return ((SetNthDat) param).getCounterHost ().execute(this, param); //
	}

	/**
	 * @param host 
	 * @param param 
	 * @return 
	 */
	public Object zeroCase(Counter host, Object param)
	{
		//
		((SetNthDat)param).getLRSHost ().setFirst (((SetNthDat)param).getDat ());
    return null;
	}

	/**
	 * @param host 
	 * @param param 
	 * @return 
	 */
	public Object nonZeroCase(Counter host, Object param)
	{
    ((SetNthDat) param).getCounterHost ().decrement ();
    LRStruct nextLRS = ((SetNthDat) param).getLRSHost ().getRest ();
    ((SetNthDat) param).setLRSHost (nextLRS);
		return nextLRS.execute (this, param);
	}

	public static Object MakeInputDat(int ix, LRStruct lrsHost, Object dat)
	{
      return new SetNthDat (ix, lrsHost, dat);
	}

	/**
	 * @return 
	 * @SBGen Singleton 
	 */
	public final static SetNth Singleton()
	{
		// SBgen: Ensure single instance
		if (instance == null) 
			instance = new SetNth();
		return(instance);
		// SBgen: End singleton
	}
}

