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 GMultiply extends PostfixMathCommand { 20 private RingI group = null; 21 24 private GMultiply() { } 25 public GMultiply(GroupI group) 26 { 27 numberOfParameters = -1; 28 if(group instanceof RingI) 29 this.group = (RingI) group; 30 } 31 32 36 public void run(Stack stack) throws ParseException { 37 if(group==null) throw new ParseException("Multiply not implemented for this group."); 38 checkStack(stack); 40 Object sum = stack.pop(); 41 Object param; 42 int i = 1; 43 44 while (i < curNumberOfParameters) { 46 param = stack.pop(); 48 sum = mul(param, sum); 50 i++; 51 } 52 stack.push(sum); 53 return; 54 } 55 56 public Object mul(Object param1, Object param2) throws ParseException { 57 if (param1 instanceof Number ) { 58 if (param2 instanceof Number ) { 59 return group.mul((Number )param1, (Number )param2); 60 } 61 } 62 63 throw new ParseException("Invalid parameter type"); 64 } 65 } 66 | Popular Tags |