davsclaus commented on code in PR #26806:
URL: https://github.com/apache/camel/pull/26806#discussion_r4085522978


##########
core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/LogicalExpression.java:
##########
@@ -93,40 +93,22 @@ public Expression createExpression(CamelContext 
camelContext, String expression)
         final Expression leftExp = left.createExpression(camelContext, 
expression);
         final Expression rightExp = right.createExpression(camelContext, 
expression);
 
+        // build the predicate once, not for every message
+        final Predicate leftPredicate = 
ExpressionToPredicateAdapter.toPredicate(leftExp);
+        final Predicate rightPredicate = 
ExpressionToPredicateAdapter.toPredicate(rightExp);
         if (operator == LogicalOperatorType.AND) {
-            return createAndExpression(leftExp, rightExp);
+            return createExpression(PredicateBuilder.and(leftPredicate, 
rightPredicate));
         } else if (operator == LogicalOperatorType.OR) {
-            return createOrExpression(leftExp, rightExp);
+            return createExpression(PredicateBuilder.or(leftPredicate, 
rightPredicate));
         }
 
         throw new SimpleParserException("Unknown logical operator " + 
operator, token.getIndex());
     }
 
-    private Expression createAndExpression(final Expression leftExp, final 
Expression rightExp) {
+    private Expression createExpression(final Predicate predicate) {
         return new Expression() {
             @Override
             public <T> T evaluate(Exchange exchange, Class<T> type) {
-                Predicate predicate = 
ExpressionToPredicateAdapter.toPredicate(leftExp);
-                predicate = PredicateBuilder.and(predicate, 
ExpressionToPredicateAdapter.toPredicate(rightExp));
-
-                boolean answer = predicate.matches(exchange);
-                return 
exchange.getContext().getTypeConverter().convertTo(type, answer);
-            }
-
-            @Override
-            public String toString() {
-                return left + " " + token.getText() + " " + right;
-            }
-        };
-    }
-
-    private Expression createOrExpression(final Expression leftExp, final 
Expression rightExp) {
-        return new Expression() {
-            @Override
-            public <T> T evaluate(Exchange exchange, Class<T> type) {
-                Predicate predicate = 
ExpressionToPredicateAdapter.toPredicate(leftExp);
-                predicate = PredicateBuilder.or(predicate, 
ExpressionToPredicateAdapter.toPredicate(rightExp));
-
                 boolean answer = predicate.matches(exchange);
                 return 
exchange.getContext().getTypeConverter().convertTo(type, answer);
             }

Review Comment:
   The override is still there: the new shared `createExpression(Predicate)` 
overrides `toString()` at lines 116-119, with the same `left + " " + 
token.getText() + " " + right` as the two methods it replaces, so logs keep 
showing the readable form. To pin that down, 8776249b126b adds 
`testLogicalExpressionToString`, which asserts `${body != null && body.size() > 
0}` prints as `${body} != null && ${body.size()} > 0`.
   
   _Claude Code on behalf of davsclaus_
   



##########
core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/OtherExpression.java:
##########
@@ -109,4 +110,9 @@ public String toString() {
             }
         };
     }
+
+    private static boolean isZero(Object value) {
+        // any kind of number such as 0, 0L, 0.0 or BigDecimal.ZERO
+        return value instanceof Number n && n.doubleValue() == 0;

Review Comment:
   Good point, that is the intent. Applied in 8776249b126b as a comment in the 
existing style (`-0.0 is also zero, NaN is not`), and `testElvisAnyZero` now 
asserts both: `-0.0 ?: 'none'` gives `none`, and `NaN ?: 'none'` gives `NaN`.
   
   _Claude Code on behalf of davsclaus_
   



-- 
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]

Reply via email to