KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > el > parser > AstNegative


1 /* Generated By:JJTree: Do not edit this line. AstNegative.java */
2
3 package org.apache.el.parser;
4
5 import java.math.BigDecimal JavaDoc;
6 import java.math.BigInteger JavaDoc;
7
8 import javax.el.ELException;
9
10 import org.apache.el.lang.EvaluationContext;
11
12
13 /**
14  * @author Jacob Hookom [jacob@hookom.net]
15  * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: markt $
16  */

17 public final class AstNegative extends SimpleNode {
18     public AstNegative(int id) {
19         super(id);
20     }
21
22     public Class JavaDoc getType(EvaluationContext ctx)
23             throws ELException {
24         return Number JavaDoc.class;
25     }
26
27     public Object JavaDoc getValue(EvaluationContext ctx)
28             throws ELException {
29         Object JavaDoc obj = this.children[0].getValue(ctx);
30
31         if (obj == null) {
32             return new Long JavaDoc(0);
33         }
34         if (obj instanceof BigDecimal JavaDoc) {
35             return ((BigDecimal JavaDoc) obj).negate();
36         }
37         if (obj instanceof BigInteger JavaDoc) {
38             return ((BigInteger JavaDoc) obj).negate();
39         }
40         if (obj instanceof String JavaDoc) {
41             if (isStringFloat((String JavaDoc) obj)) {
42                 return new Double JavaDoc(-Double.parseDouble((String JavaDoc) obj));
43             }
44             return new Long JavaDoc(-Long.parseLong((String JavaDoc) obj));
45         }
46         Class JavaDoc type = obj.getClass();
47         if (obj instanceof Long JavaDoc || Long.TYPE == type) {
48             return new Long JavaDoc(-((Long JavaDoc) obj).longValue());
49         }
50         if (obj instanceof Double JavaDoc || Double.TYPE == type) {
51             return new Double JavaDoc(-((Double JavaDoc) obj).doubleValue());
52         }
53         if (obj instanceof Integer JavaDoc || Integer.TYPE == type) {
54             return new Integer JavaDoc(-((Integer JavaDoc) obj).intValue());
55         }
56         if (obj instanceof Float JavaDoc || Float.TYPE == type) {
57             return new Float JavaDoc(-((Float JavaDoc) obj).floatValue());
58         }
59         if (obj instanceof Short JavaDoc || Short.TYPE == type) {
60             return new Short JavaDoc((short) -((Short JavaDoc) obj).shortValue());
61         }
62         if (obj instanceof Byte JavaDoc || Byte.TYPE == type) {
63             return new Byte JavaDoc((byte) -((Byte JavaDoc) obj).byteValue());
64         }
65         Long JavaDoc num = (Long JavaDoc) coerceToNumber(obj, Long JavaDoc.class);
66         return new Long JavaDoc(-num.longValue());
67     }
68 }
69
Popular Tags