1 8 package org.lsmp.djep.xjep.function; 9 10 import java.util.Stack ; 11 12 import org.nfunk.jep.*; 13 import org.nfunk.jep.function.*; 14 15 19 public class MinArg extends SumType { 20 21 static Comparative comp = new Comparative(Comparative.LE); 22 23 public MinArg() { 24 super("MinArg"); 25 } 26 27 public Object evaluate(Object [] elements) throws ParseException { 28 throw new ParseException("MinArg: call to evaluate(Object[] elements) should not have happened."); 29 } 30 31 public Object evaluate( 32 Node node, 33 Variable var, 34 double min, 35 double max, 36 double inc, 37 Object data, 38 ParserVisitor pv, 39 Stack stack) 40 throws ParseException { 41 42 int i=0; 43 double val; 44 Object minVal=null; 45 Object minArg=null; 46 for(i=0,val=min;val<=max;++i,val=min+i*inc) 47 { 48 Object curArg = new Double (val); 49 var.setValue(curArg); 50 51 node.jjtGetChild(0).jjtAccept(pv,data); 52 checkStack(stack); Object res = stack.pop(); 54 if(i==0) 55 { 56 minVal = res; 57 minArg = curArg; 58 } 59 else if(comp.lt(res,minVal)) 60 { 61 minVal = res; 62 minArg = curArg; 63 } 64 } 65 stack.push(minArg); 66 return minArg; 67 68 } 69 70 } 71 | Popular Tags |