X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.spreadsheet.graph%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fgraph%2Fformula%2FSpreadsheetEvaluationEnvironment.java;h=08483bccbd6299d502152d5dbed64a9194293165;hb=82ed7c74;hp=bb5a5d71bd38935e65ac7a4d3cfce37029ddb262;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/SpreadsheetEvaluationEnvironment.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/SpreadsheetEvaluationEnvironment.java index bb5a5d71b..08483bccb 100644 --- a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/SpreadsheetEvaluationEnvironment.java +++ b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/SpreadsheetEvaluationEnvironment.java @@ -1,60 +1,61 @@ -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 boolean iterationEnabled = false; - - - 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; - } - - public 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; - } - -} +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; + } +}