-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
-public class GeomeanFormulaFunction implements CellFormulaFunction<Object> {\r
-\r
- @Override\r
- public Object evaluate(CellValueVisitor visitor, AstArgList args) {\r
- if (args.values.size() == 0)\r
- throw new IllegalStateException();\r
- double result = 1.0;\r
- double count = 0.0;\r
- for (AstValue value : args.values){\r
- Object r = value.accept(visitor);\r
- if (r instanceof SpreadsheetMatrix) {\r
- Object v = ((SpreadsheetMatrix) r).productWithFormulaError();\r
- if(v instanceof String) return v;\r
- double dval = ((Number)v).doubleValue();\r
- if(dval!=0.0){\r
- result = result*dval;\r
- count += ((SpreadsheetMatrix) r).countOfActualDoubleValues();\r
- }\r
- } else {\r
- FormulaError2 error = FormulaError2.forObject(r);\r
- if(error!=null) return error.getString();\r
- \r
- Number vNum = SpreadsheetGraphUtils.asValidNumber(r);\r
- Double v = null;\r
- if(vNum!=null) v = vNum.doubleValue();\r
- \r
- if(v!=null){\r
- if(v<=0) return FormulaError2.NUM.getString();\r
- result = result*v;\r
- count++;\r
- }\r
- }\r
- }\r
- if(result==0.0 || count==0.0) return FormulaError2.NUM.getString();\r
- return Double.valueOf(Math.pow(result, (1.0/count)));\r
- }\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.AstValue;
+
+public class GeomeanFormulaFunction implements CellFormulaFunction<Object> {
+
+ @Override
+ public Object evaluate(CellValueVisitor visitor, AstArgList args) {
+ if (args.values.size() == 0)
+ throw new IllegalStateException();
+ double result = 1.0;
+ double count = 0.0;
+ for (AstValue value : args.values){
+ Object r = value.accept(visitor);
+ if (r instanceof SpreadsheetMatrix) {
+ Object v = ((SpreadsheetMatrix) r).productWithFormulaError();
+ if(v instanceof String) return v;
+ double dval = ((Number)v).doubleValue();
+ if(dval!=0.0){
+ result = result*dval;
+ count += ((SpreadsheetMatrix) r).countOfActualDoubleValues();
+ }
+ } else {
+ FormulaError2 error = FormulaError2.forObject(r);
+ if(error!=null) return error.getString();
+
+ Number vNum = SpreadsheetGraphUtils.asValidNumber(r);
+ Double v = null;
+ if(vNum!=null) v = vNum.doubleValue();
+
+ if(v!=null){
+ if(v<=0) return FormulaError2.NUM.getString();
+ result = result*v;
+ count++;
+ }
+ }
+ }
+ if(result==0.0 || count==0.0) return FormulaError2.NUM.getString();
+ return Double.valueOf(Math.pow(result, (1.0/count)));
+ }
+
+}