package listFW.visitor; import listFW.*; import listFW.factory.*; import listFW.visitor.*; /** * Returns the even-indexed elements of the host. * @author DXN */ public class Even implements IListAlgo { private IListFactory _fact; private IListAlgo _oddHelp; public Even(IListFactory f) { _fact = f; _oddHelp = new OddHelp(_fact, this); } public Object emptyCase(IEmptyList host, Object nu) { return host; } /** */ public Object nonEmptyCase(INEList host, Object input) { IList evenRest = (IList)host.getRest().execute(_oddHelp, null); return _fact.makeNEList(host.getFirst(), evenRest); } } /** * Helper returning the odd-indexed elements of the host. * @author DXN */ class OddHelp implements IListAlgo { private IListFactory _fact; private IListAlgo _even; public OddHelp(IListFactory f, IListAlgo e) { _fact = f; _even = e; } public Object emptyCase(IEmptyList host, Object nu) { return host; } /** */ public Object nonEmptyCase(INEList host, Object input) { return host.getRest().execute(_even, null); } }