
package LRSVisitor;

import LRStructure.*;
import Counter.*;
public class LRSTrim implements IAlgo, ICounterAlgo
{
	public Object nullCase(LRStruct host, Object param)
	{
		return(null);
	}

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

	/**
	 * @param host 
	 * @param param 
	 */
	public Object zeroCase(Counter host, Object param)
	{
		((LRStruct)param).setRest(new LRStruct());
		((LRStruct)param).removeFirst();
		return(null);
	}

	/**
	 * @param host 
	 * @param param 
	 */
	public Object nonZeroCase(Counter host, Object param)
	{
		return ((LRStruct) param).getRest().execute(this,host.decrement());  // recurse on the rest of the list
	}
}

