--- /dev/null
+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