* the generic AverageIfs version.
*/
public class AverageIf extends Baseifs {
-
public static final FreeRefFunction instance = new Averageifs();
@Override
protected ValueEval aggregateMatchingCells(Aggregator aggregator, AreaEval sumRange, AreaEval testRange, I_MatchPredicate mp)
throws EvaluationException {
- int height = testRange.getHeight();
- int width = testRange.getWidth();
+ final int height = testRange.getHeight();
+ final int width = testRange.getWidth();
for (int r = 0; r < height; r++) {
for (int c = 0; c < width; c++) {
ValueEval _testValue = testRange.getRelativeValue(r, c);
- ;
-
ValueEval _sumValue = sumRange.getRelativeValue(r, c);
- if (mp != null && mp.matches(_testValue)) { // aggregate only if all of the corresponding criteria specified are true for that cell.
+ if (mp != null && mp.matches(_testValue)) {
+ // aggregate only if all of the corresponding criteria specified are true for that cell.
if (_testValue instanceof ErrorEval) {
throw new EvaluationException((ErrorEval) _testValue);
}
return false;
}
-
@Override
protected Aggregator createAggregator() {
-
return new Aggregator() {
Double sum = 0.0;
Integer count = 0;
if (!(value instanceof NumberEval)) return;
- double d = ((NumberEval) value).getNumberValue();
+ final double d = ((NumberEval) value).getNumberValue();
sum += d;
count++;