Search in sources :

Example 1 with FixValue

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;
}
Also used : FixValue(io.fixprotocol.orchestra.model.FixValue) ModelException(io.fixprotocol.orchestra.model.ModelException) CodeType(io.fixprotocol._2020.orchestra.repository.CodeType) FixType(io.fixprotocol.orchestra.model.FixType)

Example 2 with FixValue

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);
}
Also used : FixValue(io.fixprotocol.orchestra.model.FixValue) ExprContext(io.fixprotocol.orchestra.dsl.antlr.ScoreParser.ExprContext)

Example 3 with FixValue

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());
    }
}
Also used : FixValue(io.fixprotocol.orchestra.model.FixValue) BigDecimal(java.math.BigDecimal) AnyExpressionContext(io.fixprotocol.orchestra.dsl.antlr.ScoreParser.AnyExpressionContext) Test(org.junit.jupiter.api.Test)

Example 4 with FixValue

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());
    }
}
Also used : FixValue(io.fixprotocol.orchestra.model.FixValue) AnyExpressionContext(io.fixprotocol.orchestra.dsl.antlr.ScoreParser.AnyExpressionContext) Test(org.junit.jupiter.api.Test)

Example 5 with FixValue

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());
}
Also used : FixValue(io.fixprotocol.orchestra.model.FixValue) AnyExpressionContext(io.fixprotocol.orchestra.dsl.antlr.ScoreParser.AnyExpressionContext) Test(org.junit.jupiter.api.Test)

Aggregations

FixValue (io.fixprotocol.orchestra.model.FixValue)26 AnyExpressionContext (io.fixprotocol.orchestra.dsl.antlr.ScoreParser.AnyExpressionContext)24 Test (org.junit.jupiter.api.Test)24 BigDecimal (java.math.BigDecimal)4 PathStep (io.fixprotocol.orchestra.model.PathStep)2 CodeType (io.fixprotocol._2020.orchestra.repository.CodeType)1 ExprContext (io.fixprotocol.orchestra.dsl.antlr.ScoreParser.ExprContext)1 FixType (io.fixprotocol.orchestra.model.FixType)1 ModelException (io.fixprotocol.orchestra.model.ModelException)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1 LocalTime (java.time.LocalTime)1