package scheme2.visitor; import scheme2.AListFW; import scheme2.IListAlgo; /** * Skips the first n elements and returns the remaining tail. */ public class SkipN implements IListAlgo { int _n; public SkipN( int n ) { _n = n; } /** * @param host * @param input not used. */ public Object forEmpty(AListFW host, Object input) { if( _n == 0 ) return host; throw new IllegalArgumentException ("Empty list has no data!"); } /** * @param host * @param input not used */ public Object forNonEmpty(AListFW host, Object input) { if( _n == 0 ) return host; else { _n--; return host.getRest().execute (this, null); } } }