package lrs.visitor; import lrs.*; /** * Replaces each Integer element in the host with modulo N, * where N > 0 is the input. * @author D. X. Nguyen */ public class ModN implements IAlgo { public static final ModN Singleton = new ModN(); private ModN() { } public Object emptyCase(LRStruct host, Object N) { return null; } public Object nonEmptyCase(LRStruct host, Object N) { int n = ((Integer)N).intValue(); int f = ((Integer)host.getFirst()).intValue(); return host.setFirst(new Integer(f % n)).getRest().execute(this, N); } }