package schemeFactory.visitor; import schemeFactory.*; public class Zipper implements IListAlgo { private IListFactory _fact; public Zipper(IListFactory f) { _fact = f; } /** * Weaving an empty list with inp results in inp alone. * @param inp the other AList to be weaved with host. * @return AList */ public Object emptyCase(AList host, Object inp) { return inp; } /** * Recursively weave inp with host's rest. Then "cons" * host's first with the result. * @param inp the other AList to be weaved with host. * @return AList */ public Object nonEmptyCase(AList host, Object inp) { Object zipRest = ((AList)inp).execute(this, host.getRest()); return _fact.makeNEList(host.getFirst(), (AList)zipRest); } }