001 package lrs.visitor; 002 003 import lrs.*; 004 import logic.*; 005 006 /** 007 * An algortihm on a LRStruct that will skip over all the leading multiples of the supplied value. 008 * The return value is the sub-list (a LRStruct) whose leading term is the first occurence of a 009 * non-multiple of the given value. Here the supplied value is assumed to be an Integer. 010 */ 011 public class SkipLeadMods implements IAlgo { 012 public static SkipLeadMods Singleton = new SkipLeadMods(); 013 private SkipLeadMods(){} 014 015 016 /** 017 * No multiples to be found in the empty list, so the list is returned. 018 * @param host 019 * @param param 020 * @return 021 */ 022 public Object emptyCase(LRStruct host, Object... param) 023 { 024 return (host); // NYI 025 } 026 027 /** 028 * Recursively searches for the first non-multiple of the given value (in param). 029 * @param host 030 * @param param 031 * @return 032 */ 033 public Object nonEmptyCase(final LRStruct host, final Object... param) 034 { 035 return BooleanFactory.Singleton.makeBoolean(((Integer) host.getFirst()) > ((Integer) param[0])). 036 execute( new IBooleanAlgo() { 037 public Object trueCase(IBoolean h, Object... inp) {; 038 return (host); // found the next one! 039 } 040 public Object falseCase(IBoolean h, Object... inp) { 041 return (host.getRest().execute (SkipLeadMods.this, param)); // keep looking, so recurse 042 } 043 }); 044 045 // if (((Integer) host.getFirst ()).intValue () % ((Integer)param[0]).intValue () != 0) 046 // { 047 // return (host); // found the next one! 048 // } 049 // else 050 // { 051 // return (host.getRest().execute (this, param)); // keep looking, so recurse 052 // } 053 } 054 } 055