KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lsmp > djep > groupJep > function > GSubtract


1 /* @author rich
2  * Created on 05-Mar-2004
3  *
4  * This code is covered by a Creative Commons
5  * Attribution, Non Commercial, Share Alike license
6  * <a HREF="http://creativecommons.org/licenses/by-nc-sa/1.0">License</a>
7  */

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 /**
15  * @author Rich Morris
16  * Created on 05-Mar-2004
17  */

18 public class GSubtract extends PostfixMathCommand {
19     private GroupI group;
20     /**
21      *
22      */

23     private GSubtract() { }
24     public GSubtract(GroupI group)
25     {
26         numberOfParameters = 2;
27         this.group = group;
28     }
29
30     /**
31      * Calculates the result of applying the "+" operator to the arguments from
32      * the stack and pushes it back on the stack.
33      */

34     public void run(Stack stack) throws ParseException {
35         checkStack(stack);// check the stack
36
Object JavaDoc sum = stack.pop();
37         Object JavaDoc param;
38         param = stack.pop();
39         sum = sub(param, sum);
40         stack.push(sum);
41         return;
42     }
43
44     public Object JavaDoc sub(Object JavaDoc param1, Object JavaDoc param2) throws ParseException {
45         if (param1 instanceof Number JavaDoc) {
46             if (param2 instanceof Number JavaDoc) {
47                 return group.sub((Number JavaDoc)param1, (Number JavaDoc)param2);
48             }
49         }
50         
51         throw new ParseException("Invalid parameter type");
52     }
53 }
54
Popular Tags