Search in sources :

Example 16 with RangeImpl

use of org.kie.dmn.feel.runtime.impl.RangeImpl in project drools by kiegroup.

the class RangeNode method evaluate.

@Override
public Range evaluate(EvaluationContext ctx) {
    Object s = start.evaluate(ctx);
    Object e = end.evaluate(ctx);
    Type sType = BuiltInType.determineTypeFromInstance(s);
    Type eType = BuiltInType.determineTypeFromInstance(e);
    if (s != null && e != null && sType != eType && !s.getClass().isAssignableFrom(e.getClass())) {
        ctx.notifyEvt(astEvent(Severity.ERROR, Msg.createMessage(Msg.X_TYPE_INCOMPATIBLE_WITH_Y_TYPE, "Start", "End")));
        return null;
    }
    Comparable start = convertToComparable(ctx, s);
    Comparable end = convertToComparable(ctx, e);
    return new RangeImpl(lowerBound == IntervalBoundary.OPEN ? Range.RangeBoundary.OPEN : Range.RangeBoundary.CLOSED, start, end, upperBound == IntervalBoundary.OPEN ? Range.RangeBoundary.OPEN : Range.RangeBoundary.CLOSED);
}
Also used : BuiltInType(org.kie.dmn.feel.lang.types.BuiltInType) Type(org.kie.dmn.feel.lang.Type) RangeImpl(org.kie.dmn.feel.runtime.impl.RangeImpl)

Example 17 with RangeImpl

use of org.kie.dmn.feel.runtime.impl.RangeImpl in project drools by kiegroup.

the class FEELSchemaEnumTest method testBasic.

@Test
public void testBasic() {
    List<Range> list = new ArrayList<>();
    list.add(new RangeImpl(RangeBoundary.CLOSED, 0, null, RangeBoundary.CLOSED));
    list.add(new RangeImpl(RangeBoundary.CLOSED, null, 100, RangeBoundary.CLOSED));
    Range result = FEELSchemaEnum.consolidateRanges(list);
    Assertions.assertThat(result).isNotNull().isEqualTo(new RangeImpl(RangeBoundary.CLOSED, 0, 100, RangeBoundary.CLOSED));
}
Also used : ArrayList(java.util.ArrayList) Range(org.kie.dmn.feel.runtime.Range) RangeImpl(org.kie.dmn.feel.runtime.impl.RangeImpl) Test(org.junit.Test)

Aggregations

RangeImpl (org.kie.dmn.feel.runtime.impl.RangeImpl)17 Range (org.kie.dmn.feel.runtime.Range)13 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 BigDecimal (java.math.BigDecimal)1 Type (org.kie.dmn.feel.lang.Type)1 BuiltInType (org.kie.dmn.feel.lang.types.BuiltInType)1 ASTEventBase (org.kie.dmn.feel.runtime.events.ASTEventBase)1