package scheme2.visitor; import scheme2.AListFW; import scheme2.IListAlgo; public class MoveInParallel implements IListAlgo { AListFW _tailing; // _tailing "follows" the host while it traverses to its end. public MoveInParallel(AListFW list) { _tailing = list; } /** * @param host * @param input not used */ public Object forEmpty(AListFW host, Object input) { /*when the leading list gets to the end, we return the list that followed it*/ return _tailing; } /** * @param host * @param input */ public Object forNonEmpty(AListFW host, Object input) { /*tailing "follows" the host while it traverses to its end*/ _tailing = _tailing.getRest(); /*tailing is moved one spot ahead and now we call MoveInParallel for the rest of the list*/ return host.getRest().execute (this, null); } }