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.AstValue;
10 class SumFormulaFunction implements CellFormulaFunction<Object> {
13 public Object evaluate(CellValueVisitor visitor, AstArgList args) {
15 for (AstValue value : args.values) {
16 Object result = value.accept(visitor);
18 if (result instanceof SpreadsheetMatrix) {
19 Object value2 = ((SpreadsheetMatrix) result).sumWithFormulaError();
20 if(value2 instanceof String) return value2; //means sumWithFormulaError returned an Error message.
21 sum += ((Number)value2).doubleValue();
22 } else if(result instanceof String && !result.equals("")){
23 FormulaError2 error = FormulaError2.forString(result.toString());
24 if(error!=null) return error.getString();
25 Double v = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(result);
28 } else if(result instanceof Number){
29 sum += ((Number)result).doubleValue();
31 sum += SpreadsheetGraphUtils.asNumber(result);