use of io.fixprotocol.orchestra.model.FixValue in project fix-orchestra by FIXTradingCommunity.
the class CodeSetScope method resolve.
/*
* (non-Javadoc)
*
* @see
* io.fixprotocol.orchestra.dsl.antlr.Scope#resolve(io.fixprotocol.orchestra.dsl.antlr.PathStep)
*/
@SuppressWarnings("unchecked")
@Override
public FixValue<?> resolve(PathStep pathStep) {
final String dataTypeString = codeSet.getType();
final FixType dataType = FixType.forName(dataTypeString);
final String name = pathStep.getName();
final List<CodeType> codes = codeSet.getCode();
for (final CodeType code : codes) {
if (code.getName().equals(name)) {
@SuppressWarnings("rawtypes") FixValue fixValue;
try {
fixValue = FixValueFactory.create(name, dataType, dataType.getValueClass());
fixValue.setValue(dataType.getValueClass().cast(dataType.fromString(code.getValue())));
return fixValue;
} catch (final ModelException e) {
return null;
}
}
}
return null;
}
use of io.fixprotocol.orchestra.model.FixValue in project fix-orchestra by FIXTradingCommunity.
the class ScoreVisitorImpl method visitContains.
/*
* (non-Javadoc)
*
* @see
* io.fixprotocol.orchestra.dsl.antlr.ScoreVisitor#visitContains(io.fixprotocol.orchestra.dsl.
* antlr.ScoreParser.ContainsContext)
*/
@Override
public FixValue<?> visitContains(ContainsContext ctx) {
final FixValue<?> operand0 = visit(ctx.val);
for (final ExprContext memberExpr : ctx.member) {
final FixValue<?> member = visit(memberExpr);
final FixValue<Boolean> result = fixValueOperations.eq.apply(operand0, member);
if (result.getValue()) {
return result;
}
}
return new FixValue<Boolean>(FixType.BooleanType, Boolean.FALSE);
}
use of io.fixprotocol.orchestra.model.FixValue in project fix-orchestra by FIXTradingCommunity.
the class ScoreVisitorImplTest method testVisitMulDiv.
/**
* Test method for
* {@link io.fixprotocol.orchestra.dsl.antlr.ScoreVisitorImpl#visitMulDiv(io.fixprotocol.orchestra.dsl.antlr.ScoreParser.MulDivContext)}.
*
* @throws IOException
*/
@Test
public void testVisitMulDiv() throws IOException {
TestData[] data = new TestData[] { new TestData("33 * 4", Integer.valueOf(132)), new TestData("44 / 3", Integer.valueOf(14)), new TestData("44 % 3", Integer.valueOf(2)), new TestData("7.12 * 2.3", new BigDecimal("16.376")), new TestData("65.55 / 2.3", new BigDecimal("28.5")), new TestData("44.0 / 4", new BigDecimal("11.0")) };
for (int i = 0; i < data.length; i++) {
ScoreParser parser = parse(data[i].getExpression());
AnyExpressionContext ctx = parser.anyExpression();
Object expression = visitor.visitAnyExpression(ctx);
FixValue<?> fixValue = (FixValue<?>) expression;
assertEquals(data[i].getExpected(), fixValue.getValue());
}
}
use of io.fixprotocol.orchestra.model.FixValue in project fix-orchestra by FIXTradingCommunity.
the class ScoreVisitorImplTest method testVisitContains.
/**
* Test method for
* {@link io.fixprotocol.orchestra.dsl.antlr.ScoreVisitorImpl#visitContains(io.fixprotocol.orchestra.dsl.antlr.ScoreParser.ContainsContext)}.
*
* @throws IOException
*/
@Test
public void testVisitContains() throws IOException {
TestData[] data = new TestData[] { new TestData("33 in {4, 7, 9}", Boolean.FALSE), new TestData("33 in {4, 7, 9, 33}", Boolean.TRUE), new TestData("30 + 3 in {4, 7, 9, 33}", Boolean.TRUE) };
for (int i = 0; i < data.length; i++) {
ScoreParser parser = parse(data[i].getExpression());
AnyExpressionContext ctx = parser.anyExpression();
Object expression = visitor.visitAnyExpression(ctx);
FixValue<?> fixValue = (FixValue<?>) expression;
assertEquals(data[i].getExpected(), fixValue.getValue());
}
}
use of io.fixprotocol.orchestra.model.FixValue in project fix-orchestra by FIXTradingCommunity.
the class ScoreVisitorImplTest method testVisitInteger.
/**
* Test method for
* {@link io.fixprotocol.orchestra.dsl.antlr.ScoreVisitorImpl#visitInteger(io.fixprotocol.orchestra.dsl.antlr.ScoreParser.IntegerContext)}.
*
* @throws IOException
*/
@Test
public void testVisitInteger() throws IOException {
final String value = "456";
ScoreParser parser = parse(value);
AnyExpressionContext ctx = parser.anyExpression();
Object expression = visitor.visitAnyExpression(ctx);
assertTrue(expression instanceof FixValue<?>);
FixValue<?> fixValue = (FixValue<?>) expression;
assertEquals(FixType.intType, fixValue.getType());
assertEquals(Integer.valueOf(value), fixValue.getValue());
}
Aggregations