package OOscheme.Visitor; import OOscheme.*; public class GetMinHelper implements IListAlgo { /** * Singleton Pattern. */ public static final GetMinHelper Singleton = new GetMinHelper(); private GetMinHelper() { } /** * Returns inp. * @param host an EmptyList * @param inp Integer the minimum of the preceding list. * @return Integer */ public Object emptyCase(AList host, Object inp) { return inp; } /** * Recurs by passing the mimum between the host's first and inp, the * accumulated current minimum. * @param host an NEList. * @param inp Integer the minimum of the preceding list. * @return Integer */ public Object nonEmptyCase(AList host, Object inp) { int f = ((Integer)host.getFirst()).intValue(); int i = ((Integer)inp).intValue(); return host.getRest().execute(this, new Integer(Math.min(f, i))); } }