1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.el.parser;
20
21 import java.math.BigDecimal;
22 import java.math.BigInteger;
23
24 import javax.el.ELException;
25
26 import org.apache.el.lang.EvaluationContext;
27
28
29
30
31
32
33 public final class AstNegative extends SimpleNode {
34 public AstNegative(int id) {
35 super(id);
36 }
37
38 public Class getType(EvaluationContext ctx)
39 throws ELException {
40 return Number.class;
41 }
42
43 public Object getValue(EvaluationContext ctx)
44 throws ELException {
45 Object obj = this.children[0].getValue(ctx);
46
47 if (obj == null) {
48 return new Long(0);
49 }
50 if (obj instanceof BigDecimal) {
51 return ((BigDecimal) obj).negate();
52 }
53 if (obj instanceof BigInteger) {
54 return ((BigInteger) obj).negate();
55 }
56 if (obj instanceof String) {
57 if (isStringFloat((String) obj)) {
58 return new Double(-Double.parseDouble((String) obj));
59 }
60 return new Long(-Long.parseLong((String) obj));
61 }
62 if (obj instanceof Long) {
63 return new Long(-((Long) obj).longValue());
64 }
65 if (obj instanceof Double) {
66 return new Double(-((Double) obj).doubleValue());
67 }
68 if (obj instanceof Integer) {
69 return new Integer(-((Integer) obj).intValue());
70 }
71 if (obj instanceof Float) {
72 return new Float(-((Float) obj).floatValue());
73 }
74 if (obj instanceof Short) {
75 return new Short((short) -((Short) obj).shortValue());
76 }
77 if (obj instanceof Byte) {
78 return new Byte((byte) -((Byte) obj).byteValue());
79 }
80 Long num = (Long) coerceToNumber(obj, Long.class);
81 return new Long(-num.longValue());
82 }
83 }