package listFW.visitor; import listFW.*; /** * Computes the number of elements in a list, using a helper. * @author D. X. Nguyen * @since Copyright 2002 - DXN All rights reserved */ public class GetLen implements IListAlgo { public static final GetLen Singleton = new GetLen(); private GetLen() { } /** * Returns 0 because the empty list has no elements. * @param host an empty list. * @param nu not used. * @return Integer(0) */ public Object emptyCase(IEmptyList host, Object nu) { return new Integer(0); } /** * Passes the accumulated length (1) to the rest and * asks for help to compute the length. * @param host a non-empty list. * @param nu not used. * @return Integer */ public Object nonEmptyCase(INEList host, Object nu) { return host.getRest().execute(GetLenHelp.Singleton, new Integer(1)); } }