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