package listFW.visitor; import listFW.*; /** * Reverses the host given the reverse of the list * preceding the host. * Passes the accumulated reverse to the constructor. * @author D. X. Nguyen * @custom Copyright 2002 - All rights reserved */ class HelpReverse implements IListAlgo { private IListFactory _fact; public HelpReverse(IListFactory f) { _fact = f; } /** * Returns the accumulated reverse because * this is the end of the list. * @param host not used * @param acc an INEList, the accumulated reverse * of the list preceding host. * @return acc */ public Object emptyCase(IEmptyList host, Object acc) { return acc; } /** * Accumulates the reverse by cons-ing the * host's first with the accumulated * reverse so far, and recur on the host's rest. * @param host the rest of the list to be reversed. * @param acc an INEList, the accumulated reverse * of the list preceding host. * @return IList */ public Object nonEmptyCase(INEList host, Object acc) { return host.getRest().execute (this, _fact.makeNEList(host.getFirst(), (IList)acc)); } }