1 16 17 package org.apache.taglibs.standard.lang.jstl; 18 19 26 27 public class UnaryMinusOperator 28 extends UnaryOperator 29 { 30 34 public static final UnaryMinusOperator SINGLETON = 35 new UnaryMinusOperator (); 36 37 42 public UnaryMinusOperator () 43 { 44 } 45 46 53 public String getOperatorSymbol () 54 { 55 return "-"; 56 } 57 58 63 public Object apply (Object pValue, 64 Object pContext, 65 Logger pLogger) 66 throws ELException 67 { 68 if (pValue == null) { 69 76 return PrimitiveObjects.getInteger (0); 77 } 78 79 else if (pValue instanceof String ) { 80 if (Coercions.isFloatingPointString (pValue)) { 81 double dval = 82 ((Number ) 83 (Coercions.coerceToPrimitiveNumber 84 (pValue, Double .class, pLogger))). 85 doubleValue (); 86 return PrimitiveObjects.getDouble (-dval); 87 } 88 else { 89 long lval = 90 ((Number ) 91 (Coercions.coerceToPrimitiveNumber 92 (pValue, Long .class, pLogger))). 93 longValue (); 94 return PrimitiveObjects.getLong (-lval); 95 } 96 } 97 98 else if (pValue instanceof Byte ) { 99 return PrimitiveObjects.getByte 100 ((byte) -(((Byte ) pValue).byteValue ())); 101 } 102 else if (pValue instanceof Short ) { 103 return PrimitiveObjects.getShort 104 ((short) -(((Short ) pValue).shortValue ())); 105 } 106 else if (pValue instanceof Integer ) { 107 return PrimitiveObjects.getInteger 108 ((int) -(((Integer ) pValue).intValue ())); 109 } 110 else if (pValue instanceof Long ) { 111 return PrimitiveObjects.getLong 112 ((long) -(((Long ) pValue).longValue ())); 113 } 114 else if (pValue instanceof Float ) { 115 return PrimitiveObjects.getFloat 116 ((float) -(((Float ) pValue).floatValue ())); 117 } 118 else if (pValue instanceof Double ) { 119 return PrimitiveObjects.getDouble 120 ((double) -(((Double ) pValue).doubleValue ())); 121 } 122 123 else { 124 if (pLogger.isLoggingError ()) { 125 pLogger.logError 126 (Constants.UNARY_OP_BAD_TYPE, 127 getOperatorSymbol (), 128 pValue.getClass ().getName ()); 129 } 130 return PrimitiveObjects.getInteger (0); 131 } 132 } 133 134 } 136 | Popular Tags |