add comments, adjust whitespace

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1749276 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-06-20 08:50:36 +00:00
parent f3bd334002
commit 4036202ebc
2 changed files with 14 additions and 5 deletions

View File

@ -34,15 +34,22 @@ public class Countifs implements FreeRefFunction {
public static final FreeRefFunction instance = new Countifs();
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
Double result = null;
if (args.length == 0 || args.length % 2 > 0) {
// https://support.office.com/en-us/article/COUNTIFS-function-dda3dc6e-f74e-4aee-88bc-aa8c2a866842?ui=en-US&rs=en-US&ad=US
// COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2]...)
// need at least 2 arguments and need to have an even number of arguments (criteria_range1, criteria1 plus x*(criteria_range, criteria))
if (args.length < 2 || args.length % 2 != 0) {
return ErrorEval.VALUE_INVALID;
}
for (int i = 0; i < args.length; ) {
Double result = null;
// for each (criteria_range, criteria) pair
for (int i = 0; i < args.length; i += 2) {
ValueEval firstArg = args[i];
ValueEval secondArg = args[i + 1];
i += 2;
NumberEval evaluate = (NumberEval) new Countif().evaluate(new ValueEval[]{firstArg, secondArg}, ec.getRowIndex(), ec.getColumnIndex());
NumberEval evaluate = (NumberEval) new Countif().evaluate(
new ValueEval[] {firstArg, secondArg},
ec.getRowIndex(),
ec.getColumnIndex());
if (result == null) {
result = evaluate.getNumberValue();
} else if (evaluate.getNumberValue() < result) {

View File

@ -54,6 +54,8 @@ public final class Sumifs implements FreeRefFunction {
public static final FreeRefFunction instance = new Sumifs();
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
// https://support.office.com/en-us/article/SUMIFS-function-c9e748f5-7ea7-455d-9406-611cebce642b
// COUNTIFS(sum_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...
// need at least 3 arguments and need to have an odd number of arguments (sum-range plus x*(criteria_range, criteria))
if(args.length < 3 || args.length % 2 == 0) {
return ErrorEval.VALUE_INVALID;