package listFW.visitor; import listFW.*; import listFW.factory.*; public class RunSum implements IListAlgo { private IListFactory _lf; public RunSum(IListFactory lf) { _lf = lf; } public Object emptyCase(IEmptyList host, Object... nu) { return _lf.makeEmptyList(); } public Object nonEmptyCase(INEList host, Object... nu) { IList list = (IList)host.getRest().execute(new IListAlgo() { public Object emptyCase(IEmptyList h, Object... nu) { return _lf.makeEmptyList(); } public Object nonEmptyCase(INEList h, Object... acc) { int sum = (Integer)h.getFirst() +(Integer)acc[0]; IList l = (IList)h.getRest().execute(this, sum); l = _lf.makeNEList(sum, l); return l; } }, host.getFirst()); list = _lf.makeNEList(host.getFirst(), list); return list; } }