package listFW.visitor; import listFW.*; /** * Sums all the elements in the host list, assuming it contains all Integer. * @author DXN */ public class Sum implements IListAlgo { public Object emptyCase(IEmptyList host, Object inp) { return new Integer(0); } public Object nonEmptyCase(INEList host, Object inp) { int f = ((Integer)host.getFirst()).intValue(); int r = ((Integer)host.getRest().execute(this, null)).intValue(); return new Integer(f + r); } }