KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.*;
12 import org.nfunk.jep.*;
13 /**
14  * @author Rich Morris
15  * Created on 05-Mar-2004
16  */

17 public class GUMinus extends PostfixMathCommand {
18     private GroupI group;
19     /**
20      *
21      */

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

33     public void run(Stack stack) throws ParseException {
34         checkStack(stack);// check the stack
35

36         Object JavaDoc sum = stack.pop();
37         stack.push(uminus(sum));
38         return;
39     }
40
41     public Object JavaDoc uminus(Object JavaDoc param1) throws ParseException {
42         if (param1 instanceof Number JavaDoc) {
43                 return group.getInverse((Number JavaDoc)param1);
44         }
45         throw new ParseException("Invalid parameter type");
46     }
47 }
48
Popular Tags