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 fdf41d26312c1482fd5193b29f16904ddd3b0541
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Mon Aug 26 12:15:23 2024 +0200

    (chores) camel-rest simplify type checks
    
    - to use pattern matching for instanceof
    - use simpler assertion checks
---
 .../camel/component/rest/DefaultRestRegistry.java  |  8 ++--
 .../camel/component/rest/RestApiEndpoint.java      | 16 ++++----
 .../apache/camel/component/rest/RestEndpoint.java  | 44 +++++++++++-----------
 .../rest/RestProducerBindingProcessor.java         | 16 ++++----
 4 files changed, 42 insertions(+), 42 deletions(-)

diff --git 
a/components/camel-rest/src/main/java/org/apache/camel/component/rest/DefaultRestRegistry.java
 
b/components/camel-rest/src/main/java/org/apache/camel/component/rest/DefaultRestRegistry.java
index e63dc1aa022..b0827bf4c38 100644
--- 
a/components/camel-rest/src/main/java/org/apache/camel/component/rest/DefaultRestRegistry.java
+++ 
b/components/camel-rest/src/main/java/org/apache/camel/component/rest/DefaultRestRegistry.java
@@ -257,8 +257,8 @@ public class DefaultRestRegistry extends ServiceSupport 
implements StaticService
         public String getState() {
             // must use String type to be sure remote JMX can read the 
attribute without requiring Camel classes.
             ServiceStatus status = null;
-            if (consumer instanceof StatefulService) {
-                status = ((StatefulService) consumer).getStatus();
+            if (consumer instanceof StatefulService statefulService) {
+                status = statefulService.getStatus();
             }
             // if no status exists then its stopped
             if (status == null) {
@@ -284,8 +284,8 @@ public class DefaultRestRegistry extends ServiceSupport 
implements StaticService
             super.onServiceRemove(context, service, route);
 
             // if its a consumer then de-register it from the rest registry
-            if (service instanceof Consumer) {
-                removeRestService((Consumer) service);
+            if (service instanceof Consumer consumer) {
+                removeRestService(consumer);
             }
         }
     }
diff --git 
a/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestApiEndpoint.java
 
b/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestApiEndpoint.java
index 547e18c9f1a..61148135361 100644
--- 
a/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestApiEndpoint.java
+++ 
b/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestApiEndpoint.java
@@ -214,12 +214,12 @@ public class RestApiEndpoint extends DefaultEndpoint {
         // the API then uses the api component (eg usually camel-openapi-java) 
to build the API
         if (getConsumerComponentName() != null) {
             Object comp = 
getCamelContext().getRegistry().lookupByName(getConsumerComponentName());
-            if (comp instanceof RestApiConsumerFactory) {
-                factory = (RestApiConsumerFactory) comp;
+            if (comp instanceof RestApiConsumerFactory restApiConsumerFactory) 
{
+                factory = restApiConsumerFactory;
             } else {
                 comp = 
getCamelContext().getComponent(getConsumerComponentName());
-                if (comp instanceof RestApiConsumerFactory) {
-                    factory = (RestApiConsumerFactory) comp;
+                if (comp instanceof RestApiConsumerFactory 
restApiConsumerFactory) {
+                    factory = restApiConsumerFactory;
                 }
             }
 
@@ -238,8 +238,8 @@ public class RestApiEndpoint extends DefaultEndpoint {
         if (factory == null) {
             for (String name : getCamelContext().getComponentNames()) {
                 Component comp = getCamelContext().getComponent(name);
-                if (comp instanceof RestApiConsumerFactory) {
-                    factory = (RestApiConsumerFactory) comp;
+                if (comp instanceof RestApiConsumerFactory 
restApiConsumerFactory) {
+                    factory = restApiConsumerFactory;
                     cname = name;
                     break;
                 }
@@ -259,8 +259,8 @@ public class RestApiEndpoint extends DefaultEndpoint {
             String foundName = null;
             for (String name : DEFAULT_REST_API_CONSUMER_COMPONENTS) {
                 Object comp = getCamelContext().getComponent(name, true);
-                if (comp instanceof RestApiConsumerFactory) {
-                    found = (RestApiConsumerFactory) comp;
+                if (comp instanceof RestApiConsumerFactory 
restApiConsumerFactory) {
+                    found = restApiConsumerFactory;
                     foundName = name;
                     break;
                 }
diff --git 
a/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
 
b/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
index d50aaf315df..85dd209db94 100644
--- 
a/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
+++ 
b/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
@@ -343,13 +343,13 @@ public class RestEndpoint extends DefaultEndpoint {
         String pname = getProducerComponentName();
         if (pname != null) {
             Object comp = getCamelContext().getRegistry().lookupByName(pname);
-            if (comp instanceof RestProducerFactory) {
-                factory = (RestProducerFactory) comp;
+            if (comp instanceof RestProducerFactory restProducerFactory) {
+                factory = restProducerFactory;
             } else {
                 comp = setupComponent(getProducerComponentName(), 
getCamelContext(),
                         (Map<String, Object>) parameters.get("component"));
-                if (comp instanceof RestProducerFactory) {
-                    factory = (RestProducerFactory) comp;
+                if (comp instanceof RestProducerFactory restProducerFactory) {
+                    factory = restProducerFactory;
                 }
             }
 
@@ -366,8 +366,8 @@ public class RestEndpoint extends DefaultEndpoint {
         if (factory == null) {
             for (String name : getCamelContext().getComponentNames()) {
                 Component comp = setupComponent(name, getCamelContext(), 
(Map<String, Object>) parameters.get("component"));
-                if (comp instanceof RestProducerFactory) {
-                    factory = (RestProducerFactory) comp;
+                if (comp instanceof RestProducerFactory producerFactory) {
+                    factory = producerFactory;
                     pname = name;
                     break;
                 }
@@ -378,13 +378,13 @@ public class RestEndpoint extends DefaultEndpoint {
         if (pname == null && getConsumerComponentName() != null) {
             String cname = getConsumerComponentName();
             Object comp = getCamelContext().getRegistry().lookupByName(cname);
-            if (comp instanceof RestProducerFactory) {
-                factory = (RestProducerFactory) comp;
+            if (comp instanceof RestProducerFactory restProducerFactory) {
+                factory = restProducerFactory;
                 pname = cname;
             } else {
                 comp = setupComponent(cname, getCamelContext(), (Map<String, 
Object>) parameters.get("component"));
-                if (comp instanceof RestProducerFactory) {
-                    factory = (RestProducerFactory) comp;
+                if (comp instanceof RestProducerFactory restProducerFactory) {
+                    factory = restProducerFactory;
                     pname = cname;
                 }
             }
@@ -404,8 +404,8 @@ public class RestEndpoint extends DefaultEndpoint {
             String foundName = null;
             for (String name : DEFAULT_REST_PRODUCER_COMPONENTS) {
                 Object comp = setupComponent(name, getCamelContext(), 
(Map<String, Object>) parameters.get("component"));
-                if (comp instanceof RestProducerFactory) {
-                    found = (RestProducerFactory) comp;
+                if (comp instanceof RestProducerFactory restProducerFactory) {
+                    found = restProducerFactory;
                     foundName = name;
                     break;
                 }
@@ -451,12 +451,12 @@ public class RestEndpoint extends DefaultEndpoint {
         String cname = null;
         if (getConsumerComponentName() != null) {
             Object comp = 
getCamelContext().getRegistry().lookupByName(getConsumerComponentName());
-            if (comp instanceof RestConsumerFactory) {
-                factory = (RestConsumerFactory) comp;
+            if (comp instanceof RestConsumerFactory restConsumerFactory) {
+                factory = restConsumerFactory;
             } else {
                 comp = 
getCamelContext().getComponent(getConsumerComponentName());
-                if (comp instanceof RestConsumerFactory) {
-                    factory = (RestConsumerFactory) comp;
+                if (comp instanceof RestConsumerFactory restConsumerFactory) {
+                    factory = restConsumerFactory;
                 }
             }
 
@@ -475,8 +475,8 @@ public class RestEndpoint extends DefaultEndpoint {
         if (factory == null) {
             for (String name : getCamelContext().getComponentNames()) {
                 Component comp = getCamelContext().getComponent(name);
-                if (comp instanceof RestConsumerFactory) {
-                    factory = (RestConsumerFactory) comp;
+                if (comp instanceof RestConsumerFactory restConsumerFactory) {
+                    factory = restConsumerFactory;
                     cname = name;
                     break;
                 }
@@ -486,8 +486,8 @@ public class RestEndpoint extends DefaultEndpoint {
         // favour using platform-http if available on classpath
         if (factory == null) {
             Object comp = getCamelContext().getComponent("platform-http", 
true);
-            if (comp instanceof RestConsumerFactory) {
-                factory = (RestConsumerFactory) comp;
+            if (comp instanceof RestConsumerFactory restConsumerFactory) {
+                factory = restConsumerFactory;
                 LOG.debug("Auto discovered platform-http as 
RestConsumerFactory");
             }
         }
@@ -506,8 +506,8 @@ public class RestEndpoint extends DefaultEndpoint {
             String foundName = null;
             for (String name : DEFAULT_REST_CONSUMER_COMPONENTS) {
                 Object comp = getCamelContext().getComponent(name, true);
-                if (comp instanceof RestConsumerFactory) {
-                    found = (RestConsumerFactory) comp;
+                if (comp instanceof RestConsumerFactory restConsumerFactory) {
+                    found = restConsumerFactory;
                     foundName = name;
                     break;
                 }
diff --git 
a/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestProducerBindingProcessor.java
 
b/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestProducerBindingProcessor.java
index 3703917668d..4eba8c7f8ee 100644
--- 
a/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestProducerBindingProcessor.java
+++ 
b/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestProducerBindingProcessor.java
@@ -98,17 +98,17 @@ public class RestProducerBindingProcessor extends 
DelegateAsyncProcessor {
     @Override
     protected void doStart() throws Exception {
         // inject CamelContext before starting
-        if (jsonMarshal instanceof CamelContextAware) {
-            ((CamelContextAware) jsonMarshal).setCamelContext(camelContext);
+        if (jsonMarshal instanceof CamelContextAware camelContextAware) {
+            camelContextAware.setCamelContext(camelContext);
         }
-        if (jsonUnmarshal instanceof CamelContextAware) {
-            ((CamelContextAware) jsonUnmarshal).setCamelContext(camelContext);
+        if (jsonUnmarshal instanceof CamelContextAware camelContextAware) {
+            camelContextAware.setCamelContext(camelContext);
         }
-        if (xmlMarshal instanceof CamelContextAware) {
-            ((CamelContextAware) xmlMarshal).setCamelContext(camelContext);
+        if (xmlMarshal instanceof CamelContextAware camelContextAware) {
+            camelContextAware.setCamelContext(camelContext);
         }
-        if (xmlUnmarshal instanceof CamelContextAware) {
-            ((CamelContextAware) xmlUnmarshal).setCamelContext(camelContext);
+        if (xmlUnmarshal instanceof CamelContextAware camelContextAware) {
+            camelContextAware.setCamelContext(camelContext);
         }
         ServiceHelper.startService(jsonMarshal, jsonUnmarshal, xmlMarshal, 
xmlUnmarshal);
     }

Reply via email to