package listFW.visitor;
import listFW.*;
/**
* Helps compute the last element in the list containing the host.
* The input parameter is the last element of the preceding list.
* @author D. X. Nguyen
*/
public class HelpGetLast implements IListAlgo {
public static final HelpGetLast Singleton = new HelpGetLast ();
private HelpGetLast () {
}
/**
* Returns the input parameter since this is the end of the list.
* @param host not used
* @param input the first element of the host's parent list.
* @return Object
*/
public Object emptyCase(IEmptyList host, Object input) {
return input;
}
/**
* Passes the host's first down to the host's rest and asks for help to
* figure out the last element in the host: recur!
* @param host a non-empty list
* @param input not used.
* @return Object
*/
public Object nonEmptyCase(INEList host, Object input) {
return host.getRest().execute(this, host.getFirst());
}
}