aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache
diff options
context:
space:
mode:
authorJosh Micich <josh@apache.org>2009-02-02 19:42:57 +0000
committerJosh Micich <josh@apache.org>2009-02-02 19:42:57 +0000
commitd0f2a79c0723720f9c986a2061080b686264df83 (patch)
tree7d324b7265be142a72e347e29f0089bca5c74d48 /src/java/org/apache
parentf6fae6e2d1ab4f9dc08bdaa3059b5f040bb02f4e (diff)
downloadpoi-d0f2a79c0723720f9c986a2061080b686264df83.tar.gz
poi-d0f2a79c0723720f9c986a2061080b686264df83.zip
Fix for bug 46647 - COUNTIF NE operator and other special cases involving type conversion
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@740088 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/functions/Countif.java20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Countif.java b/src/java/org/apache/poi/hssf/record/formula/functions/Countif.java
index db973ec21b..babedab61d 100644
--- a/src/java/org/apache/poi/hssf/record/formula/functions/Countif.java
+++ b/src/java/org/apache/poi/hssf/record/formula/functions/Countif.java
@@ -128,7 +128,7 @@ public final class Countif implements Function {
case NONE:
case EQ:
return cmpResult == 0;
- case NE: return cmpResult == 0;
+ case NE: return cmpResult != 0;
case LT: return cmpResult < 0;
case LE: return cmpResult <= 0;
case GT: return cmpResult > 0;
@@ -160,14 +160,27 @@ public final class Countif implements Function {
double testValue;
if(x instanceof StringEval) {
// if the target(x) is a string, but parses as a number
- // it may still count as a match
+ // it may still count as a match, only for the equality operator
+ switch (_operator.getCode()) {
+ case CmpOp.EQ:
+ case CmpOp.NONE:
+ break;
+ case CmpOp.NE:
+ // Always matches (inconsistent with above two cases).
+ // for example '<>123' matches '123', '4', 'abc', etc
+ return true;
+ default:
+ // never matches (also inconsistent with above three cases).
+ // for example '>5' does not match '6',
+ return false;
+ }
StringEval se = (StringEval)x;
Double val = OperandResolver.parseDouble(se.getStringValue());
if(val == null) {
// x is text that is not a number
return false;
}
- testValue = val.doubleValue();
+ return _value == val.doubleValue();
} else if((x instanceof NumberEval)) {
NumberEval ne = (NumberEval) x;
testValue = ne.getNumberValue();
@@ -249,6 +262,7 @@ public final class Countif implements Function {
_pattern = getWildCardPattern(value);
break;
default:
+ // pattern matching is never used for < > <= =>
_pattern = null;
}
}