package OOscheme.visitor; import OOscheme.*; /** * Computes the length of the IList 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 nu not used * @return Integer. */ public Object emptyCase(IEmptyList host, Object... nu) { return 0; } /** * Return the length of the host's rest plus 1. * @param host an NEList * @param nu not used. * @return Integer */ public Object nonEmptyCase(INEList host, Object... nu) { Integer restLen = (Integer)host.getRest().execute(this); return 1 + restLen; } }