1 16 17 package org.apache.taglibs.standard.lang.jstl; 18 19 26 27 public class ModulusOperator 28 extends BinaryOperator 29 { 30 34 public static final ModulusOperator SINGLETON = 35 new ModulusOperator (); 36 37 42 public ModulusOperator () 43 { 44 } 45 46 53 public String getOperatorSymbol () 54 { 55 return "%"; 56 } 57 58 63 public Object apply (Object pLeft, 64 Object pRight, 65 Object pContext, 66 Logger pLogger) 67 throws ELException 68 { 69 if (pLeft == null && 70 pRight == null) { 71 if (pLogger.isLoggingWarning ()) { 72 pLogger.logWarning 73 (Constants.ARITH_OP_NULL, 74 getOperatorSymbol ()); 75 } 76 return PrimitiveObjects.getInteger (0); 77 } 78 79 if ((pLeft != null && 80 (Coercions.isFloatingPointType (pLeft) || 81 Coercions.isFloatingPointString (pLeft))) || 82 (pRight != null && 83 (Coercions.isFloatingPointType (pRight) || 84 Coercions.isFloatingPointString (pRight)))) { 85 double left = 86 Coercions.coerceToPrimitiveNumber (pLeft, Double .class, pLogger). 87 doubleValue (); 88 double right = 89 Coercions.coerceToPrimitiveNumber (pRight, Double .class, pLogger). 90 doubleValue (); 91 92 try { 93 return PrimitiveObjects.getDouble (left % right); 94 } 95 catch (Exception exc) { 96 if (pLogger.isLoggingError ()) { 97 pLogger.logError 98 (Constants.ARITH_ERROR, 99 getOperatorSymbol (), 100 "" + left, 101 "" + right); 102 } 103 return PrimitiveObjects.getInteger (0); 104 } 105 } 106 else { 107 long left = 108 Coercions.coerceToPrimitiveNumber (pLeft, Long .class, pLogger). 109 longValue (); 110 long right = 111 Coercions.coerceToPrimitiveNumber (pRight, Long .class, pLogger). 112 longValue (); 113 114 try { 115 return PrimitiveObjects.getLong (left % right); 116 } 117 catch (Exception exc) { 118 if (pLogger.isLoggingError ()) { 119 pLogger.logError 120 (Constants.ARITH_ERROR, 121 getOperatorSymbol (), 122 "" + left, 123 "" + right); 124 } 125 return PrimitiveObjects.getInteger (0); 126 } 127 } 128 } 129 130 } 132 | Popular Tags |