X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.spreadsheet.graph%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fgraph%2Fformula%2FIfFormulaFunction.java;fp=bundles%2Forg.simantics.spreadsheet.graph%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fgraph%2Fformula%2FIfFormulaFunction.java;h=2d2ef8c5b74e9ce41a5398b7629e98320dae6cc3;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=c770f34bfff20d397c38642252ac8e543d65132e;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/IfFormulaFunction.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/IfFormulaFunction.java index c770f34bf..2d2ef8c5b 100644 --- a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/IfFormulaFunction.java +++ b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/IfFormulaFunction.java @@ -1,42 +1,42 @@ -package org.simantics.spreadsheet.graph.formula; - -import org.simantics.spreadsheet.graph.CellFormulaFunction; -import org.simantics.spreadsheet.graph.CellValueVisitor; -import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils; -import org.simantics.spreadsheet.graph.parser.ast.AstArgList; -import org.simantics.spreadsheet.graph.parser.ast.AstNothing; -import org.simantics.spreadsheet.graph.parser.ast.AstValue; - -public class IfFormulaFunction implements CellFormulaFunction { - - @Override - public Object evaluate(CellValueVisitor visitor, AstArgList args) { - if (args.values.size() != 3) throw new IllegalStateException(); - - Object condition = args.values.get(0).accept(visitor); - AstValue ifTrueResult = args.values.get(1); - AstValue ifFalseResult = args.values.get(2); - - FormulaError2 error = FormulaError2.forObject(condition); - if(error!=null) return error.getString(); - - if (SpreadsheetGraphUtils.asBoolean(condition)) { - if(ifTrueResult==null || ifTrueResult instanceof AstNothing) - return 0; - try { - return ifTrueResult.accept(visitor); - } catch (IllegalStateException e){ - return FormulaError2.NAME.getString(); - } - } - else { - if(ifFalseResult==null || ifFalseResult instanceof AstNothing) - return 0; - try { - return ifFalseResult.accept(visitor); - } catch (IllegalStateException e){ - return FormulaError2.NAME.getString(); - } - } - } +package org.simantics.spreadsheet.graph.formula; + +import org.simantics.spreadsheet.graph.CellFormulaFunction; +import org.simantics.spreadsheet.graph.CellValueVisitor; +import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils; +import org.simantics.spreadsheet.graph.parser.ast.AstArgList; +import org.simantics.spreadsheet.graph.parser.ast.AstNothing; +import org.simantics.spreadsheet.graph.parser.ast.AstValue; + +public class IfFormulaFunction implements CellFormulaFunction { + + @Override + public Object evaluate(CellValueVisitor visitor, AstArgList args) { + if (args.values.size() != 3) throw new IllegalStateException(); + + Object condition = args.values.get(0).accept(visitor); + AstValue ifTrueResult = args.values.get(1); + AstValue ifFalseResult = args.values.get(2); + + FormulaError2 error = FormulaError2.forObject(condition); + if(error!=null) return error.getString(); + + if (SpreadsheetGraphUtils.asBoolean(condition)) { + if(ifTrueResult==null || ifTrueResult instanceof AstNothing) + return 0; + try { + return ifTrueResult.accept(visitor); + } catch (IllegalStateException e){ + return FormulaError2.NAME.getString(); + } + } + else { + if(ifFalseResult==null || ifFalseResult instanceof AstNothing) + return 0; + try { + return ifFalseResult.accept(visitor); + } catch (IllegalStateException e){ + return FormulaError2.NAME.getString(); + } + } + } } \ No newline at end of file