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

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


The following commit(s) were added to refs/heads/master by this push:
     new dc8c20d  Use lambda
dc8c20d is described below

commit dc8c20d12ffe3a15187980b88f3df7face738500
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Wed Jul 17 11:32:55 2019 +0200

    Use lambda
---
 .../impl/engine/DefaultCamelBeanPostProcessor.java | 72 ++++++++++------------
 .../org/apache/camel/util/ReflectionHelper.java    |  3 +
 2 files changed, 35 insertions(+), 40 deletions(-)

diff --git 
a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultCamelBeanPostProcessor.java
 
b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultCamelBeanPostProcessor.java
index 72019f7..ade05e4 100644
--- 
a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultCamelBeanPostProcessor.java
+++ 
b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultCamelBeanPostProcessor.java
@@ -162,42 +162,38 @@ public class DefaultCamelBeanPostProcessor implements 
CamelBeanPostProcessor {
      * @param bean the bean to be injected
      */
     protected void injectFields(final Object bean, final String beanName) {
-        ReflectionHelper.doWithFields(bean.getClass(), new 
ReflectionHelper.FieldCallback() {
-            public void doWith(Field field) throws IllegalArgumentException, 
IllegalAccessException {
-                PropertyInject propertyInject = 
field.getAnnotation(PropertyInject.class);
-                if (propertyInject != null && 
getPostProcessorHelper().matchContext(propertyInject.context())) {
-                    injectFieldProperty(field, propertyInject.value(), 
propertyInject.defaultValue(), bean, beanName);
-                }
+        ReflectionHelper.doWithFields(bean.getClass(), field -> {
+            PropertyInject propertyInject = 
field.getAnnotation(PropertyInject.class);
+            if (propertyInject != null && 
getPostProcessorHelper().matchContext(propertyInject.context())) {
+                injectFieldProperty(field, propertyInject.value(), 
propertyInject.defaultValue(), bean, beanName);
+            }
 
-                BeanInject beanInject = field.getAnnotation(BeanInject.class);
-                if (beanInject != null && 
getPostProcessorHelper().matchContext(beanInject.context())) {
-                    injectFieldBean(field, beanInject.value(), bean, beanName);
-                }
+            BeanInject beanInject = field.getAnnotation(BeanInject.class);
+            if (beanInject != null && 
getPostProcessorHelper().matchContext(beanInject.context())) {
+                injectFieldBean(field, beanInject.value(), bean, beanName);
+            }
 
-                EndpointInject endpointInject = 
field.getAnnotation(EndpointInject.class);
-                if (endpointInject != null && 
getPostProcessorHelper().matchContext(endpointInject.context())) {
-                    @SuppressWarnings("deprecation")
-                    String uri = endpointInject.value().isEmpty() ? 
endpointInject.uri() : endpointInject.value();
-                    injectField(field, uri, endpointInject.property(), bean, 
beanName);
-                }
+            EndpointInject endpointInject = 
field.getAnnotation(EndpointInject.class);
+            if (endpointInject != null && 
getPostProcessorHelper().matchContext(endpointInject.context())) {
+                @SuppressWarnings("deprecation")
+                String uri = endpointInject.value().isEmpty() ? 
endpointInject.uri() : endpointInject.value();
+                injectField(field, uri, endpointInject.property(), bean, 
beanName);
+            }
 
-                Produce produce = field.getAnnotation(Produce.class);
-                if (produce != null && 
getPostProcessorHelper().matchContext(produce.context())) {
-                    @SuppressWarnings("deprecation")
-                    String uri = produce.value().isEmpty() ? produce.uri() : 
produce.value();
-                    injectField(field, uri, produce.property(), bean, 
beanName, produce.binding());
-                }
+            Produce produce = field.getAnnotation(Produce.class);
+            if (produce != null && 
getPostProcessorHelper().matchContext(produce.context())) {
+                @SuppressWarnings("deprecation")
+                String uri = produce.value().isEmpty() ? produce.uri() : 
produce.value();
+                injectField(field, uri, produce.property(), bean, beanName, 
produce.binding());
             }
         });
     }
 
     protected void injectBindToRegistryFields(final Object bean, final String 
beanName) {
-        ReflectionHelper.doWithFields(bean.getClass(), new 
ReflectionHelper.FieldCallback() {
-            public void doWith(Field field) throws IllegalArgumentException, 
IllegalAccessException {
-                BindToRegistry bind = 
field.getAnnotation(BindToRegistry.class);
-                if (bind != null && 
getPostProcessorHelper().matchContext(bind.context())) {
-                    bindToRegistry(field, bind.value(), bean, beanName, 
bind.beanPostProcess());
-                }
+        ReflectionHelper.doWithFields(bean.getClass(), field -> {
+            BindToRegistry bind = field.getAnnotation(BindToRegistry.class);
+            if (bind != null && 
getPostProcessorHelper().matchContext(bind.context())) {
+                bindToRegistry(field, bind.value(), bean, beanName, 
bind.beanPostProcess());
             }
         });
     }
@@ -226,11 +222,9 @@ public class DefaultCamelBeanPostProcessor implements 
CamelBeanPostProcessor {
     }
 
     protected void injectMethods(final Object bean, final String beanName) {
-        ReflectionHelper.doWithMethods(bean.getClass(), new 
ReflectionHelper.MethodCallback() {
-            public void doWith(Method method) throws IllegalArgumentException, 
IllegalAccessException {
-                setterInjection(method, bean, beanName);
-                getPostProcessorHelper().consumerInjection(method, bean, 
beanName);
-            }
+        ReflectionHelper.doWithMethods(bean.getClass(), method -> {
+            setterInjection(method, bean, beanName);
+            getPostProcessorHelper().consumerInjection(method, bean, beanName);
         });
     }
 
@@ -292,13 +286,11 @@ public class DefaultCamelBeanPostProcessor implements 
CamelBeanPostProcessor {
     }
 
     protected void injectNestedClasses(final Object bean, final String 
beanName) {
-        ReflectionHelper.doWithClasses(bean.getClass(), new 
ReflectionHelper.ClassCallback() {
-            public void doWith(Class clazz) throws IllegalArgumentException, 
IllegalAccessException {
-                BindToRegistry ann = (BindToRegistry) 
clazz.getAnnotation(BindToRegistry.class);
-                if (ann != null && 
getPostProcessorHelper().matchContext(ann.context())) {
-                    // its a nested class so we dont have a bean instance for 
it
-                    bindToRegistry(clazz, ann.value(), null, null, 
ann.beanPostProcess());
-                }
+        ReflectionHelper.doWithClasses(bean.getClass(), clazz -> {
+            BindToRegistry ann = (BindToRegistry) 
clazz.getAnnotation(BindToRegistry.class);
+            if (ann != null && 
getPostProcessorHelper().matchContext(ann.context())) {
+                // its a nested class so we dont have a bean instance for it
+                bindToRegistry(clazz, ann.value(), null, null, 
ann.beanPostProcess());
             }
         });
     }
diff --git 
a/core/camel-util/src/main/java/org/apache/camel/util/ReflectionHelper.java 
b/core/camel-util/src/main/java/org/apache/camel/util/ReflectionHelper.java
index 15ab434..b22f9d0 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/ReflectionHelper.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/ReflectionHelper.java
@@ -35,6 +35,7 @@ public final class ReflectionHelper {
     /**
      * Callback interface invoked on each field in the hierarchy.
      */
+    @FunctionalInterface
     public interface FieldCallback {
 
         /**
@@ -48,6 +49,7 @@ public final class ReflectionHelper {
     /**
      * Action to take on each method.
      */
+    @FunctionalInterface
     public interface MethodCallback {
 
         /**
@@ -61,6 +63,7 @@ public final class ReflectionHelper {
     /**
      * Action to take on each class.
      */
+    @FunctionalInterface
     public interface ClassCallback {
 
         /**

Reply via email to