1 23 24 package com.sun.el.parser; 25 26 import java.math.BigDecimal ; 27 import java.math.BigInteger ; 28 29 import javax.el.ELException; 30 31 import com.sun.el.lang.EvaluationContext; 32 33 37 public final class AstNegative extends SimpleNode { 38 public AstNegative(int id) { 39 super(id); 40 } 41 42 public Class getType(EvaluationContext ctx) 43 throws ELException { 44 return Number .class; 45 } 46 47 public Object getValue(EvaluationContext ctx) 48 throws ELException { 49 Object obj = this.children[0].getValue(ctx); 50 51 if (obj == null) { 52 return new Long (0); 53 } 54 if (obj instanceof BigDecimal ) { 55 return ((BigDecimal ) obj).negate(); 56 } 57 if (obj instanceof BigInteger ) { 58 return ((BigInteger ) obj).negate(); 59 } 60 if (obj instanceof String ) { 61 if (isStringFloat((String ) obj)) { 62 return new Double (-Double.parseDouble((String ) obj)); 63 } 64 return new Long (-Long.parseLong((String ) obj)); 65 } 66 Class type = obj.getClass(); 67 if (obj instanceof Long || Long.TYPE == type) { 68 return new Long (-((Long ) obj).longValue()); 69 } 70 if (obj instanceof Double || Double.TYPE == type) { 71 return new Double (-((Double ) obj).doubleValue()); 72 } 73 if (obj instanceof Integer || Integer.TYPE == type) { 74 return new Integer (-((Integer ) obj).intValue()); 75 } 76 if (obj instanceof Float || Float.TYPE == type) { 77 return new Float (-((Float ) obj).floatValue()); 78 } 79 if (obj instanceof Short || Short.TYPE == type) { 80 return new Short ((short) -((Short ) obj).shortValue()); 81 } 82 if (obj instanceof Byte || Byte.TYPE == type) { 83 return new Byte ((byte) -((Byte ) obj).byteValue()); 84 } 85 Long num = (Long ) coerceToNumber(obj, Long .class); 86 return new Long (-num.longValue()); 87 } 88 } 89 | Popular Tags |