1 8 package org.lsmp.djep.groupJep.function; 9 import org.nfunk.jep.function.*; 10 import org.lsmp.djep.groupJep.*; 11 12 import java.util.*; 13 import org.nfunk.jep.*; 14 18 public class GAdd extends PostfixMathCommand { 19 private GroupI group; 20 23 private GAdd() { } 24 public GAdd(GroupI group) 25 { 26 numberOfParameters = -1; 27 this.group = group; 28 } 29 30 34 public void run(Stack stack) throws ParseException { 35 checkStack(stack); 37 Object sum = stack.pop(); 38 Object param; 39 int i = 1; 40 41 while (i < curNumberOfParameters) { 43 param = stack.pop(); 45 sum = add(param, sum); 47 i++; 48 } 49 stack.push(sum); 50 return; 51 } 52 53 public Object add(Object param1, Object param2) throws ParseException { 54 if (param1 instanceof Number ) { 55 if (param2 instanceof Number ) { 56 return group.add((Number )param1, (Number )param2); 57 } 58 } 59 60 throw new ParseException("Invalid parameter type"); 61 } 62 } 63 | Popular Tags |