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

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

commit 5949e91a22f654267817654064cd598a5163c4f1
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Thu Apr 11 13:34:22 2024 +0200

    (chores) camel-core-support: extract independent code snippets from large 
code blocks
---
 .../org/apache/camel/support/EndpointHelper.java   | 49 ++++++++++++----------
 .../camel/support/component/ApiMethodParser.java   | 41 ++++++++++--------
 2 files changed, 50 insertions(+), 40 deletions(-)

diff --git 
a/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java 
b/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java
index f13cb037f01..eb1c640e785 100644
--- 
a/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java
+++ 
b/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java
@@ -118,36 +118,41 @@ public final class EndpointHelper {
         // the query parameters needs to be rebuild by removing the unresolved 
key=value pairs
         if (query != null && query.contains(prefix)) {
             Map<String, Object> params = URISupport.parseQuery(query);
-            Map<String, Object> keep = new LinkedHashMap<>();
-            for (Map.Entry<String, Object> entry : params.entrySet()) {
-                String key = entry.getKey();
-                if (key.startsWith(prefix)) {
+            final Map<String, Object> keep = extractParamsToKeep(params, 
prefix);
+            // rebuild query
+            query = URISupport.createQueryString(keep);
+        }
+
+        // assemble uri as answer
+        uri = query != null && !query.isEmpty() ? base + "?" + query : base;
+        return uri;
+    }
+
+    private static Map<String, Object> extractParamsToKeep(Map<String, Object> 
params, String prefix) {
+        Map<String, Object> keep = new LinkedHashMap<>();
+        for (Map.Entry<String, Object> entry : params.entrySet()) {
+            String key = entry.getKey();
+            if (key.startsWith(prefix)) {
+                continue;
+            }
+            Object value = entry.getValue();
+            if (value instanceof String) {
+                String s = value.toString();
+                if (s.startsWith(prefix)) {
                     continue;
                 }
-                Object value = entry.getValue();
-                if (value instanceof String) {
-                    String s = value.toString();
+                // okay the value may use a resource loader with a scheme 
prefix
+                int dot = s.indexOf(':');
+                if (dot > 0 && dot < s.length() - 1) {
+                    s = s.substring(dot + 1);
                     if (s.startsWith(prefix)) {
                         continue;
                     }
-                    // okay the value may use a resource loader with a scheme 
prefix
-                    int dot = s.indexOf(':');
-                    if (dot > 0 && dot < s.length() - 1) {
-                        s = s.substring(dot + 1);
-                        if (s.startsWith(prefix)) {
-                            continue;
-                        }
-                    }
                 }
-                keep.put(key, value);
             }
-            // rebuild query
-            query = URISupport.createQueryString(keep);
+            keep.put(key, value);
         }
-
-        // assemble uri as answer
-        uri = query != null && !query.isEmpty() ? base + "?" + query : base;
-        return uri;
+        return keep;
     }
 
     /**
diff --git 
a/core/camel-support/src/main/java/org/apache/camel/support/component/ApiMethodParser.java
 
b/core/camel-support/src/main/java/org/apache/camel/support/component/ApiMethodParser.java
index dff9938052e..650095e7782 100644
--- 
a/core/camel-support/src/main/java/org/apache/camel/support/component/ApiMethodParser.java
+++ 
b/core/camel-support/src/main/java/org/apache/camel/support/component/ApiMethodParser.java
@@ -207,24 +207,7 @@ public abstract class ApiMethodParser<T> {
         result = processResults(result);
 
         // check that argument names have the same type across methods
-        Map<String, Class<?>> allArguments = new HashMap<>();
-        for (ApiMethodModel model : result) {
-            for (ApiMethodArg argument : model.getArguments()) {
-                String name = argument.getName();
-                Class<?> argClass = allArguments.get(name);
-                Class<?> type = argument.getType();
-                if (argClass == null) {
-                    allArguments.put(name, type);
-                } else {
-                    if (argClass != type) {
-                        throw new IllegalArgumentException(
-                                "Argument [" + name
-                                                           + "] is used in 
multiple methods with different types "
-                                                           + 
argClass.getCanonicalName() + ", " + type.getCanonicalName());
-                    }
-                }
-            }
-        }
+        final Map<String, Class<?>> allArguments = extractArguments(result);
         allArguments.clear();
 
         result.sort(new Comparator<>() {
@@ -276,6 +259,28 @@ public abstract class ApiMethodParser<T> {
         return result;
     }
 
+    private static Map<String, Class<?>> extractArguments(List<ApiMethodModel> 
result) {
+        Map<String, Class<?>> allArguments = new HashMap<>();
+        for (ApiMethodModel model : result) {
+            for (ApiMethodArg argument : model.getArguments()) {
+                String name = argument.getName();
+                Class<?> argClass = allArguments.get(name);
+                Class<?> type = argument.getType();
+                if (argClass == null) {
+                    allArguments.put(name, type);
+                } else {
+                    if (argClass != type) {
+                        throw new IllegalArgumentException(
+                                "Argument [" + name
+                                                           + "] is used in 
multiple methods with different types "
+                                                           + 
argClass.getCanonicalName() + ", " + type.getCanonicalName());
+                    }
+                }
+            }
+        }
+        return allArguments;
+    }
+
     protected List<ApiMethodModel> processResults(List<ApiMethodModel> result) 
{
         return result;
     }

Reply via email to