-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.AstValue;\r
-\r
-class SumFormulaFunction implements CellFormulaFunction<Object> {\r
-\r
- @Override\r
- public Object evaluate(CellValueVisitor visitor, AstArgList args) {\r
- Double sum = 0.0;\r
- for (AstValue value : args.values) {\r
- Object result = value.accept(visitor);\r
- \r
- if (result instanceof SpreadsheetMatrix) {\r
- Object value2 = ((SpreadsheetMatrix) result).sumWithFormulaError();\r
- if(value2 instanceof String) return value2; //means sumWithFormulaError returned an Error message.\r
- sum += ((Number)value2).doubleValue();\r
- } else if(result instanceof String && !result.equals("")){\r
- FormulaError2 error = FormulaError2.forString(result.toString());\r
- if(error!=null) return error.getString();\r
- Double v = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(result);\r
- if(v!=null)\r
- sum += v;\r
- } else if(result instanceof Number){\r
- sum += ((Number)result).doubleValue();\r
- } else {\r
- sum += SpreadsheetGraphUtils.asNumber(result);\r
- }\r
- }\r
- return sum;\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.AstValue;
+
+class SumFormulaFunction implements CellFormulaFunction<Object> {
+
+ @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