]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/SpreadsheetEvaluationEnvironment.java
Sync git svn branch with SVN repository r33153.
[simantics/platform.git] / bundles / org.simantics.spreadsheet.graph / src / org / simantics / spreadsheet / graph / formula / SpreadsheetEvaluationEnvironment.java
1 package org.simantics.spreadsheet.graph.formula;\r
2 \r
3 import java.util.HashMap;\r
4 import java.util.Map;\r
5 \r
6 import org.simantics.spreadsheet.graph.CellFormulaFunction;\r
7 import org.simantics.spreadsheet.graph.SpreadsheetBook;\r
8 \r
9 public class SpreadsheetEvaluationEnvironment {\r
10 \r
11     final private SpreadsheetBook book;\r
12     private Map<String, CellFormulaFunction<?>> functions = new HashMap<>();\r
13     public int iterationLimit = 100;\r
14 \r
15     public SpreadsheetEvaluationEnvironment(SpreadsheetBook book) {\r
16         this.book = book;\r
17 \r
18         functions.put("MATCH", new MatchFormulaFunction());\r
19         functions.put("ISERROR",new IsErrorFormulaFunction());\r
20         functions.put("IFERROR",new IfErrorFormulaFunction());\r
21         functions.put("IF", new IfFormulaFunction());\r
22         functions.put("OR", new OrFormulaFunction());\r
23         functions.put("AND", new AndFormulaFunction());\r
24         functions.put("ROUND", new RoundFormulaFunction());\r
25         functions.put("ROUNDUP", new RoundupFormulaFunction());\r
26         functions.put("SQRT", new SqrtFormulaFunction());\r
27         functions.put("PI", new PiFormulaFunction());\r
28         functions.put("COUNTIF", new CountifFormulaFunction());\r
29         functions.put("SUM", new SumFormulaFunction());\r
30         functions.put("AVERAGE", new AverageFormulaFunction());\r
31         functions.put("SUMIF", new SumifFormulaFunction());\r
32         functions.put("VLOOKUP", new VlookupFormulaFunction());\r
33         functions.put("HLOOKUP", new HlookupFormulaFunction());\r
34         functions.put("TODAY", new TodayFormulaFunction());\r
35         functions.put("LINEST", new LinestFormulaFunction());\r
36         functions.put("GEOMEAN", new GeomeanFormulaFunction());\r
37     }\r
38 \r
39     public CellFormulaFunction<?> getFunction(String name) {\r
40         return functions.get(name);\r
41     }\r
42 \r
43     public SpreadsheetBook getBook() {\r
44         return book;\r
45     }\r
46 \r
47     public static Map<SpreadsheetBook, SpreadsheetEvaluationEnvironment> INSTANCES = new HashMap<>();\r
48 \r
49     public static SpreadsheetEvaluationEnvironment getInstance(SpreadsheetBook book) {\r
50         SpreadsheetEvaluationEnvironment env = INSTANCES.get(book);\r
51         if (env == null) {\r
52             env = new SpreadsheetEvaluationEnvironment(book);\r
53             INSTANCES.put(book, env);\r
54         }\r
55         return env;\r
56     }\r
57 \r
58 }\r