1 package org.simantics.spreadsheet.solver.formula;
3 import java.util.HashMap;
6 import org.simantics.spreadsheet.solver.SpreadsheetBook;
8 public class SpreadsheetEvaluationEnvironment {
10 final private SpreadsheetBook book;
11 private Map<String, CellFormulaFunction<?>> functions = new HashMap<>();
12 public int iterationLimit = 100;
14 public SpreadsheetEvaluationEnvironment(SpreadsheetBook book) {
17 functions.put("MATCH", new MatchFormulaFunction());
18 functions.put("ISERROR",new IsErrorFormulaFunction());
19 functions.put("IFERROR",new IfErrorFormulaFunction());
20 functions.put("IF", new IfFormulaFunction());
21 functions.put("OR", new OrFormulaFunction());
22 functions.put("AND", new AndFormulaFunction());
23 functions.put("ROUND", new RoundFormulaFunction());
24 functions.put("ROUNDUP", new RoundupFormulaFunction());
25 functions.put("SQRT", new SqrtFormulaFunction());
26 functions.put("PI", new PiFormulaFunction());
27 functions.put("COUNTIF", new CountifFormulaFunction());
28 functions.put("SUM", new SumFormulaFunction());
29 functions.put("AVERAGE", new AverageFormulaFunction());
30 functions.put("SUMIF", new SumifFormulaFunction());
31 functions.put("VLOOKUP", new VlookupFormulaFunction());
32 functions.put("HLOOKUP", new HlookupFormulaFunction());
33 functions.put("TODAY", new TodayFormulaFunction());
34 functions.put("LINEST", new LinestFormulaFunction());
35 functions.put("GEOMEAN", new GeomeanFormulaFunction());
38 public CellFormulaFunction<?> getFunction(String name) {
39 return functions.get(name);
42 public SpreadsheetBook getBook() {
46 private static Map<SpreadsheetBook, SpreadsheetEvaluationEnvironment> INSTANCES = new HashMap<>();
48 public static SpreadsheetEvaluationEnvironment getInstance(SpreadsheetBook book) {
49 SpreadsheetEvaluationEnvironment env = INSTANCES.get(book);
51 env = new SpreadsheetEvaluationEnvironment(book);
52 INSTANCES.put(book, env);
57 public static boolean removeInstance(SpreadsheetBook book) {
58 return INSTANCES.remove(book) != null;