package listFW.visitor; import listFW.*; /** * Accepts as input the accumulated sum of the list preceding the host and * adds the sum of the host to the accumulated sum. * @author DXN */ public class HelpGetSum implements IListAlgo { /** * @param inp Integer the accumulated sum of the list preceding host. * @return Integer inp - we are done! */ public Object emptyCase(IEmptyList host, Object inp) { return inp; } /** * Adds the host's first to inp and recurs by passing the resulting sum to * the rest. * @param inp Integer the accumulated sum of the list preceding host. * @return Integer */ public Object nonEmptyCase(INEList host, Object inp) { int f = ((Integer)host.getFirst()).intValue(); int acc = ((Integer)inp).intValue(); return host.getRest().execute(this, new Integer(f + acc)); } }