package listFW.visitor; import listFW.*; import listFW.factory.*; import listFW.visitor.*; /** * Returns the even-indexed elements of the host. * @author DXN */ public class Odd implements IListAlgo { private IListFactory _fact; private IListAlgo _evenHelp; public Odd(IListFactory f) { _fact = f; _evenHelp = new EvenHelp(_fact, this); } public Object emptyCase(IEmptyList host, Object nu) { return host; } /** */ public Object nonEmptyCase(INEList host, Object input) { return host.getRest().execute(_evenHelp, null); } } class EvenHelp implements IListAlgo { private IListFactory _fact; private IListAlgo _odd; public EvenHelp(IListFactory f, IListAlgo od) { _fact = f; _odd = od; } public Object emptyCase(IEmptyList host, Object nu) { return host; } /** */ public Object nonEmptyCase(INEList host, Object input) { IList evenRest = (IList)host.getRest().execute(_odd, null); return _fact.makeNEList(host.getFirst(), evenRest); } }