Search in sources :

Example 6 with Range

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

the class TypeUtil method formatValue.

public static String formatValue(final Object val, final boolean wrapForCodeUsage) {
    if (val instanceof String) {
        return formatString(val.toString(), wrapForCodeUsage);
    } else if (val instanceof LocalDate) {
        return formatDate((LocalDate) val, wrapForCodeUsage);
    } else if (val instanceof LocalTime || val instanceof OffsetTime) {
        return formatTimeString(TimeFunction.FEEL_TIME.format((TemporalAccessor) val), wrapForCodeUsage);
    } else if (val instanceof LocalDateTime || val instanceof OffsetDateTime) {
        return formatDateTimeString(DateAndTimeFunction.FEEL_DATE_TIME.format((TemporalAccessor) val), wrapForCodeUsage);
    } else if (val instanceof ZonedDateTime) {
        TemporalAccessor ta = (TemporalAccessor) val;
        ZoneId zone = ta.query(TemporalQueries.zone());
        if (!(zone instanceof ZoneOffset)) {
            // it is a ZoneRegion
            return formatDateTimeString(DateAndTimeFunction.REGION_DATETIME_FORMATTER.format((TemporalAccessor) val), wrapForCodeUsage);
        } else {
            return formatDateTimeString(DateAndTimeFunction.FEEL_DATE_TIME.format((TemporalAccessor) val), wrapForCodeUsage);
        }
    } else if (val instanceof Duration) {
        return formatDuration((Duration) val, wrapForCodeUsage);
    } else if (val instanceof ChronoPeriod) {
        return formatPeriod((ChronoPeriod) val, wrapForCodeUsage);
    } else if (val instanceof TemporalAccessor) {
        TemporalAccessor ta = (TemporalAccessor) val;
        if (ta.query(TemporalQueries.localDate()) == null && ta.query(TemporalQueries.localTime()) != null && ta.query(TemporalQueries.zoneId()) != null) {
            return formatTimeString(TimeFunction.FEEL_TIME.format((TemporalAccessor) val), wrapForCodeUsage);
        } else {
            return String.valueOf(val);
        }
    } else if (val instanceof List) {
        return formatList((List) val, wrapForCodeUsage);
    } else if (val instanceof Range) {
        return formatRange((Range) val, wrapForCodeUsage);
    } else if (val instanceof Map) {
        return formatContext((Map) val, wrapForCodeUsage);
    } else {
        return String.valueOf(val);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) ChronoPeriod(java.time.chrono.ChronoPeriod) TemporalAccessor(java.time.temporal.TemporalAccessor) LocalTime(java.time.LocalTime) ZoneId(java.time.ZoneId) Duration(java.time.Duration) Range(org.kie.dmn.feel.runtime.Range) LocalDate(java.time.LocalDate) ZoneOffset(java.time.ZoneOffset) OffsetDateTime(java.time.OffsetDateTime) ZonedDateTime(java.time.ZonedDateTime) OffsetTime(java.time.OffsetTime) List(java.util.List) Map(java.util.Map)

Example 7 with Range

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

the class DuringFunctionTest method invokeParamIsNull.

@Test
public void invokeParamIsNull() {
    FunctionTestUtil.assertResultError(duringFunction.invoke((Comparable) null, (Range) new RangeImpl()), InvalidParametersEvent.class);
    FunctionTestUtil.assertResultError(duringFunction.invoke((Comparable) "a", (Range) null), InvalidParametersEvent.class);
}
Also used : Range(org.kie.dmn.feel.runtime.Range) RangeImpl(org.kie.dmn.feel.runtime.impl.RangeImpl) Test(org.junit.Test)

Example 8 with Range

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

the class FinishedByFunctionTest method invokeParamIsNull.

@Test
public void invokeParamIsNull() {
    FunctionTestUtil.assertResultError(finishedByFunction.invoke((Range) null, (Comparable) "b"), InvalidParametersEvent.class);
    FunctionTestUtil.assertResultError(finishedByFunction.invoke((Range) new RangeImpl(), (Comparable) null), InvalidParametersEvent.class);
}
Also used : Range(org.kie.dmn.feel.runtime.Range) RangeImpl(org.kie.dmn.feel.runtime.impl.RangeImpl) Test(org.junit.Test)

Example 9 with Range

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

the class MeetsFunctionTest method invokeParamIsNull.

@Test
public void invokeParamIsNull() {
    FunctionTestUtil.assertResultError(meetsFunction.invoke((Range) null, (Range) new RangeImpl()), InvalidParametersEvent.class);
    FunctionTestUtil.assertResultError(meetsFunction.invoke((Range) new RangeImpl(), (Range) null), InvalidParametersEvent.class);
}
Also used : Range(org.kie.dmn.feel.runtime.Range) RangeImpl(org.kie.dmn.feel.runtime.impl.RangeImpl) Test(org.junit.Test)

Example 10 with Range

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

the class FinishesFunctionTest method invokeParamIsNull.

@Test
public void invokeParamIsNull() {
    FunctionTestUtil.assertResultError(finishesFunction.invoke((Comparable) null, (Range) new RangeImpl()), InvalidParametersEvent.class);
    FunctionTestUtil.assertResultError(finishesFunction.invoke((Comparable) "a", (Range) null), InvalidParametersEvent.class);
}
Also used : Range(org.kie.dmn.feel.runtime.Range) RangeImpl(org.kie.dmn.feel.runtime.impl.RangeImpl) Test(org.junit.Test)

Aggregations

Range (org.kie.dmn.feel.runtime.Range)23 RangeImpl (org.kie.dmn.feel.runtime.impl.RangeImpl)14 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Map (java.util.Map)6 DMNContext (org.kie.dmn.api.core.DMNContext)4 EvaluatorResult (org.kie.dmn.core.api.EvaluatorResult)4 DMNResultImpl (org.kie.dmn.core.impl.DMNResultImpl)4 ChronoPeriod (java.time.chrono.ChronoPeriod)3 TemporalAccessor (java.time.temporal.TemporalAccessor)3 Duration (java.time.Duration)2 ZoneId (java.time.ZoneId)2 LinkedList (java.util.LinkedList)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 EvaluatorResultImpl (org.kie.dmn.core.ast.EvaluatorResultImpl)2 IterableRange (org.kie.dmn.core.util.IterableRange)2 FEELFunction (org.kie.dmn.feel.runtime.FEELFunction)2 UnaryTest (org.kie.dmn.feel.runtime.UnaryTest)2 IterableRange (org.kie.dmn.trisotech.core.util.IterableRange)2