]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/OrFormulaFunction.java
Improved exception message
[simantics/platform.git] / bundles / org.simantics.spreadsheet.graph / src / org / simantics / spreadsheet / graph / formula / OrFormulaFunction.java
1 package org.simantics.spreadsheet.graph.formula;
2
3 import org.simantics.spreadsheet.graph.CellFormulaFunction;
4 import org.simantics.spreadsheet.graph.CellValueVisitor;
5 import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils;
6 import org.simantics.spreadsheet.graph.parser.ast.AstArgList;
7
8 public class OrFormulaFunction implements CellFormulaFunction<Object> {
9
10     @Override
11     public Object evaluate(CellValueVisitor visitor, AstArgList args) {
12         if (args.values.size() == 0) throw new IllegalStateException();
13         
14         for (int i = 0; i < args.values.size(); i++) {
15                 Object obj = null;
16                 try {
17                         obj = args.values.get(i).accept(visitor);
18                 } catch (IllegalStateException e){
19                         return FormulaError2.NAME.getString();
20                 }
21                 FormulaError2 error = FormulaError2.forObject(obj);
22                 if(error!=null) return error.getString();
23                 
24             if (SpreadsheetGraphUtils.asBoolean(obj))
25                 return Boolean.TRUE;
26         }
27         return Boolean.FALSE;
28     }
29
30 }