KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nfunk > jep > function > Not


1 /*****************************************************************************
2
3 JEP - Java Math Expression Parser 2.3.0
4       October 3 2004
5       (c) Copyright 2004, Nathan Funk and Richard Morris
6       See LICENSE.txt for license information.
7
8 *****************************************************************************/

9 package org.nfunk.jep.function;
10
11 import java.util.*;
12 import org.nfunk.jep.*;
13
14 public class Not extends PostfixMathCommand
15 {
16     public Not()
17     {
18         numberOfParameters = 1;
19     
20     }
21     
22     public void run(Stack inStack)
23         throws ParseException
24     {
25         checkStack(inStack);// check the stack
26
Object JavaDoc param = inStack.pop();
27         if (param instanceof Number JavaDoc)
28         {
29             int r = (((Number JavaDoc)param).doubleValue() == 0) ? 1 : 0;
30             inStack.push(new Double JavaDoc(r));//push the result on the inStack
31
}
32         else
33             throw new ParseException("Invalid parameter type");
34         return;
35     }
36
37 }
38
Popular Tags