From 920859270f819b171a98149474b6b4edb724faf6 Mon Sep 17 00:00:00 2001 From: "Jaan Sepp, Anton Keks" Date: Wed, 4 Jan 2017 15:06:15 +0200 Subject: [PATCH] support for BigDecimal/BigInteger and Float/Double BigInteger and BigDecimal are not converted because it is slow, but conversion of all other Numbers to double is a single CPU instruction --- src/main/java/play/template2/GTJavaBase.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/play/template2/GTJavaBase.java b/src/main/java/play/template2/GTJavaBase.java index ec816d3..bdf5beb 100644 --- a/src/main/java/play/template2/GTJavaBase.java +++ b/src/main/java/play/template2/GTJavaBase.java @@ -11,6 +11,8 @@ import java.io.OutputStream; import java.io.StringWriter; +import java.math.BigDecimal; +import java.math.BigInteger; import java.util.*; @@ -216,9 +218,13 @@ public boolean evaluateCondition(Object test) { if (test instanceof Boolean) { return ((Boolean) test).booleanValue(); } else if (test instanceof String) { - return ((String) test).length() > 0; + return !((String) test).isEmpty(); + } else if (test instanceof BigInteger) { + return ((BigInteger) test).compareTo(BigInteger.ZERO) != 0; + } else if (test instanceof BigDecimal) { + return ((BigDecimal) test).compareTo(BigDecimal.ZERO) != 0; } else if (test instanceof Number) { - return ((Number) test).intValue() != 0; + return ((Number) test).doubleValue() != 0.0; } else if (test instanceof Collection) { return !((Collection) test).isEmpty(); } else if (test instanceof Map) {