use of org.kie.dmn.feel.lang.types.impl.ComparablePeriod in project drools by kiegroup.
the class RangeNode method convertToComparable.
private Comparable convertToComparable(EvaluationContext ctx, Object s) {
Comparable start;
if (s == null) {
start = null;
} else if (s instanceof Comparable) {
start = (Comparable) s;
} else if (s instanceof Period) {
// period has special semantics
start = new ComparablePeriod((Period) s);
} else {
ctx.notifyEvt(astEvent(Severity.ERROR, Msg.createMessage(Msg.INCOMPATIBLE_TYPE_FOR_RANGE, s.getClass().getSimpleName())));
start = null;
}
return start;
}
use of org.kie.dmn.feel.lang.types.impl.ComparablePeriod in project drools by kiegroup.
the class YearsAndMonthsFunction method invoke.
public FEELFnResult<TemporalAmount> invoke(@ParameterName("from") Temporal from, @ParameterName("to") Temporal to) {
if (from == null) {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "from", "cannot be null"));
}
if (to == null) {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "to", "cannot be null"));
}
final LocalDate fromDate = getLocalDateFromTemporal(from);
if (fromDate == null) {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "from", "is of type not suitable for years and months function"));
}
final LocalDate toDate = getLocalDateFromTemporal(to);
if (toDate == null) {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "to", "is of type not suitable for years and months function"));
}
return FEELFnResult.ofResult(new ComparablePeriod(Period.between(fromDate, toDate).withDays(0)));
}
use of org.kie.dmn.feel.lang.types.impl.ComparablePeriod in project drools by kiegroup.
the class DTAnalysisMeta method boundAsExpression.
private static Expression boundAsExpression(Bound<?> bound) {
Comparable<?> value = bound.getValue();
Expression valueExpr = null;
if (value == Interval.NEG_INF) {
valueExpr = parseExpression("Interval.NEG_INF");
} else if (value == Interval.POS_INF) {
valueExpr = parseExpression("Interval.POS_INF");
} else if (value instanceof BigDecimal) {
BigDecimal bigDecimal = (BigDecimal) value;
ObjectCreationExpr newExpression = parseExpression("new BigDecimal()");
StringLiteralExpr stringRep = new StringLiteralExpr(bigDecimal.toString());
newExpression.addArgument(stringRep);
valueExpr = newExpression;
} else if (value instanceof String) {
String string = (String) value;
StringLiteralExpr newExpression = new StringLiteralExpr();
newExpression.setString(string);
valueExpr = newExpression;
} else if (value instanceof Boolean) {
Boolean b = (Boolean) value;
valueExpr = new BooleanLiteralExpr(b);
} else if (value instanceof LocalDate) {
LocalDate localDateTime = (LocalDate) value;
MethodCallExpr newExpression = parseExpression("java.time.LocalDate.parse()");
StringLiteralExpr stringRep = new StringLiteralExpr(localDateTime.toString());
newExpression.addArgument(stringRep);
valueExpr = newExpression;
} else if (value instanceof ComparablePeriod) {
ComparablePeriod comparablePeriod = (ComparablePeriod) value;
MethodCallExpr newExpression = parseExpression("org.kie.dmn.feel.lang.types.impl.ComparablePeriod.parse()");
StringLiteralExpr stringRep = new StringLiteralExpr(comparablePeriod.asPeriod().toString());
newExpression.addArgument(stringRep);
valueExpr = newExpression;
} else {
throw new UnsupportedOperationException("boundAsExpression value " + value + " not supported.");
}
Expression typeExpr = null;
if (bound.getBoundaryType() == RangeBoundary.OPEN) {
typeExpr = parseExpression("RangeBoundary.OPEN");
} else if (bound.getBoundaryType() == RangeBoundary.CLOSED) {
typeExpr = parseExpression("RangeBoundary.CLOSED");
} else {
throw new IllegalStateException("illegal getBoundaryType");
}
ObjectCreationExpr newExpression = parseExpression("new Bound()");
newExpression.addArgument(valueExpr);
newExpression.addArgument(typeExpr);
newExpression.addArgument(new NullLiteralExpr());
return newExpression;
}
Aggregations