This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new dd01512b408 CAMEL-20960: camel-jbang - camel top processor should 
group by pid
dd01512b408 is described below

commit dd01512b40801b28734e02e402744189298fffb6
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Jul 10 13:08:00 2024 +0200

    CAMEL-20960: camel-jbang - camel top processor should group by pid
---
 .../core/commands/process/CamelProcessorTop.java   | 25 ++++++++++++++--------
 .../jbang/core/commands/process/CamelRouteTop.java | 25 ++++++++++++++--------
 2 files changed, 32 insertions(+), 18 deletions(-)

diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelProcessorTop.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelProcessorTop.java
index fa8a9e27cee..6bc07cb5817 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelProcessorTop.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelProcessorTop.java
@@ -29,16 +29,23 @@ public class CamelProcessorTop extends CamelProcessorStatus 
{
 
     @Override
     protected int sortRow(Row o1, Row o2) {
-        // sort for highest mean value as we want the slowest in the top
-        long m1 = o1.mean != null ? Long.parseLong(o1.mean) : 0;
-        long m2 = o2.mean != null ? Long.parseLong(o2.mean) : 0;
-        if (m1 < m2) {
-            return 1;
-        } else if (m1 > m2) {
-            return -1;
-        } else {
-            return 0;
+        // use super to group by first
+        int answer = super.sortRow(o1, o2);
+        if (answer == 0) {
+            int negate = 1;
+            if (sort.startsWith("-")) {
+                negate = -1;
+            }
+            // sort for highest mean value as we want the slowest in the top
+            long m1 = o1.mean != null ? Long.parseLong(o1.mean) : 0;
+            long m2 = o2.mean != null ? Long.parseLong(o2.mean) : 0;
+            if (m1 < m2) {
+                answer = 1 * negate;
+            } else if (m1 > m2) {
+                answer = -1 * negate;
+            }
         }
+        return answer;
     }
 
 }
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelRouteTop.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelRouteTop.java
index 75d65f92a70..a2e6e1d8401 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelRouteTop.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelRouteTop.java
@@ -82,16 +82,23 @@ public class CamelRouteTop extends CamelRouteStatus {
 
     @Override
     protected int sortRow(Row o1, Row o2) {
-        // sort for highest mean value as we want the slowest in the top
-        long m1 = o1.mean != null ? Long.parseLong(o1.mean) : 0;
-        long m2 = o2.mean != null ? Long.parseLong(o2.mean) : 0;
-        if (m1 < m2) {
-            return 1;
-        } else if (m1 > m2) {
-            return -1;
-        } else {
-            return 0;
+        // use super to group by first
+        int answer = super.sortRow(o1, o2);
+        if (answer == 0) {
+            int negate = 1;
+            if (sort.startsWith("-")) {
+                negate = -1;
+            }
+            // sort for highest mean value as we want the slowest in the top
+            long m1 = o1.mean != null ? Long.parseLong(o1.mean) : 0;
+            long m2 = o2.mean != null ? Long.parseLong(o2.mean) : 0;
+            if (m1 < m2) {
+                answer = 1 * negate;
+            } else if (m1 > m2) {
+                answer = -1 * negate;
+            }
         }
+        return answer;
     }
 
 }

Reply via email to