package list.visitor; import list.*; public class Append implements IListAlgo { public final static Append Singleton = new Append(); private Append() { } /** * @param input receives a list. * Returns the input list */ public Object forEmpty(AList host, Object input) { return input; } /** * Returns the appended lists. */ public Object forNonEmpty(AList host, Object input) { if ((AList)input == ListFactory.Singleton.makeEmptyList()) { return host; } else { return ListFactory.Singleton.makeNEList(host.getFirst(), (AList)host.getRest().execute(this, input)); } } }