orpiske commented on code in PR #21086:
URL: https://github.com/apache/camel/pull/21086#discussion_r2732576082


##########
core/camel-console/src/main/java/org/apache/camel/impl/console/BrowseDevConsole.java:
##########
@@ -104,45 +104,48 @@ protected String doCallText(Map<String, Object> options) {
         StringBuilder sb = new StringBuilder();
 
         String filter = (String) options.get(FILTER);
-        String lim = (String) options.get(LIMIT);
-        String tail = (String) options.get(TAIL);
-        final int pos = tail == null ? 0 : Integer.parseInt(tail);
-        final int max = lim == null ? limit : Integer.parseInt(lim);
-        boolean freshSize = "true".equals(options.getOrDefault(FRESH_SIZE, 
"false"));
-        boolean dump = "true".equals(options.getOrDefault(DUMP, "true"));
-        boolean includeBody = "true".equals(options.getOrDefault(INCLUDE_BODY, 
"true"));
-        int maxChars = Integer.parseInt((String) 
options.getOrDefault(BODY_MAX_CHARS, "" + bodyMaxChars));
+        final int pos = parseIntOption(options, TAIL, 0);
+        final int max = parseIntOption(options, LIMIT, limit);
+        boolean freshSize = parseBooleanOption(options, FRESH_SIZE, false);
+        boolean dump = parseBooleanOption(options, DUMP, true);
+        boolean includeBody = parseBooleanOption(options, INCLUDE_BODY, true);
+        int maxChars = parseIntOption(options, BODY_MAX_CHARS, bodyMaxChars);
 
         Collection<Endpoint> endpoints = new 
TreeSet<>(Comparator.comparing(Endpoint::getEndpointUri));
         endpoints.addAll(getCamelContext().getEndpoints());
         for (Endpoint endpoint : endpoints) {
-            if (endpoint instanceof BrowsableEndpoint be
-                    && (filter == null || 
PatternHelper.matchPattern(endpoint.getEndpointUri(), filter))) {
-
-                if (dump) {
-                    List<Exchange> list = freshSize ? 
be.getExchanges(Integer.MAX_VALUE, null) : be.getExchanges(max, null);
-                    int queueSize = list != null ? list.size() : 0;
-                    int begin = 0;
-                    if (list != null && pos > 0) {
-                        begin = Math.max(0, list.size() - pos);
-                        list = list.subList(begin, list.size());
-                    }
-                    if (list != null) {
-                        sb.append("\n");
-                        sb.append(String.format("Browse: %s (size: %d limit: 
%d position: %d)%n", endpoint.getEndpointUri(),
-                                queueSize, max, begin));
-                        for (Exchange e : list) {
-                            String json
-                                    = MessageHelper.dumpAsJSon(e.getMessage(), 
false, false, includeBody, 2, true, true, true,
-                                            maxChars, true);
-                            sb.append(json);
-                            sb.append("\n");
-                        }
-                    }
-                } else {
-                    BrowsableEndpoint.BrowseStatus status = 
be.getBrowseStatus(Integer.MAX_VALUE);
-                    sb.append(String.format("Browse: %s (size: %d%n", 
endpoint.getEndpointUri(), status.size()));
-                }
+            if (!(endpoint instanceof BrowsableEndpoint be)) {
+                continue;
+            }
+            if (!matchesFilter(endpoint.getEndpointUri(), filter)) {
+                continue;
+            }
+
+            if (!dump) {
+                BrowsableEndpoint.BrowseStatus status = 
be.getBrowseStatus(Integer.MAX_VALUE);
+                sb.append(String.format("Browse: %s (size: %d%n", 
endpoint.getEndpointUri(), status.size()));
+                continue;
+            }
+
+            List<Exchange> list = freshSize ? 
be.getExchanges(Integer.MAX_VALUE, null) : be.getExchanges(max, null);
+            if (list == null) {
+                continue;
+            }
+
+            int queueSize = list.size();
+            int begin = calculateBeginPosition(list.size(), pos);
+            if (begin > 0) {
+                list = list.subList(begin, list.size());
+            }
+
+            sb.append("\n");
+            sb.append(String.format("Browse: %s (size: %d limit: %d position: 
%d)%n", endpoint.getEndpointUri(),
+                    queueSize, max, begin));
+            for (Exchange e : list) {
+                String json = MessageHelper.dumpAsJSon(e.getMessage(), false, 
false, includeBody, 2, true, true, true,
+                        maxChars, true);
+                sb.append(json);
+                sb.append("\n");

Review Comment:
   TBH, I feel this is a lot better to read than before. 



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