]> gerrit.simantics Code Review - simantics/platform.git/blob
bb5a5d71bd38935e65ac7a4d3cfce37029ddb262
[simantics/platform.git] /
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     public boolean iterationEnabled = false;\r
15     \r
16 \r
17     public SpreadsheetEvaluationEnvironment(SpreadsheetBook book) {\r
18         this.book = book;\r
19 \r
20         functions.put("MATCH", new MatchFormulaFunction());\r
21         functions.put("ISERROR",new IsErrorFormulaFunction());\r
22         functions.put("IFERROR",new IfErrorFormulaFunction());\r
23         functions.put("IF", new IfFormulaFunction());\r
24         functions.put("OR", new OrFormulaFunction());\r
25         functions.put("AND", new AndFormulaFunction());\r
26         functions.put("ROUND", new RoundFormulaFunction());\r
27         functions.put("ROUNDUP", new RoundupFormulaFunction());\r
28         functions.put("SQRT", new SqrtFormulaFunction());\r
29         functions.put("PI", new PiFormulaFunction());\r
30         functions.put("COUNTIF", new CountifFormulaFunction());\r
31         functions.put("SUM", new SumFormulaFunction());\r
32         functions.put("AVERAGE", new AverageFormulaFunction());\r
33         functions.put("SUMIF", new SumifFormulaFunction());\r
34         functions.put("VLOOKUP", new VlookupFormulaFunction());\r
35         functions.put("HLOOKUP", new HlookupFormulaFunction());\r
36         functions.put("TODAY", new TodayFormulaFunction());\r
37         functions.put("LINEST", new LinestFormulaFunction());\r
38         functions.put("GEOMEAN", new GeomeanFormulaFunction());\r
39     }\r
40 \r
41     public CellFormulaFunction<?> getFunction(String name) {\r
42         return functions.get(name);\r
43     }\r
44 \r
45     public SpreadsheetBook getBook() {\r
46         return book;\r
47     }\r
48 \r
49     public static Map<SpreadsheetBook, SpreadsheetEvaluationEnvironment> INSTANCES = new HashMap<>();\r
50 \r
51     public static SpreadsheetEvaluationEnvironment getInstance(SpreadsheetBook book) {\r
52         SpreadsheetEvaluationEnvironment env = INSTANCES.get(book);\r
53         if (env == null) {\r
54             env = new SpreadsheetEvaluationEnvironment(book);\r
55             INSTANCES.put(book, env);\r
56         }\r
57         return env;\r
58     }\r
59 \r
60 }\r