]> gerrit.simantics Code Review - simantics/platform.git/blob
4152188cd7d2d5e2f7534680b33847a2d7634334
[simantics/platform.git] /
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 AndFormulaFunction implements CellFormulaFunction<Object> {
9
10     @Override
11     public Object evaluate(CellValueVisitor visitor, AstArgList args) {
12         if (args.values.size() == 0)
13             throw new IllegalStateException();
14         Boolean finalResult = Boolean.TRUE;
15         for (int i = 0; i < args.values.size(); i++) {
16                 Object res = (args.values.get(i).accept(visitor));
17                 FormulaError2 err = FormulaError2.forObject(res);
18                 if(err!=null) return err.getString();
19                 
20             if ((res instanceof Boolean && !((Boolean)res)) || !SpreadsheetGraphUtils.asBoolean(res))
21                 finalResult = Boolean.FALSE;
22         }
23         return finalResult;
24     }
25 }