You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/04/27 11:37:19 UTC

[camel] branch main updated: CAMEL-16477: camel-core - ProcessorDefinitionHelper: ruturn a collection instead of an iterator for filterTypeInOutputs methods

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 1d7d94a  CAMEL-16477: camel-core - ProcessorDefinitionHelper: ruturn a collection instead of an iterator for filterTypeInOutputs methods
1d7d94a is described below

commit 1d7d94a3f0d8b246f380be2c5b244a8c1242eded
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Apr 27 13:36:20 2021 +0200

    CAMEL-16477: camel-core - ProcessorDefinitionHelper: ruturn a collection instead of an iterator for filterTypeInOutputs methods
---
 .../java/org/apache/camel/component/kamelet/Kamelet.java  |  7 +++----
 .../src/main/java/org/apache/camel/impl/DefaultModel.java |  6 ++----
 .../java/org/apache/camel/builder/AdviceWithTasks.java    | 11 +++++------
 .../java/org/apache/camel/model/ProcessorDefinition.java  |  6 ++----
 .../org/apache/camel/model/ProcessorDefinitionHelper.java |  8 ++++----
 .../org/apache/camel/model/RouteDefinitionHelper.java     | 14 +++++++-------
 .../main/java/org/apache/camel/model/TryDefinition.java   |  7 +++----
 .../apache/camel/model/ProcessorDefinitionHelperTest.java |  2 +-
 .../main/java/org/apache/camel/xml/jaxb/JaxbHelper.java   | 15 +++++++--------
 .../modules/ROOT/pages/camel-3x-upgrade-guide-3_10.adoc   |  3 +++
 10 files changed, 37 insertions(+), 42 deletions(-)

diff --git a/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/Kamelet.java b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/Kamelet.java
index 3733459..98626ae 100644
--- a/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/Kamelet.java
+++ b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/Kamelet.java
@@ -16,7 +16,7 @@
  */
 package org.apache.camel.component.kamelet;
 
-import java.util.Iterator;
+import java.util.Collection;
 import java.util.Map;
 import java.util.Properties;
 import java.util.function.Predicate;
@@ -134,9 +134,8 @@ public final class Kamelet {
 
         // there must be at least one sink
         boolean sink = false;
-        Iterator<ToDefinition> it = filterTypeInOutputs(def.getOutputs(), ToDefinition.class);
-        while (it.hasNext()) {
-            ToDefinition to = it.next();
+        Collection<ToDefinition> col = filterTypeInOutputs(def.getOutputs(), ToDefinition.class);
+        for (ToDefinition to : col) {
             if (to.getEndpointUri().startsWith("kamelet:sink") || to.getEndpointUri().startsWith("kamelet://sink")) {
                 to.setUri("kamelet://sink?" + PARAM_ROUTE_ID + "=" + rid);
                 sink = true;
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java
index 042fe76..e10a28c 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java
@@ -20,7 +20,6 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.StringJoiner;
@@ -434,10 +433,9 @@ public class DefaultModel implements Model {
     @Override
     public ProcessorDefinition<?> getProcessorDefinition(String id) {
         for (RouteDefinition route : getRouteDefinitions()) {
-            Iterator<ProcessorDefinition> it
+            Collection<ProcessorDefinition> col
                     = ProcessorDefinitionHelper.filterTypeInOutputs(route.getOutputs(), ProcessorDefinition.class);
-            while (it.hasNext()) {
-                ProcessorDefinition<?> proc = it.next();
+            for (ProcessorDefinition proc : col) {
                 if (id.equals(proc.getId())) {
                     return proc;
                 }
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/builder/AdviceWithTasks.java b/core/camel-core-model/src/main/java/org/apache/camel/builder/AdviceWithTasks.java
index 7faf31e..2633e63 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/builder/AdviceWithTasks.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/builder/AdviceWithTasks.java
@@ -17,6 +17,7 @@
 package org.apache.camel.builder;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 
@@ -538,13 +539,11 @@ public final class AdviceWithTasks {
         }
 
         @SuppressWarnings("rawtypes")
-        Iterator<ProcessorDefinition> itAll
+        Collection<ProcessorDefinition> all
                 = ProcessorDefinitionHelper.filterTypeInOutputs(outputs, ProcessorDefinition.class, maxDeep);
-        while (itAll.hasNext()) {
-            ProcessorDefinition<?> next = itAll.next();
-
-            if (matchBy.match(next)) {
-                matched.add(next);
+        for (ProcessorDefinition proc : all) {
+            if (matchBy.match(proc)) {
+                matched.add(proc);
             }
         }
 
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index 0cfe946..10f9145 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -21,7 +21,6 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Comparator;
-import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
@@ -3575,11 +3574,10 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
     public OnCompletionDefinition onCompletion() {
         OnCompletionDefinition answer = new OnCompletionDefinition();
 
-        Iterator<OnCompletionDefinition> it
+        Collection<OnCompletionDefinition> col
                 = ProcessorDefinitionHelper.filterTypeInOutputs(getOutputs(), OnCompletionDefinition.class);
         // check if there is a clash
-        while (it.hasNext()) {
-            OnCompletionDefinition ocd = it.next();
+        for (OnCompletionDefinition ocd : col) {
             if (ocd.isRouteScoped()) {
                 throw new IllegalArgumentException("Only 1 onCompletion is allowed per route.");
             }
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
index 7925053..2ff6413 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
@@ -17,7 +17,7 @@
 package org.apache.camel.model;
 
 import java.util.ArrayList;
-import java.util.Iterator;
+import java.util.Collection;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
@@ -45,7 +45,7 @@ public final class ProcessorDefinitionHelper {
      * @param  type    the type to look for
      * @return         the found definitions, or <tt>null</tt> if not found
      */
-    public static <T> Iterator<T> filterTypeInOutputs(List<ProcessorDefinition<?>> outputs, Class<T> type) {
+    public static <T> Collection<T> filterTypeInOutputs(List<ProcessorDefinition<?>> outputs, Class<T> type) {
         return filterTypeInOutputs(outputs, type, -1);
     }
 
@@ -57,10 +57,10 @@ public final class ProcessorDefinitionHelper {
      * @param  maxDeep maximum levels deep to traverse
      * @return         the found definitions, or <tt>null</tt> if not found
      */
-    public static <T> Iterator<T> filterTypeInOutputs(List<ProcessorDefinition<?>> outputs, Class<T> type, int maxDeep) {
+    public static <T> Collection<T> filterTypeInOutputs(List<ProcessorDefinition<?>> outputs, Class<T> type, int maxDeep) {
         List<T> found = new ArrayList<>();
         doFindType(outputs, type, found, maxDeep);
-        return found.iterator();
+        return found;
     }
 
     /**
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java b/core/camel-core-model/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
index 9b99990..edc6de4 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
@@ -19,9 +19,9 @@ package org.apache.camel.model;
 import java.io.UnsupportedEncodingException;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
@@ -89,9 +89,10 @@ public final class RouteDefinitionHelper {
         }
 
         if (includeOutputs) {
-            Iterator<EndpointRequiredDefinition> it = filterTypeInOutputs(route.getOutputs(), EndpointRequiredDefinition.class);
-            while (it.hasNext()) {
-                String uri = normalizeUri(it.next().getEndpointUri());
+            Collection<EndpointRequiredDefinition> col
+                    = filterTypeInOutputs(route.getOutputs(), EndpointRequiredDefinition.class);
+            for (EndpointRequiredDefinition erd : col) {
+                String uri = normalizeUri(erd.getEndpointUri());
                 if (uri != null) {
                     answer.add(uri);
                 }
@@ -637,11 +638,10 @@ public final class RouteDefinitionHelper {
         List<OnCompletionDefinition> completions = new ArrayList<>();
 
         // check if there is a clash
-        Iterator<OnCompletionDefinition> it
+        Collection<OnCompletionDefinition> col
                 = ProcessorDefinitionHelper.filterTypeInOutputs(abstracts, OnCompletionDefinition.class);
         int count = 0;
-        while (it.hasNext()) {
-            OnCompletionDefinition ocd = it.next();
+        for (OnCompletionDefinition ocd : col) {
             if (ocd.isRouteScoped()) {
                 count++;
             }
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/TryDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/TryDefinition.java
index d754b3d..5014bd3 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/TryDefinition.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/TryDefinition.java
@@ -18,7 +18,7 @@ package org.apache.camel.model;
 
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Iterator;
+import java.util.Collection;
 import java.util.List;
 
 import javax.xml.bind.annotation.XmlAccessType;
@@ -130,9 +130,8 @@ public class TryDefinition extends OutputDefinition<TryDefinition> {
         // TryDefinition
         // to configure all with try .. catch .. finally
         // set the onWhen predicate on all the catch definitions
-        Iterator<CatchDefinition> it = ProcessorDefinitionHelper.filterTypeInOutputs(getOutputs(), CatchDefinition.class);
-        while (it.hasNext()) {
-            CatchDefinition doCatch = it.next();
+        Collection<CatchDefinition> col = ProcessorDefinitionHelper.filterTypeInOutputs(getOutputs(), CatchDefinition.class);
+        for (CatchDefinition doCatch : col) {
             doCatch.setOnWhen(new WhenDefinition(predicate));
         }
         return this;
diff --git a/core/camel-core/src/test/java/org/apache/camel/model/ProcessorDefinitionHelperTest.java b/core/camel-core/src/test/java/org/apache/camel/model/ProcessorDefinitionHelperTest.java
index 299875a..60ed3ed 100644
--- a/core/camel-core/src/test/java/org/apache/camel/model/ProcessorDefinitionHelperTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/model/ProcessorDefinitionHelperTest.java
@@ -32,7 +32,7 @@ public class ProcessorDefinitionHelperTest extends ContextTestSupport {
         RouteDefinition route = context.getRouteDefinitions().get(0);
 
         Iterator<ProcessorDefinition> it
-                = ProcessorDefinitionHelper.filterTypeInOutputs(route.getOutputs(), ProcessorDefinition.class);
+                = ProcessorDefinitionHelper.filterTypeInOutputs(route.getOutputs(), ProcessorDefinition.class).iterator();
         assertNotNull(it);
 
         assertThat(it.next().getId()).matches("choice[0-9]+");
diff --git a/core/camel-xml-jaxb/src/main/java/org/apache/camel/xml/jaxb/JaxbHelper.java b/core/camel-xml-jaxb/src/main/java/org/apache/camel/xml/jaxb/JaxbHelper.java
index b6268ba..a06d1f8 100644
--- a/core/camel-xml-jaxb/src/main/java/org/apache/camel/xml/jaxb/JaxbHelper.java
+++ b/core/camel-xml-jaxb/src/main/java/org/apache/camel/xml/jaxb/JaxbHelper.java
@@ -18,7 +18,7 @@ package org.apache.camel.xml.jaxb;
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.Iterator;
+import java.util.Collection;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -66,10 +66,9 @@ public final class JaxbHelper {
      * @param namespaces the map of namespaces to add discovered XML namespaces into
      */
     public static void extractNamespaces(RouteDefinition route, Map<String, String> namespaces) {
-        Iterator<ExpressionNode> it = filterTypeInOutputs(route.getOutputs(), ExpressionNode.class);
-        while (it.hasNext()) {
-            NamespaceAware na = getNamespaceAwareFromExpression(it.next());
-
+        Collection<ExpressionNode> col = filterTypeInOutputs(route.getOutputs(), ExpressionNode.class);
+        for (ExpressionNode en : col) {
+            NamespaceAware na = getNamespaceAwareFromExpression(en);
             if (na != null) {
                 Map<String, String> map = na.getNamespaces();
                 if (map != null && !map.isEmpty()) {
@@ -137,9 +136,9 @@ public final class JaxbHelper {
     }
 
     public static void applyNamespaces(RouteDefinition route, Map<String, String> namespaces) {
-        Iterator<ExpressionNode> it = filterTypeInOutputs(route.getOutputs(), ExpressionNode.class);
-        while (it.hasNext()) {
-            NamespaceAware na = getNamespaceAwareFromExpression(it.next());
+        Collection<ExpressionNode> col = filterTypeInOutputs(route.getOutputs(), ExpressionNode.class);
+        for (ExpressionNode en : col) {
+            NamespaceAware na = getNamespaceAwareFromExpression(en);
             if (na != null) {
                 na.setNamespaces(namespaces);
             }
diff --git a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_10.adoc b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_10.adoc
index 12fb0b3..43bdab0 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_10.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_10.adoc
@@ -15,6 +15,9 @@ functional interface methods take the current `Exchange` as additional parameter
 to allow for content-based filtering of service candidates. `RibbonServiceLoadBalancer` 
 has no notion of a current exchange, service filters therefore receive a dummy exchange when used with Ribbon.
 
+The two methods `filterTypeInOutputs` on `org.apache.camel.model.ProcessorDefinitionHelper` has changed
+to return `Collection` instead of `Iterator`.
+
 === camel-scheduler
 
 The option `concurrentTasks` has been renamed to `poolSize` to better reflect its purpose.