gitgabrio commented on code in PR #6537:
URL:
https://github.com/apache/incubator-kie-drools/pull/6537#discussion_r2571189753
##########
kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/BooleanEvalHelper.java:
##########
@@ -62,9 +60,13 @@ public static Boolean getBooleanOrNull(Object value) {
* @param op
* @return
*/
- public static Boolean compare(Object left, Object right, FEELDialect
feelDialect, BiPredicate<Comparable, Comparable> op) {
+ public static Boolean compare(Object left, Object right,
BiPredicate<Comparable, Comparable> op, Supplier<Boolean> nullFallback,
Review Comment:
Hi @ChinchuAjith
I'm not 100% sure of this approach.
Those two `Supplier`s basically depend on the FEELDialect, and this
compareMethod - IINW, is invoked only by the FEELHandlers. I've the impression
that, as the code currently is, this method could be completely remove - if
actually invoked only by DialectHandlers and test, and managed directly inside
handler: wdyt ? (I may be miss something, of course)
##########
kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/BooleanEvalHelper.java:
##########
@@ -96,19 +98,69 @@ public static Boolean compare(Object left, Object right,
FEELDialect feelDialect
Comparable<?> r = (Comparable<?>) right;
return op.test(l, r);
}
- return getBooleanOrDialectDefault(null, feelDialect);
+ return defaultFallback.get();
}
+ /**
+ * Compares left and right operands using the given predicate and returns
TRUE/FALSE accordingly
+ *
+ * @param left
+ * @param right
+ * @param op
+ * @return
+ */
+ /*
+ * public static Boolean compare(Object left, Object right, FEELDialect
feelDialect, BiPredicate<Comparable, Comparable> op) {
+ * if (left == null || right == null) {
+ * return getBooleanOrDialectDefault(null, feelDialect);
+ * }
+ * if (left instanceof ChronoPeriod && right instanceof ChronoPeriod) {
+ * // periods have special compare semantics in FEEL as it ignores "days".
Only months and years are compared
+ * Long l = ComparablePeriod.toTotalMonths((ChronoPeriod) left);
+ * Long r = ComparablePeriod.toTotalMonths((ChronoPeriod) right);
+ * return op.test(l, r);
+ * }
+ * if (left instanceof TemporalAccessor && right instanceof
TemporalAccessor) {
+ * // Handle specific cases when both time / datetime
+ * TemporalAccessor l = (TemporalAccessor) left;
+ * TemporalAccessor r = (TemporalAccessor) right;
+ * if (BuiltInTypeUtils.determineTypeFromInstance(left) ==
BuiltInType.TIME && BuiltInTypeUtils.determineTypeFromInstance(right) ==
BuiltInType.TIME) {
+ * return op.test(valuet(l), valuet(r));
+ * } else if (BuiltInTypeUtils.determineTypeFromInstance(left) ==
BuiltInType.DATE_TIME && BuiltInTypeUtils.determineTypeFromInstance(right) ==
BuiltInType.DATE_TIME) {
+ * return op.test(valuedt(l, r.query(TemporalQueries.zone())), valuedt(r,
l.query(TemporalQueries.zone())));
+ * }
+ * }
+ * if (left instanceof Number && right instanceof Number) {
+ * // Handle specific cases when both are Number, converting both to
BigDecimal
+ * BigDecimal l = getBigDecimalOrNull(left);
+ * BigDecimal r = getBigDecimalOrNull(right);
+ * return op.test(l, r);
+ * }
+ * // last fallback:
+ * if ((left instanceof String && right instanceof String) ||
+ * (left instanceof Boolean && right instanceof Boolean) ||
+ * (left instanceof Comparable &&
left.getClass().isAssignableFrom(right.getClass()))) {
+ * Comparable<?> l = (Comparable<?>) left;
+ * Comparable<?> r = (Comparable<?>) right;
+ * return op.test(l, r);
+ * }
+ * return getBooleanOrDialectDefault(null, feelDialect);
+ * }
+ */
+
/**
* Compares left and right for equality applying FEEL semantics to
specific data types
*
* @param left
* @param right
* @return
*/
- public static Boolean isEqual(Object left, Object right, FEELDialect
feelDialect) {
+ public static Boolean isEqual(Object left, Object right, Supplier<Boolean>
nullFallback, Supplier<Boolean> defaultFallback) {
Review Comment:
Same comment as above
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]