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 MaxArg extends SumType { 20 21 static Comparative comp = new Comparative(Comparative.LE); 22 23 public MaxArg() { 24 super("MaxArg"); 25 } 26 27 public Object evaluate(Object [] elements) throws ParseException { 28 throw new ParseException("MaxArg: 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 maxVal=null; 45 Object maxArg=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 maxVal = res; 57 maxArg = curArg; 58 } 59 else if(comp.gt(res,maxVal)) 60 { 61 maxVal = res; 62 maxArg = curArg; 63 } 64 } 65 stack.push(maxArg); 66 return maxArg; 67 } 68 69 } 70 | Popular Tags |