X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.spreadsheet.graph%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fgraph%2Fformula%2FCountifFormulaFunction.java;fp=bundles%2Forg.simantics.spreadsheet.graph%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fgraph%2Fformula%2FCountifFormulaFunction.java;h=f34b89f5a57026ab818f516cd95517b9fa06ae1c;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=c2f2b1222cb5ed8a53ba2dd8eb0bf5f0fb80e34c;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/CountifFormulaFunction.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/CountifFormulaFunction.java index c2f2b1222..f34b89f5a 100644 --- a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/CountifFormulaFunction.java +++ b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/CountifFormulaFunction.java @@ -1,33 +1,33 @@ -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 { - - @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); - } -} +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 { + + @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); + } +}