Search in sources :

Example 1 with RangeImpl

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

the class FEELSchemaEnum method consolidateRanges.

public static Range consolidateRanges(List<Range> ranges) {
    boolean consistent = true;
    Range result = new RangeImpl();
    for (Range r : ranges) {
        if (r.getLowEndPoint() != null) {
            if (result.getLowEndPoint() == null) {
                result = new RangeImpl(r.getLowBoundary(), r.getLowEndPoint(), result.getHighEndPoint(), result.getHighBoundary());
            } else {
                consistent = false;
            }
        }
        if (r.getHighEndPoint() != null) {
            if (result.getHighEndPoint() == null) {
                result = new RangeImpl(result.getLowBoundary(), result.getLowEndPoint(), r.getHighEndPoint(), r.getHighBoundary());
            } else {
                consistent = false;
            }
        }
    }
    return consistent ? result : null;
}
Also used : Range(org.kie.dmn.feel.runtime.Range) RangeImpl(org.kie.dmn.feel.runtime.impl.RangeImpl)

Example 2 with RangeImpl

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

the class FEELSchemaEnumTest method testInvalidRepeatedLB.

@Test
public void testInvalidRepeatedLB() {
    List<Range> list = new ArrayList<>();
    list.add(new RangeImpl(RangeBoundary.CLOSED, 0, null, RangeBoundary.CLOSED));
    list.add(new RangeImpl(RangeBoundary.CLOSED, 0, 100, RangeBoundary.CLOSED));
    Range result = FEELSchemaEnum.consolidateRanges(list);
    Assertions.assertThat(result).isNull();
}
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)

Example 3 with RangeImpl

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

the class FEELSchemaEnumTest method testInvalidRepeatedUB.

@Test
public void testInvalidRepeatedUB() {
    List<Range> list = new ArrayList<>();
    list.add(new RangeImpl(RangeBoundary.CLOSED, null, 50, RangeBoundary.CLOSED));
    list.add(new RangeImpl(RangeBoundary.CLOSED, null, 100, RangeBoundary.CLOSED));
    Range result = FEELSchemaEnum.consolidateRanges(list);
    Assertions.assertThat(result).isNull();
}
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)

Example 4 with RangeImpl

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

the class CompiledFEELSemanticMappings method range.

/**
 * Represents a [n..m] construct
 */
public static RangeImpl range(EvaluationContext ctx, Range.RangeBoundary lowBoundary, Object lowEndPoint, Object highEndPoint, Range.RangeBoundary highBoundary) {
    Comparable left = asComparable(lowEndPoint);
    Comparable right = asComparable(highEndPoint);
    if (left != null && right != null && !compatible(left, right)) {
        ctx.notifyEvt(() -> new ASTEventBase(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.INCOMPATIBLE_TYPE_FOR_RANGE, left.getClass().getSimpleName()), null));
        return null;
    }
    return new RangeImpl(lowBoundary, left, right, highBoundary);
}
Also used : ASTEventBase(org.kie.dmn.feel.runtime.events.ASTEventBase) RangeImpl(org.kie.dmn.feel.runtime.impl.RangeImpl)

Example 5 with RangeImpl

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

the class FEELListsTest method data.

@Parameterized.Parameters(name = "{3}: {0} ({1}) = {2}")
public static Collection<Object[]> data() {
    final Object[][] cases = new Object[][] { { "[ 5, 10+2, \"foo\"+\"bar\", true ]", Arrays.asList(BigDecimal.valueOf(5), BigDecimal.valueOf(12), "foobar", Boolean.TRUE), null }, { "[ null ]", Arrays.asList(new Object[] { null }), null }, { "[ null, null ]", Arrays.asList(null, null), null }, { "[ null, 47, null ]", Arrays.asList(null, BigDecimal.valueOf(47), null), null }, // Filtering by index
    { "[\"a\", \"b\", \"c\"][1]", "a", null }, { "[\"a\", \"b\", \"c\"][2]", "b", null }, { "[\"a\", \"b\", \"c\"][3]", "c", null }, { "[\"a\", \"b\", \"c\"][-1]", "c", null }, { "[\"a\", \"b\", \"c\"][-2]", "b", null }, { "[\"a\", \"b\", \"c\"][-3]", "a", null }, { "[\"a\", \"b\", \"c\"][4]", null, FEELEvent.Severity.WARN }, { "[\"a\", \"b\", \"c\"][984]", null, FEELEvent.Severity.WARN }, { "[\"a\", \"b\", \"c\"][-4]", null, FEELEvent.Severity.WARN }, { "[\"a\", \"b\", \"c\"][-984]", null, FEELEvent.Severity.WARN }, { "\"a\"[1]", "a", null }, { "\"a\"[2]", null, FEELEvent.Severity.WARN }, { "{L :3, r: L[1]}.r", BigDecimal.valueOf(3), null }, { "{L :3, r: L[2]}.r", null, FEELEvent.Severity.WARN }, { "\"a\"[-1]", "a", null }, { "\"a\"[-2]", null, FEELEvent.Severity.WARN }, { "{ a list : [10, 20, 30, 40], second : a list[2] }.second", BigDecimal.valueOf(20), null }, // Filtering by boolean expression
    { "[1, 2, 3, 4][item = 4]", Collections.singletonList(BigDecimal.valueOf(4)), null }, { "[1, 2, 3, 4][item > 2]", Arrays.asList(BigDecimal.valueOf(3), BigDecimal.valueOf(4)), null }, { "[1, 2, 3, 4][item > 5]", Collections.emptyList(), null }, { "[ {x:1, y:2}, {x:2, y:3} ][x = 1]", Collections.singletonList(new HashMap<String, Object>() {

        {
            put("x", BigDecimal.valueOf(1));
            put("y", BigDecimal.valueOf(2));
        }
    }), null }, { "[ {x:1, y:2}, {x:2, y:3} ][x > 1]", Collections.singletonList(new HashMap<String, Object>() {

        {
            put("x", BigDecimal.valueOf(2));
            put("y", BigDecimal.valueOf(3));
        }
    }), null }, { "[ {x:1, y:2}, {x:2, y:3} ][x = 0]", Collections.emptyList(), null }, { "{x:false, l:[ {x:1, y:2}, {x:2, y:3} ],r:l[x] }.r", Collections.emptyList(), null }, // DROOLS-1679
    { "[\"a\", \"b\", \"c\"][a]", Collections.emptyList(), null }, { "{ a list : [ { a : false, b : 2 }, { a : true, b : 3 } ], r : a list[a] }.r", Collections.singletonList(new HashMap<String, Object>() {

        {
            put("a", true);
            put("b", BigDecimal.valueOf(3));
        }
    }), null }, { "{ a list : [ { a : false, b : 2 }, { a : null, b : 3 }, { b : 4 } ], r : a list[a] }.r", Collections.emptyList(), null }, { "{ a list : [ \"a\", \"b\", \"c\" ], x : 2, a : a list[x]}.a", "b", null }, { "{ a list : [ { x : false, y : 2 }, { x : true, y : 3 } ], x : \"asd\", a : a list[x] }.a", Collections.singletonList(new HashMap<String, Object>() {

        {
            put("x", true);
            put("y", BigDecimal.valueOf(3));
        }
    }), null }, { "{ a list : [ { x : false, y : 2 }, { x : true, y : 3 } ], x : false, a : a list[x] }.a", Collections.singletonList(new HashMap<String, Object>() {

        {
            put("x", true);
            put("y", BigDecimal.valueOf(3));
        }
    }), null }, { "{ a list : [ { x : false, y : 2 }, { x : true, y : 3 } ], x : null, a : a list[x] }.a", Collections.singletonList(new HashMap<String, Object>() {

        {
            put("x", true);
            put("y", BigDecimal.valueOf(3));
        }
    }), null }, { "{ people : [ { firstName : \"bob\" }, { firstName : \"max\" } ], result : people[ lastName = null ] }.result", Arrays.asList(new HashMap<String, Object>() {

        {
            put("firstName", "bob");
        }
    }, new HashMap<String, Object>() {

        {
            put("firstName", "max");
        }
    }), null }, // Selection
    { "[ {x:1, y:2}, {x:2, y:3} ].y", Arrays.asList(BigDecimal.valueOf(2), BigDecimal.valueOf(3)), null }, { "[ {x:1, y:2}, {x:2} ].y", Collections.singletonList(BigDecimal.valueOf(2)), null }, { "[ {x:1, y:2}, {x:2, y:3} ].z", Collections.emptyList(), null }, // lists of intervals
    { "[ ( 10 .. 20 ) ]", Collections.singletonList(new RangeImpl(Range.RangeBoundary.OPEN, BigDecimal.valueOf(10), BigDecimal.valueOf(20), Range.RangeBoundary.OPEN)), null }, { "[ ] 10 .. 20 [ ]", Collections.singletonList(new RangeImpl(Range.RangeBoundary.OPEN, BigDecimal.valueOf(10), BigDecimal.valueOf(20), Range.RangeBoundary.OPEN)), null }, { "[ ( duration(\"P1D\") .. duration(\"P10D\") ) ]", Collections.singletonList(new RangeImpl(Range.RangeBoundary.OPEN, Duration.parse("P1D"), Duration.parse("P10D"), Range.RangeBoundary.OPEN)), null }, { "[ ( duration(\"P1D\") .. duration(\"P10D\") [ ]", Collections.singletonList(new RangeImpl(Range.RangeBoundary.OPEN, Duration.parse("P1D"), Duration.parse("P10D"), Range.RangeBoundary.OPEN)), null }, { "[ ( duration(\"P1D\") .. duration(\"P10D\") ] ]", Collections.singletonList(new RangeImpl(Range.RangeBoundary.OPEN, Duration.parse("P1D"), Duration.parse("P10D"), Range.RangeBoundary.CLOSED)), null }, { "[ ] duration(\"P1D\") .. duration(\"P10D\") ) ]", Collections.singletonList(new RangeImpl(Range.RangeBoundary.OPEN, Duration.parse("P1D"), Duration.parse("P10D"), Range.RangeBoundary.OPEN)), null }, { "[ ] duration(\"P1D\") .. duration(\"P10D\") [ ]", Collections.singletonList(new RangeImpl(Range.RangeBoundary.OPEN, Duration.parse("P1D"), Duration.parse("P10D"), Range.RangeBoundary.OPEN)), null }, { "[ ] duration(\"P1D\") .. duration(\"P10D\") ] ]", Collections.singletonList(new RangeImpl(Range.RangeBoundary.OPEN, Duration.parse("P1D"), Duration.parse("P10D"), Range.RangeBoundary.CLOSED)), null }, { "[ [ duration(\"P1D\") .. duration(\"P10D\") ) ]", Collections.singletonList(new RangeImpl(Range.RangeBoundary.CLOSED, Duration.parse("P1D"), Duration.parse("P10D"), Range.RangeBoundary.OPEN)), null }, { "[ [ duration(\"P1D\") .. duration(\"P10D\") [ ]", Collections.singletonList(new RangeImpl(Range.RangeBoundary.CLOSED, Duration.parse("P1D"), Duration.parse("P10D"), Range.RangeBoundary.OPEN)), null }, { "[ [ duration(\"P1D\") .. duration(\"P10D\") ] ]", Collections.singletonList(new RangeImpl(Range.RangeBoundary.CLOSED, Duration.parse("P1D"), Duration.parse("P10D"), Range.RangeBoundary.CLOSED)), null }, { "[ ( duration(\"P1D\") .. duration(\"P10D\") ), ( duration(\"P2D\") .. duration(\"P10D\") )][1]", new RangeImpl(Range.RangeBoundary.OPEN, Duration.parse("P1D"), Duration.parse("P10D"), Range.RangeBoundary.OPEN), null } };
    return addAdditionalParameters(cases, false);
}
Also used : HashMap(java.util.HashMap) RangeImpl(org.kie.dmn.feel.runtime.impl.RangeImpl)

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