-package org.simantics.spreadsheet.graph.formula;\r
-\r
-import org.simantics.spreadsheet.graph.CellFormulaFunction;\r
-import org.simantics.spreadsheet.graph.CellValueVisitor;\r
-import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils;\r
-import org.simantics.spreadsheet.graph.SpreadsheetMatrix;\r
-import org.simantics.spreadsheet.graph.parser.ast.AstArgList;\r
-import org.simantics.spreadsheet.graph.parser.ast.AstRange;\r
-\r
-public class CountifFormulaFunction implements CellFormulaFunction<Integer> {\r
-\r
- @Override\r
- public Integer evaluate(CellValueVisitor visitor, AstArgList args) {\r
- if (args.values.size() != 2) throw new IllegalStateException();\r
- \r
- AstRange range = (AstRange) args.values.get(0);\r
- SpreadsheetMatrix matrix = (SpreadsheetMatrix) range.accept(visitor);\r
- Object crit = null;\r
- try {\r
- crit = args.values.get(1).accept(visitor);\r
- } catch (IllegalStateException e){\r
- return 0;\r
- }\r
- \r
- String criteria = SpreadsheetGraphUtils.asString(crit);\r
- int result = 0;\r
- for (Object value : matrix.values) {\r
- if (SpreadsheetGraphUtils.matchCriteria(value, criteria))\r
- result++;\r
- }\r
- return Integer.valueOf(result);\r
- }\r
-}\r
+package org.simantics.spreadsheet.graph.formula;
+
+import org.simantics.spreadsheet.graph.CellFormulaFunction;
+import org.simantics.spreadsheet.graph.CellValueVisitor;
+import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils;
+import org.simantics.spreadsheet.graph.SpreadsheetMatrix;
+import org.simantics.spreadsheet.graph.parser.ast.AstArgList;
+import org.simantics.spreadsheet.graph.parser.ast.AstRange;
+
+public class CountifFormulaFunction implements CellFormulaFunction<Integer> {
+
+ @Override
+ public Integer evaluate(CellValueVisitor visitor, AstArgList args) {
+ if (args.values.size() != 2) throw new IllegalStateException();
+
+ AstRange range = (AstRange) args.values.get(0);
+ SpreadsheetMatrix matrix = (SpreadsheetMatrix) range.accept(visitor);
+ Object crit = null;
+ try {
+ crit = args.values.get(1).accept(visitor);
+ } catch (IllegalStateException e){
+ return 0;
+ }
+
+ String criteria = SpreadsheetGraphUtils.asString(crit);
+ int result = 0;
+ for (Object value : matrix.values) {
+ if (SpreadsheetGraphUtils.matchCriteria(value, criteria))
+ result++;
+ }
+ return Integer.valueOf(result);
+ }
+}