]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/SpreadsheetEvaluationEnvironment.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.spreadsheet.graph / src / org / simantics / spreadsheet / graph / formula / SpreadsheetEvaluationEnvironment.java
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/SpreadsheetEvaluationEnvironment.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/SpreadsheetEvaluationEnvironment.java
new file mode 100644 (file)
index 0000000..bb5a5d7
--- /dev/null
@@ -0,0 +1,60 @@
+package org.simantics.spreadsheet.graph.formula;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import org.simantics.spreadsheet.graph.CellFormulaFunction;\r
+import org.simantics.spreadsheet.graph.SpreadsheetBook;\r
+\r
+public class SpreadsheetEvaluationEnvironment {\r
+\r
+    final private SpreadsheetBook book;\r
+    private Map<String, CellFormulaFunction<?>> functions = new HashMap<>();\r
+    public int iterationLimit = 100;\r
+    public boolean iterationEnabled = false;\r
+    \r
+\r
+    public SpreadsheetEvaluationEnvironment(SpreadsheetBook book) {\r
+        this.book = book;\r
+\r
+        functions.put("MATCH", new MatchFormulaFunction());\r
+        functions.put("ISERROR",new IsErrorFormulaFunction());\r
+        functions.put("IFERROR",new IfErrorFormulaFunction());\r
+        functions.put("IF", new IfFormulaFunction());\r
+        functions.put("OR", new OrFormulaFunction());\r
+        functions.put("AND", new AndFormulaFunction());\r
+        functions.put("ROUND", new RoundFormulaFunction());\r
+        functions.put("ROUNDUP", new RoundupFormulaFunction());\r
+        functions.put("SQRT", new SqrtFormulaFunction());\r
+        functions.put("PI", new PiFormulaFunction());\r
+        functions.put("COUNTIF", new CountifFormulaFunction());\r
+        functions.put("SUM", new SumFormulaFunction());\r
+        functions.put("AVERAGE", new AverageFormulaFunction());\r
+        functions.put("SUMIF", new SumifFormulaFunction());\r
+        functions.put("VLOOKUP", new VlookupFormulaFunction());\r
+        functions.put("HLOOKUP", new HlookupFormulaFunction());\r
+        functions.put("TODAY", new TodayFormulaFunction());\r
+        functions.put("LINEST", new LinestFormulaFunction());\r
+        functions.put("GEOMEAN", new GeomeanFormulaFunction());\r
+    }\r
+\r
+    public CellFormulaFunction<?> getFunction(String name) {\r
+        return functions.get(name);\r
+    }\r
+\r
+    public SpreadsheetBook getBook() {\r
+        return book;\r
+    }\r
+\r
+    public static Map<SpreadsheetBook, SpreadsheetEvaluationEnvironment> INSTANCES = new HashMap<>();\r
+\r
+    public static SpreadsheetEvaluationEnvironment getInstance(SpreadsheetBook book) {\r
+        SpreadsheetEvaluationEnvironment env = INSTANCES.get(book);\r
+        if (env == null) {\r
+            env = new SpreadsheetEvaluationEnvironment(book);\r
+            INSTANCES.put(book, env);\r
+        }\r
+        return env;\r
+    }\r
+\r
+}\r