/** Applies the operator to the given value */ public Object apply(Object pLeft, Object pRight, Logger pLogger) throws EvaluatException { if (pLeft == null && pRight == null) { if (pLogger.isLoggingWarning()) { pLogger.logWarning(Constants.ARITH_OP_NULL, getOperatorSymbol()); } return PrimitiveObjects.getInteger(0); } if (Coercions.isBigDecimal(pLeft) || Coercions.isBigInteger(pLeft) || Coercions.isBigDecimal(pRight) || Coercions.isBigInteger(pRight)) { BigDecimal left = (BigDecimal) Coercions.coerceToPrimitiveNumber(pLeft, BigDecimal.class, pLogger); BigDecimal right = (BigDecimal) Coercions.coerceToPrimitiveNumber(pRight, BigDecimal.class, pLogger); try { return left.divide(right, BigDecimal.ROUND_HALF_UP); } catch (Exception exc) { if (pLogger.isLoggingError()) { pLogger.logError(Constants.ARITH_ERROR, getOperatorSymbol(), "" + left, "" + right); } return PrimitiveObjects.getInteger(0); } } else { double left = Coercions.coerceToPrimitiveNumber(pLeft, Double.class, pLogger).doubleValue(); double right = Coercions.coerceToPrimitiveNumber(pRight, Double.class, pLogger).doubleValue(); try { return PrimitiveObjects.getDouble(left / right); } catch (Exception exc) { if (pLogger.isLoggingError()) { pLogger.logError(Constants.ARITH_ERROR, getOperatorSymbol(), "" + left, "" + right); } return PrimitiveObjects.getInteger(0); } } }
/** Applies the operator to the given value */ public Object apply(Object pValue, Logger pLogger) throws EvaluatException { // See if the value is null if (pValue == null) { return PrimitiveObjects.getBoolean(true); } // See if the value is a zero-length String else if ("".equals(pValue)) { return PrimitiveObjects.getBoolean(true); } // See if the value is a zero-length array else if (pValue.getClass().isArray() && Array.getLength(pValue) == 0) { return PrimitiveObjects.getBoolean(true); } // See if the value is an empty Map else if (pValue instanceof Map && ((Map) pValue).isEmpty()) { return PrimitiveObjects.getBoolean(true); } // See if the value is an empty Collection else if (pValue instanceof Collection && ((Collection) pValue).isEmpty()) { return PrimitiveObjects.getBoolean(true); } // Otherwise, not empty else { return PrimitiveObjects.getBoolean(false); } }