import schemeFW.*; /** * Inserts an Integer into an ordered host list, assuming the host list contains * only Integer objects. Makes use of a list factory (IListFactory) to create * IList objects instead of calling their constructors directly. * @author D. X. Nguyen */ public class InsertInOrderWithFactory implements IListAlgo { private IListFactory _listFact; public InsertInOrderWithFactory(IListFactory lf) { _listFact = lf; } /** * This is easy, don't you think? * @param inp an Integer to be inserted in order into host. */ public Object emptyCase(IEmptyList host, Object inp) { return _listFact.makeNEList(inp, host); } /** * Recur! * @param inp an Integer to be inserted in order into host. */ public Object nonEmptyCase(INEList host, Object inp) { int n = ((Integer)inp).intValue(); int f = ((Integer)host.getFirst()).intValue(); return n < f? _listFact.makeNEList(inp, host): _listFact.makeNEList(host.getFirst(), (IList)host.getRest().execute(this, inp)); } }