ExpressionBuilder { public static SelectionExpr SELECT(Expression condition, SelectionExpr.Case... cases) { return new SelectionExpr(condition, cases); } private  ExpressionBuilder(); static ConstantExpr CONSTANT(Object value); static ConstantExpr INV(Expression value); static SequenceExpr SEQ(Type elementType, Expression elementCount); static SequenceExpr SEQ(Expression elementType, int elementCount); static SequenceExpr SEQ(Type elementType, int elementCount); static SequenceExpr SEQ(Expression elementType, Expression elementCount); static CompoundExpr COMP(String name, CompoundExpr.Member... members); static CompoundExpr.Member MEMBER(String name, Type type); static CompoundExpr.Member MEMBER(String name, Expression expression); static ChoiceExpr IF(Expression condition, Type type1, Type type2); static ChoiceExpr IF(Expression condition, Expression expression1, Expression expression2); static SelectionExpr SELECT(Expression condition, SelectionExpr.Case... cases); static SelectionExpr.Case CASE(Object value, Type type); static SelectionExpr.Case CASE(Object value, Expression expression); static SelectionExpr.Default DEFAULT(Type type); static SelectionExpr.Default DEFAULT(Expression expression); static IntReferenceExpr IREF(String name); final static SimpleType BYTE; final static SimpleType UBYTE; final static SimpleType SHORT; final static SimpleType USHORT; final static SimpleType INT; final static SimpleType UINT; final static SimpleType LONG; final static SimpleType ULONG; final static SimpleType FLOAT; final static SimpleType DOUBLE; }
@Test public void testSelect() throws IOException { final VariableExpr condition = new VariableExpr(); final SelectionExpr selection = SELECT(condition, CASE("A", FLOAT), CASE("B", DOUBLE), DEFAULT(INT)); condition.value = "A"; assertEquals(false, selection.isConstant()); Object result = selection.evaluate(null); assertTrue(result instanceof SimpleType); assertEquals(SimpleType.FLOAT, result); condition.value = "B"; assertEquals(false, selection.isConstant()); result = selection.evaluate(null); assertTrue(result instanceof SimpleType); assertEquals(SimpleType.DOUBLE, result); condition.value = "X"; assertEquals(false, selection.isConstant()); result = selection.evaluate(null); assertTrue(result instanceof SimpleType); assertEquals(SimpleType.INT, result); }