gitgabrio commented on code in PR #6557:
URL:
https://github.com/apache/incubator-kie-drools/pull/6557#discussion_r2711934534
##########
kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/UnaryTestNode.java:
##########
@@ -158,15 +159,66 @@ public UnaryTest getUnaryTest() {
* For a Unary Test an = (equal) semantic depends on the RIGHT value.
* If the RIGHT is NOT a list, then standard equals semantic applies
* If the RIGHT is a LIST, then the semantic is "right contains left"
+ * When both are Collections:
+ * - Verify that the two objects have the same size
+ * - Verify that the elements in left object are contained, in the same
order, in the right object
*/
private Boolean utEqualSemantic(Object left, Object right) {
- if (right instanceof Collection) {
- return ((Collection) right).contains(left);
+ if (left instanceof Collection && right instanceof Collection) {
+ return areCollectionsEqual((Collection<?>) left, (Collection<?>)
right);
+ } else if (right instanceof Collection) {
+ return isElementInCollection((Collection<?>) right, left);
} else {
- // evaluate single entity
- return DefaultDialectHandler.isEqual(left, right, () -> (left ==
null && right == null), () -> Boolean.FALSE);
+ return areElementsEqual(left, right);
+ }
+ }
+ /**
+ * Checks if two collections are equal by comparing elements in order.
+ * Both collections must have the same size and each element at position i
in left
+ * must equal the element at position i in right.
+ *
+ * @param left the left collection
+ * @param right the right collection
+ * @return true if collections have same size and elements match in order,
false otherwise
+ */
+ static Boolean areCollectionsEqual(Collection<?> left, Collection<?>
right) {
+ if (left.size() != right.size()) {
+ return false;
}
+
+ Iterator<?> rightIterator = right.iterator();
+ return left.stream()
+ .allMatch(leftElement -> {
+ Object rightElement = rightIterator.next();
+ return areElementsEqual(leftElement, rightElement);
+ });
+ }
+
+ /**
+ * Checks if a collection contains a specific element.
+ *
+ * @param collection the collection to search in
+ * @param element the element to search for
+ * @return true if collection contains the element, false otherwise
+ */
+ static Boolean isElementInCollection(Collection<?> collection, Object
element) {
+ return collection.contains(element);
Review Comment:
@yesamer @AthiraHari77 @ChinchuAjith
That comment seems reasonable (not the suggested code).
But, the original implementation was the Collection.contains: wdyt ?
--
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]