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