diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2018-07-17 21:49:09 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2018-07-17 21:49:09 +0000 |
commit | abe506f27c2d6c789eb53a43bcdbe0a258c596dd (patch) | |
tree | 6e125e88d8bd68d058ff80241690ec5b9bcff3b9 /src/main/java/com/healthmarketscience/jackcess/impl/expr | |
parent | 18a4998e71e239bba1712109f456dbea80067867 (diff) | |
download | jackcess-abe506f27c2d6c789eb53a43bcdbe0a258c596dd.tar.gz jackcess-abe506f27c2d6c789eb53a43bcdbe0a258c596dd.zip |
test number functions
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1183 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/main/java/com/healthmarketscience/jackcess/impl/expr')
3 files changed, 11 insertions, 7 deletions
diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/expr/BuiltinOperators.java b/src/main/java/com/healthmarketscience/jackcess/impl/expr/BuiltinOperators.java index 407ec52..eef7c77 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/BuiltinOperators.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/expr/BuiltinOperators.java @@ -56,6 +56,8 @@ public class BuiltinOperators public static final Value FALSE_VAL = new LongValue(0); public static final Value EMPTY_STR_VAL = new StringValue(""); public static final Value ZERO_VAL = FALSE_VAL; + public static final Value NEG_ONE_VAL = TRUE_VAL; + public static final Value ONE_VAL = new LongValue(1); private enum CoercionType { diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultNumberFunctions.java b/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultNumberFunctions.java index 4389d9f..d93463f 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultNumberFunctions.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultNumberFunctions.java @@ -147,14 +147,15 @@ public class DefaultNumberFunctions public static final Function SGN = registerFunc(new Func1NullIsNull("Sgn") { @Override protected Value eval1(EvalContext ctx, Value param1) { - int signum = 0; + int val = 0; if(param1.getType().isIntegral()) { - int lv = param1.getAsLongInt(); - signum = ((lv > 0) ? 1 : ((lv < 0) ? -1 : 0)); + val = param1.getAsLongInt(); } else { - signum = param1.getAsBigDecimal().signum(); + val = param1.getAsBigDecimal().signum(); } - return BuiltinOperators.toValue(signum); + return ((val > 0) ? BuiltinOperators.ONE_VAL : + ((val < 0) ? BuiltinOperators.NEG_ONE_VAL : + BuiltinOperators.ZERO_VAL)); } }); diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultTextFunctions.java b/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultTextFunctions.java index 7831d6e..de1159a 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultTextFunctions.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultTextFunctions.java @@ -309,8 +309,9 @@ public class DefaultTextFunctions int cmp = (ignoreCase ? s1.compareToIgnoreCase(s2) : s1.compareTo(s2)); // stupid java doesn't return 1, -1, 0... - cmp = ((cmp < 0) ? -1 : ((cmp > 0) ? 1 : 0)); - return BuiltinOperators.toValue(cmp); + return ((cmp < 0) ? BuiltinOperators.NEG_ONE_VAL : + ((cmp > 0) ? BuiltinOperators.ONE_VAL : + BuiltinOperators.ZERO_VAL)); } }); |