01: /* Generated By:JJTree: Do not edit this line. AstNegative.java */
02:
03: package org.apache.el.parser;
04:
05: import java.math.BigDecimal;
06: import java.math.BigInteger;
07:
08: import javax.el.ELException;
09:
10: import org.apache.el.lang.EvaluationContext;
11:
12: /**
13: * @author Jacob Hookom [jacob@hookom.net]
14: * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: markt $
15: */
16: public final class AstNegative extends SimpleNode {
17: public AstNegative(int id) {
18: super (id);
19: }
20:
21: public Class getType(EvaluationContext ctx) throws ELException {
22: return Number.class;
23: }
24:
25: public Object getValue(EvaluationContext ctx) throws ELException {
26: Object obj = this .children[0].getValue(ctx);
27:
28: if (obj == null) {
29: return new Long(0);
30: }
31: if (obj instanceof BigDecimal) {
32: return ((BigDecimal) obj).negate();
33: }
34: if (obj instanceof BigInteger) {
35: return ((BigInteger) obj).negate();
36: }
37: if (obj instanceof String) {
38: if (isStringFloat((String) obj)) {
39: return new Double(-Double.parseDouble((String) obj));
40: }
41: return new Long(-Long.parseLong((String) obj));
42: }
43: Class type = obj.getClass();
44: if (obj instanceof Long || Long.TYPE == type) {
45: return new Long(-((Long) obj).longValue());
46: }
47: if (obj instanceof Double || Double.TYPE == type) {
48: return new Double(-((Double) obj).doubleValue());
49: }
50: if (obj instanceof Integer || Integer.TYPE == type) {
51: return new Integer(-((Integer) obj).intValue());
52: }
53: if (obj instanceof Float || Float.TYPE == type) {
54: return new Float(-((Float) obj).floatValue());
55: }
56: if (obj instanceof Short || Short.TYPE == type) {
57: return new Short((short) -((Short) obj).shortValue());
58: }
59: if (obj instanceof Byte || Byte.TYPE == type) {
60: return new Byte((byte) -((Byte) obj).byteValue());
61: }
62: Long num = (Long) coerceToNumber(obj, Long.class);
63: return new Long(-num.longValue());
64: }
65: }
|