From 3bdc1bd16a29ebc977dce397d1266d7e98d50f75 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Wed, 25 May 2022 18:18:40 +0000 Subject: [PATCH] revert change to IDStarAlgorithm.processMatch git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1901252 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/poi/ss/formula/functions/DCount.java | 4 ++-- .../java/org/apache/poi/ss/formula/functions/DGet.java | 2 +- .../java/org/apache/poi/ss/formula/functions/DMax.java | 2 +- .../java/org/apache/poi/ss/formula/functions/DMin.java | 2 +- .../org/apache/poi/ss/formula/functions/DStarRunner.java | 9 +++++++-- .../java/org/apache/poi/ss/formula/functions/DSum.java | 2 +- .../apache/poi/ss/formula/functions/IDStarAlgorithm.java | 3 +-- 7 files changed, 14 insertions(+), 10 deletions(-) diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/DCount.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/DCount.java index a367eca814..0fda8fa32c 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/DCount.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/DCount.java @@ -29,8 +29,8 @@ public final class DCount implements IDStarAlgorithm { private int count; @Override - public boolean processMatch(ValueEval eval, int fieldNumber) { - if (fieldNumber < 0 || eval instanceof NumericValueEval) { + public boolean processMatch(ValueEval eval) { + if (eval instanceof NumericValueEval) { count++; } return true; diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/DGet.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/DGet.java index 34c2900462..78b1b9235e 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/DGet.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/DGet.java @@ -31,7 +31,7 @@ public final class DGet implements IDStarAlgorithm { private ValueEval result; @Override - public boolean processMatch(ValueEval eval, int fieldNumber) { + public boolean processMatch(ValueEval eval) { if(result == null) // First match, just set the value. { result = eval; diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/DMax.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/DMax.java index 77b4624406..4d442f0415 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/DMax.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/DMax.java @@ -33,7 +33,7 @@ public final class DMax implements IDStarAlgorithm { private ValueEval maximumValue; @Override - public boolean processMatch(ValueEval eval, int fieldNumber) { + public boolean processMatch(ValueEval eval) { if(eval instanceof NumericValueEval) { if(maximumValue == null) { // First match, just set the value. maximumValue = eval; diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/DMin.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/DMin.java index 216d194ca5..61b75768c7 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/DMin.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/DMin.java @@ -33,7 +33,7 @@ public final class DMin implements IDStarAlgorithm { private ValueEval minimumValue; @Override - public boolean processMatch(ValueEval eval, int fieldNumber) { + public boolean processMatch(ValueEval eval) { if(eval instanceof NumericValueEval) { if(minimumValue == null) { // First match, just set the value. minimumValue = eval; diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/DStarRunner.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/DStarRunner.java index 5c014802aa..9a2e2637eb 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/DStarRunner.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/DStarRunner.java @@ -23,7 +23,9 @@ import org.apache.poi.ss.formula.eval.AreaEval; import org.apache.poi.ss.formula.eval.BlankEval; import org.apache.poi.ss.formula.eval.ErrorEval; import org.apache.poi.ss.formula.eval.EvaluationException; +import org.apache.poi.ss.formula.eval.MissingArgEval; import org.apache.poi.ss.formula.eval.NotImplementedException; +import org.apache.poi.ss.formula.eval.NumberEval; import org.apache.poi.ss.formula.eval.NumericValueEval; import org.apache.poi.ss.formula.eval.OperandResolver; import org.apache.poi.ss.formula.eval.StringEval; @@ -138,10 +140,13 @@ public final class DStarRunner implements Function3Arg { return ErrorEval.VALUE_INVALID; } // Filter each entry. - if(matches) { + if (matches) { ValueEval currentValueEval = resolveReference(db, row, fc); + if (fc < 0 && algorithm.allowEmptyMatchField() && !(currentValueEval instanceof NumericValueEval)) { + currentValueEval = NumberEval.ZERO; + } // Pass the match to the algorithm and conditionally abort the search. - boolean shouldContinue = algorithm.processMatch(currentValueEval, fc); + boolean shouldContinue = algorithm.processMatch(currentValueEval); if(! shouldContinue) { break; } diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/DSum.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/DSum.java index 758b2481c3..26604677de 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/DSum.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/DSum.java @@ -33,7 +33,7 @@ public final class DSum implements IDStarAlgorithm { private double totalValue = 0; @Override - public boolean processMatch(ValueEval eval, int fieldNumber) { + public boolean processMatch(ValueEval eval) { if(eval instanceof NumericValueEval) { double currentValue = ((NumericValueEval)eval).getNumberValue(); totalValue += currentValue; diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/IDStarAlgorithm.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/IDStarAlgorithm.java index dff5eb227f..0d8d52266e 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/IDStarAlgorithm.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/IDStarAlgorithm.java @@ -27,10 +27,9 @@ public interface IDStarAlgorithm { /** * Process a match that is found during a run through a database. * @param eval ValueEval of the cell in the matching row. References will already be resolved. - * @param fieldNumber the field number (added in POI 5.2.3) * @return Whether we should continue iterating through the database. */ - boolean processMatch(ValueEval eval, int fieldNumber); + boolean processMatch(ValueEval eval); /** * Return a result ValueEval that will be the result of the calculation. -- 2.39.5