FilterN.java
Created with JBuilder
package lrs.visitor;

import lrs.IAlgo;
import lrs.LRStruct;

/**
 * Removes multiples of the input N (> 0) from the host.
 * @author D. X. Nguyen
 */
public class FilterN implements IAlgo {

    public static final FilterN Singleton = new FilterN();
    private FilterN() {
    }

    public Object emptyCase(LRStruct host, Object N) {
        return null;
    }

    /**
     * @param N Integer > 0.
     */
    public Object nonEmptyCase(LRStruct host, Object N) {
        int n = ((Integer)N).intValue();
        int f = ((Integer)host.getFirst()).intValue();
        if (f % n == 0) {
            host.removeFront();
            return host.execute(this, N);
        }
        return host.getRest().execute(this, N) ;
    }
}

FilterN.java
Created with JBuilder