1 package org.simantics.spreadsheet.graph.formula;
3 import org.simantics.spreadsheet.graph.CellFormulaFunction;
4 import org.simantics.spreadsheet.graph.CellValueVisitor;
5 import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils;
6 import org.simantics.spreadsheet.graph.SpreadsheetMatrix;
7 import org.simantics.spreadsheet.graph.parser.ast.AstArgList;
8 import org.simantics.spreadsheet.graph.parser.ast.AstRange;
10 public class CountifFormulaFunction implements CellFormulaFunction<Integer> {
13 public Integer evaluate(CellValueVisitor visitor, AstArgList args) {
14 if (args.values.size() != 2) throw new IllegalStateException();
16 AstRange range = (AstRange) args.values.get(0);
17 SpreadsheetMatrix matrix = (SpreadsheetMatrix) range.accept(visitor);
20 crit = args.values.get(1).accept(visitor);
21 } catch (IllegalStateException e){
25 String criteria = SpreadsheetGraphUtils.asString(crit);
27 for (Object value : matrix.values) {
28 if (SpreadsheetGraphUtils.matchCriteria(value, criteria))
31 return Integer.valueOf(result);