X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.spreadsheet.graph%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fgraph%2Fformula%2FGeomeanFormulaFunction.java;fp=bundles%2Forg.simantics.spreadsheet.graph%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fgraph%2Fformula%2FGeomeanFormulaFunction.java;h=0000000000000000000000000000000000000000;hb=c07a3818f0024e932a27eb85cbfd3f2291475a65;hp=88689850182c092bea261137a65df23b591dbc9e;hpb=6c99e980d250fb9201aba93be7dcb1f55564dccd;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/GeomeanFormulaFunction.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/GeomeanFormulaFunction.java deleted file mode 100644 index 886898501..000000000 --- a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/GeomeanFormulaFunction.java +++ /dev/null @@ -1,47 +0,0 @@ -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 { - - @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))); - } - -}