package org.simantics.spreadsheet.graph.formula; import java.util.HashMap; import java.util.Map; import org.simantics.spreadsheet.graph.CellFormulaFunction; import org.simantics.spreadsheet.graph.SpreadsheetBook; public class SpreadsheetEvaluationEnvironment { final private SpreadsheetBook book; private Map> functions = new HashMap<>(); public int iterationLimit = 100; public SpreadsheetEvaluationEnvironment(SpreadsheetBook book) { this.book = book; functions.put("MATCH", new MatchFormulaFunction()); functions.put("ISERROR",new IsErrorFormulaFunction()); functions.put("IFERROR",new IfErrorFormulaFunction()); functions.put("IF", new IfFormulaFunction()); functions.put("OR", new OrFormulaFunction()); functions.put("AND", new AndFormulaFunction()); functions.put("ROUND", new RoundFormulaFunction()); functions.put("ROUNDUP", new RoundupFormulaFunction()); functions.put("SQRT", new SqrtFormulaFunction()); functions.put("PI", new PiFormulaFunction()); functions.put("COUNTIF", new CountifFormulaFunction()); functions.put("SUM", new SumFormulaFunction()); functions.put("AVERAGE", new AverageFormulaFunction()); functions.put("SUMIF", new SumifFormulaFunction()); functions.put("VLOOKUP", new VlookupFormulaFunction()); functions.put("HLOOKUP", new HlookupFormulaFunction()); functions.put("TODAY", new TodayFormulaFunction()); functions.put("LINEST", new LinestFormulaFunction()); functions.put("GEOMEAN", new GeomeanFormulaFunction()); } public CellFormulaFunction getFunction(String name) { return functions.get(name); } public SpreadsheetBook getBook() { return book; } private static Map INSTANCES = new HashMap<>(); public static SpreadsheetEvaluationEnvironment getInstance(SpreadsheetBook book) { SpreadsheetEvaluationEnvironment env = INSTANCES.get(book); if (env == null) { env = new SpreadsheetEvaluationEnvironment(book); INSTANCES.put(book, env); } return env; } public static boolean removeInstance(SpreadsheetBook book) { return INSTANCES.remove(book) != null; } }