]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/interpreted/IIf.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / internal / interpreted / IIf.java
1 package org.simantics.scl.compiler.internal.interpreted;
2
3
4 public class IIf implements IExpression {
5     private final IExpression condition;
6     private final IExpression thenBranch;
7     private final IExpression elseBranch;
8     
9     public IIf(IExpression condition, IExpression thenBranch,
10             IExpression elseBranch) {
11         this.condition = condition;
12         this.thenBranch = thenBranch;
13         this.elseBranch = elseBranch;
14     }
15
16     @Override
17     public Object execute(Object[] variableBindings) {
18         if((Boolean)condition.execute(variableBindings))
19             return thenBranch.execute(variableBindings);
20         else
21             return elseBranch.execute(variableBindings);
22     }
23     
24     @Override
25     public String toString() {
26         StringBuilder b = new StringBuilder();
27         b.append("(if ");
28         b.append(condition);
29         b.append(" then ");
30         b.append(thenBranch);
31         b.append(" else ");
32         b.append(elseBranch);
33         b.append(')');
34         return b.toString();
35     }
36 }