package OOscheme.Visitor; import OOscheme.*; /** * Computes the length of the AList host. */ public class GetLength implements IListAlgo { /** * Singleton Pattern. */ public static final GetLength Singleton = new GetLength(); private GetLength() { } /** * Returns Integer(0). * @param host an EmptyList * @param inp not used * @return Integer. */ public Object emptyCase(AList host, Object inp) { return new Integer(0); } /** * Return the length of the host's rest plus 1. * @param host an NEList * @param inp not used. * @return Integer */ public Object nonEmptyCase(AList host, Object inp) { Integer restLen = (Integer)host.getRest().execute(this, null); return new Integer(1 + restLen.intValue()); } }