X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.spreadsheet.graph%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fgraph%2Fformula%2FSumFormulaFunction.java;h=299973db59329d0d56ea9dfff0e5f1251b4fbcc1;hp=2163094e3777192f0ff5360862071d386bfac96c;hb=refs%2Fchanges%2F38%2F238%2F2;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/SumFormulaFunction.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/SumFormulaFunction.java index 2163094e3..299973db5 100644 --- a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/SumFormulaFunction.java +++ b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/SumFormulaFunction.java @@ -1,36 +1,36 @@ -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.AstValue; - -class SumFormulaFunction implements CellFormulaFunction { - - @Override - public Object evaluate(CellValueVisitor visitor, AstArgList args) { - Double sum = 0.0; - for (AstValue value : args.values) { - Object result = value.accept(visitor); - - if (result instanceof SpreadsheetMatrix) { - Object value2 = ((SpreadsheetMatrix) result).sumWithFormulaError(); - if(value2 instanceof String) return value2; //means sumWithFormulaError returned an Error message. - sum += ((Number)value2).doubleValue(); - } else if(result instanceof String && !result.equals("")){ - FormulaError2 error = FormulaError2.forString(result.toString()); - if(error!=null) return error.getString(); - Double v = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(result); - if(v!=null) - sum += v; - } else if(result instanceof Number){ - sum += ((Number)result).doubleValue(); - } else { - sum += SpreadsheetGraphUtils.asNumber(result); - } - } - return sum; - } +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.AstValue; + +class SumFormulaFunction implements CellFormulaFunction { + + @Override + public Object evaluate(CellValueVisitor visitor, AstArgList args) { + Double sum = 0.0; + for (AstValue value : args.values) { + Object result = value.accept(visitor); + + if (result instanceof SpreadsheetMatrix) { + Object value2 = ((SpreadsheetMatrix) result).sumWithFormulaError(); + if(value2 instanceof String) return value2; //means sumWithFormulaError returned an Error message. + sum += ((Number)value2).doubleValue(); + } else if(result instanceof String && !result.equals("")){ + FormulaError2 error = FormulaError2.forString(result.toString()); + if(error!=null) return error.getString(); + Double v = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(result); + if(v!=null) + sum += v; + } else if(result instanceof Number){ + sum += ((Number)result).doubleValue(); + } else { + sum += SpreadsheetGraphUtils.asNumber(result); + } + } + return sum; + } } \ No newline at end of file