ConditionalExpression implements Expression<T> { @Override public String use() { return String.format("if %s then %s else %s endif", condition.use(), thenBranch.use(), elseBranch.use()); } ConditionalExpression(BooleanExpression condition, Expression<T> thenBranch,
      Expression<T> elseBranch); @Override String use(); @Override Expression<T> substitute(String name, Object value);  }
@Test public void testIntegerIfElse() { BooleanExpression condition = new RelationalOperation<>(new IntegerConstant(1), RelationalOperator.LT, new IntegerConstant(2)); IntegerExpression thenBranch = new IntegerConstant(1); IntegerExpression elseBranch = new IntegerConstant(2); ConditionalExpression<Integer> condExpr = new IntegerConditionalExpression(condition, thenBranch, elseBranch); Assert.assertEquals("if 1 < 2 then 1 else 2 endif", condExpr.use()); }
@Test public void testNestedIntegerIfElse() { BooleanExpression condition1 = new RelationalOperation<>(new IntegerConstant(1), RelationalOperator.LT, new IntegerConstant(2)); IntegerExpression then1 = new IntegerConstant(1); BooleanExpression condition2 = new RelationalOperation<>(new IntegerConstant(2), RelationalOperator.LT, new IntegerConstant(1)); IntegerExpression then2 = new IntegerConstant(2); IntegerExpression else2 = new IntegerConstant(3); ConditionalExpression<Integer> condExpr = new IntegerConditionalExpression(condition1, then1, new IntegerConditionalExpression(condition2, then2, else2)); Assert.assertEquals("if 1 < 2 then 1 else if 2 < 1 then 2 else 3 endif endif", condExpr.use()); }