package OOscheme.visitor; import OOscheme.*; public class GetMinHelper implements IListAlgo { /** * Singleton Pattern. */ public static final GetMinHelper Singleton = new GetMinHelper(); private GetMinHelper() { } /** * Returns inp[0]. * @param host an empty list * @param inp Integer[] inp[0] is the minimum of the preceding list. * @return Integer */ public Object emptyCase(IEmptyList host, Object... inp) { return inp[0]; } /** * Recurs by passing the mimum between the host's first and inp, the * accumulated current minimum. * @param host a non-empty list * @param inp Integer[] inp[0] is the minimum of the preceding list. * @return Integer */ public Object nonEmptyCase(INEList host, Object... inp) { int f = (Integer)host.getFirst(); // auto-unboxing int i = (Integer)inp[0]; // auto-unboxing return host.getRest().execute(this, Math.min(f, i)); // auto-boxing of Math.min(f, i) } }