24 lines
908 B
Java
24 lines
908 B
Java
|
package io.gitlab.jfronny.muscript.compiler.expr.common.conditional;
|
||
|
|
||
|
import io.gitlab.jfronny.muscript.compiler.expr.*;
|
||
|
import io.gitlab.jfronny.muscript.dynamic.*;
|
||
|
|
||
|
public class BoolConditional extends BoolExpr {
|
||
|
public final BoolExpr condition;
|
||
|
public final BoolExpr trueExpr;
|
||
|
public final BoolExpr falseExpr;
|
||
|
|
||
|
public BoolConditional(BoolExpr condition, BoolExpr trueExpr, BoolExpr falseExpr) {
|
||
|
this.condition = condition;
|
||
|
this.trueExpr = trueExpr;
|
||
|
this.falseExpr = falseExpr;
|
||
|
if (trueExpr.getResultType() != falseExpr.getResultType())
|
||
|
throw new IllegalArgumentException("Values used in conditional operator must be of the same type");
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public Boolean get(Dynamic<?> branch, Dynamic<?> dataRoot) {
|
||
|
return condition.get(branch, dataRoot) ? trueExpr.get(branch, dataRoot) : falseExpr.get(branch, dataRoot);
|
||
|
}
|
||
|
}
|