/** * * @param object object * @return the result * @deprecated since 2.1, you should use the * {@link org.thymeleaf.standard.expression.IStandardConversionService} implementation * corresponding to the dialect you are using or the methods in * {@link EvaluationUtils}. * Will be removed in 3.0. */ @Deprecated public static BigDecimal evaluateAsNumber(final Object object) { return EvaluationUtils.evaluateAsNumber(object); }
@Deprecated public static BigDecimal evaluateAsNumber(final Object object) { return EvaluationUtils.evaluateAsNumber(object); }
null : EvaluationUtils.evaluateAsNumber(year)); final BigDecimal nMonth = (month == null? null : EvaluationUtils.evaluateAsNumber(month)); final BigDecimal nDay = (day == null? null : EvaluationUtils.evaluateAsNumber(day)); final BigDecimal nHour = (hour == null? null : EvaluationUtils.evaluateAsNumber(hour)); final BigDecimal nMinute = (minute == null? null : EvaluationUtils.evaluateAsNumber(minute)); final BigDecimal nSecond = (second == null? null : EvaluationUtils.evaluateAsNumber(second)); final BigDecimal nMillisecond = (millisecond == null? null : EvaluationUtils.evaluateAsNumber(millisecond));
final BigDecimal leftNumberValue = EvaluationUtils.evaluateAsNumber(leftValue); final BigDecimal rightNumberValue = EvaluationUtils.evaluateAsNumber(rightValue);
final BigDecimal leftNumberValue = EvaluationUtils.evaluateAsNumber(leftValue); final BigDecimal rightNumberValue = EvaluationUtils.evaluateAsNumber(rightValue);
static Object executeMinus( final IExpressionContext context, final MinusExpression expression, final StandardExpressionExecutionContext expContext) { if (logger.isTraceEnabled()) { logger.trace("[THYMELEAF][{}] Evaluating minus expression: \"{}\"", TemplateEngine.threadIndex(), expression.getStringRepresentation()); } Object operandValue = expression.getOperand().execute(context, expContext); if (operandValue == null) { operandValue = "null"; } final BigDecimal operandNumberValue = EvaluationUtils.evaluateAsNumber(operandValue); if (operandNumberValue != null) { // Addition will act as a mathematical 'plus' return operandNumberValue.multiply(BigDecimal.valueOf(-1)); } throw new TemplateProcessingException( "Cannot execute minus: operand is \"" + LiteralValue.unwrap(operandValue) + "\""); }
final BigDecimal leftNumberValue = EvaluationUtils.evaluateAsNumber(leftValue); final BigDecimal rightNumberValue = EvaluationUtils.evaluateAsNumber(rightValue); if (leftNumberValue != null && rightNumberValue != null) { try {
final BigDecimal leftNumberValue = EvaluationUtils.evaluateAsNumber(leftValue); final BigDecimal rightNumberValue = EvaluationUtils.evaluateAsNumber(rightValue);
static Object executeMultiplication( final IExpressionContext context, final MultiplicationExpression expression, final StandardExpressionExecutionContext expContext) { if (logger.isTraceEnabled()) { logger.trace("[THYMELEAF][{}] Evaluating multiplication expression: \"{}\"", TemplateEngine.threadIndex(), expression.getStringRepresentation()); } Object leftValue = expression.getLeft().execute(context, expContext); Object rightValue = expression.getRight().execute(context, expContext); if (leftValue == null) { leftValue = "null"; } if (rightValue == null) { rightValue = "null"; } final BigDecimal leftNumberValue = EvaluationUtils.evaluateAsNumber(leftValue); final BigDecimal rightNumberValue = EvaluationUtils.evaluateAsNumber(rightValue); if (leftNumberValue != null && rightNumberValue != null) { // Addition will act as a mathematical 'plus' return leftNumberValue.multiply(rightNumberValue); } throw new TemplateProcessingException( "Cannot execute multiplication: operands are \"" + LiteralValue.unwrap(leftValue) + "\" and \"" + LiteralValue.unwrap(rightValue) + "\""); }
static Object executeSubtraction( final IExpressionContext context, final SubtractionExpression expression, final StandardExpressionExecutionContext expContext) { if (logger.isTraceEnabled()) { logger.trace("[THYMELEAF][{}] Evaluating subtraction expression: \"{}\"", TemplateEngine.threadIndex(), expression.getStringRepresentation()); } Object leftValue = expression.getLeft().execute(context, expContext); Object rightValue = expression.getRight().execute(context, expContext); if (leftValue == null) { leftValue = "null"; } if (rightValue == null) { rightValue = "null"; } final BigDecimal leftNumberValue = EvaluationUtils.evaluateAsNumber(leftValue); final BigDecimal rightNumberValue = EvaluationUtils.evaluateAsNumber(rightValue); if (leftNumberValue != null && rightNumberValue != null) { // Addition will act as a mathematical 'plus' return leftNumberValue.subtract(rightNumberValue); } throw new TemplateProcessingException( "Cannot execute subtraction: operands are \"" + LiteralValue.unwrap(leftValue) + "\" and \"" + LiteralValue.unwrap(rightValue) + "\""); }
final BigDecimal leftNumberValue = EvaluationUtils.evaluateAsNumber(leftValue); final BigDecimal rightNumberValue = EvaluationUtils.evaluateAsNumber(rightValue);
final BigDecimal leftNumberValue = EvaluationUtils.evaluateAsNumber(leftValue); final BigDecimal rightNumberValue = EvaluationUtils.evaluateAsNumber(rightValue);
final BigDecimal leftNumberValue = EvaluationUtils.evaluateAsNumber(leftValue); final BigDecimal rightNumberValue = EvaluationUtils.evaluateAsNumber(rightValue);
static Object executeRemainder( final IExpressionContext context, final RemainderExpression expression, final StandardExpressionExecutionContext expContext) { if (logger.isTraceEnabled()) { logger.trace("[THYMELEAF][{}] Evaluating remainder expression: \"{}\"", TemplateEngine.threadIndex(), expression.getStringRepresentation()); } Object leftValue = expression.getLeft().execute(context, expContext); Object rightValue = expression.getRight().execute(context, expContext); if (leftValue == null) { leftValue = "null"; } if (rightValue == null) { rightValue = "null"; } final BigDecimal leftNumberValue = EvaluationUtils.evaluateAsNumber(leftValue); final BigDecimal rightNumberValue = EvaluationUtils.evaluateAsNumber(rightValue); if (leftNumberValue != null && rightNumberValue != null) { // Addition will act as a mathematical 'plus' return leftNumberValue.remainder(rightNumberValue); } throw new TemplateProcessingException( "Cannot execute division: operands are \"" + LiteralValue.unwrap(leftValue) + "\" and \"" + LiteralValue.unwrap(rightValue) + "\""); }
final BigDecimal leftNumberValue = EvaluationUtils.evaluateAsNumber(leftValue); if (leftNumberValue != null) { final BigDecimal rightNumberValue = EvaluationUtils.evaluateAsNumber(rightValue); if (rightNumberValue != null) {
private int integer(final Object number) { Validate.notNull(number, "Argument cannot be null"); return EvaluationUtils.evaluateAsNumber(number).intValue(); }