001 package lrs.visitor; 002 import lrs.*; 003 import logic.*; 004 005 // This visitor returns the minimum value from a list 006 public class GetMin extends AGetExtrema 007 { 008 public static GetMin Singleton = new GetMin(); 009 010 private GetMin() 011 { 012 } 013 014 public Object emptyCase(LRStruct host, Object... param) 015 { 016 return(Integer.MAX_VALUE); // The empty list has a valid return object that will always fail a compare. 017 } 018 019 public Object nonEmptyCase(LRStruct host, Object... param) 020 { 021 Integer tmp = (Integer) host.getRest().execute(this, param); // Get the min of the rest of the list 022 023 //return the data that passes the compare test. 024 // if(tmp.intValue() < ((Integer)host.getFirst()).intValue()) return (tmp); 025 // else return (host.getFirst()); 026 return BooleanFactory.Singleton.makeBoolean(tmp < (Integer) host.getFirst()).execute(BooleanChoice.Singleton, tmp, host.getFirst()); 027 } 028 029 }