1 8 package org.lsmp.djep.groupJep.function; 9 import org.nfunk.jep.function.*; 10 import org.lsmp.djep.groupJep.*; 11 import org.lsmp.djep.groupJep.interfaces.*; 12 13 import java.util.*; 14 import org.nfunk.jep.*; 15 19 public class GDivide extends PostfixMathCommand { 20 private HasDivI group=null; 21 24 private GDivide() { } 25 public GDivide(GroupI group) 26 { 27 numberOfParameters = 2; 28 if(group instanceof HasDivI) 29 this.group = (HasDivI) group; 30 } 31 32 36 public void run(Stack stack) throws ParseException { 37 checkStack(stack); Object sum = stack.pop(); 39 Object param; 40 param = stack.pop(); 41 sum = div(param, sum); 42 stack.push(sum); 43 return; 44 } 45 46 public Object div(Object param1, Object param2) throws ParseException { 47 if(group==null) throw new ParseException("Divide not implemented for this group."); 48 if (param1 instanceof Number ) { 49 if (param2 instanceof Number ) { 50 return group.div((Number )param1, (Number )param2); 51 } 52 } 53 54 throw new ParseException("Invalid parameter type"); 55 } 56 } 57 | Popular Tags |