camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From astefanu...@apache.org
Subject camel git commit: Camel CDI: better use of Java 8 functional API
Date Wed, 23 Nov 2016 10:56:52 GMT
Repository: camel
Updated Branches:
  refs/heads/master 662dd8f99 -> a37b24de0


Camel CDI: better use of Java 8 functional API


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a37b24de
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a37b24de
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a37b24de

Branch: refs/heads/master
Commit: a37b24de01744280dea902e6c973a7a535140ba4
Parents: 662dd8f
Author: Antonin Stefanutti <antonin@stefanutti.fr>
Authored: Wed Nov 23 11:56:41 2016 +0100
Committer: Antonin Stefanutti <antonin@stefanutti.fr>
Committed: Wed Nov 23 11:56:41 2016 +0100

----------------------------------------------------------------------
 .../org/apache/camel/cdi/AnnotatedDelegate.java     |  5 +----
 .../org/apache/camel/cdi/CdiCamelEnvironment.java   |  4 +---
 .../org/apache/camel/cdi/CdiCamelExtension.java     | 16 +++++-----------
 .../java/org/apache/camel/cdi/CdiSpiHelper.java     |  6 ++----
 .../org/apache/camel/cdi/SyntheticAnnotated.java    |  5 +----
 5 files changed, 10 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a37b24de/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnnotatedDelegate.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnnotatedDelegate.java
b/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnnotatedDelegate.java
index c9c9777..53f3d0e 100644
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnnotatedDelegate.java
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnnotatedDelegate.java
@@ -66,10 +66,7 @@ class AnnotatedDelegate implements Annotated {
 
     @Override
     public boolean isAnnotationPresent(Class<? extends Annotation> type) {
-        return annotations.stream()
-            .filter(isAnnotationType(type))
-            .findAny()
-            .isPresent();
+        return annotations.stream().anyMatch(isAnnotationType(type));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/a37b24de/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelEnvironment.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelEnvironment.java
b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelEnvironment.java
index 3aabe6f..feb38df 100644
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelEnvironment.java
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelEnvironment.java
@@ -47,9 +47,7 @@ final class CdiCamelEnvironment {
         try {
             getClassLoader(CdiCamelExtension.class).loadClass("org.apache.camel.core.osgi.OsgiCamelContextHelper");
             return true;
-        } catch (ClassNotFoundException cause) {
-            return false;
-        } catch (NoClassDefFoundError cause) {
+        } catch (ClassNotFoundException | NoClassDefFoundError cause) {
             return false;
         }
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/a37b24de/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelExtension.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelExtension.java
b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelExtension.java
index f4bb9bb..e16ec42 100755
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelExtension.java
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelExtension.java
@@ -208,7 +208,7 @@ public class CdiCamelExtension implements Extension {
             if (qualifiers.isEmpty()) {
                 eventQualifiers.add(ANY);
             } else if (qualifiers.size() == 1 && qualifiers.stream()
-                .filter(isAnnotationType(Named.class)).findAny().isPresent()) {
+                .anyMatch(isAnnotationType(Named.class))) {
                 eventQualifiers.add(DEFAULT);
             } else {
                 eventQualifiers.addAll(qualifiers);
@@ -333,22 +333,18 @@ public class CdiCamelExtension implements Extension {
                 .or(hasType(RouteContainer.class).or(hasType(RoutesBuilder.class))))
             .map(Bean::getQualifiers)
             .flatMap(Set::stream)
-            .filter(isEqual(DEFAULT))
-            .findAny()
-            .isPresent()
+            .anyMatch(isEqual(DEFAULT))
             // Or a bean with Camel annotations?
             || concat(camelBeans.stream().map(AnnotatedType::getFields),
                       camelBeans.stream().map(AnnotatedType::getMethods))
             .flatMap(Set::stream)
             .map(Annotated::getAnnotations)
             .flatMap(Set::stream)
-            .filter(isAnnotationType(Consume.class).and(a -> ((Consume) a).context().isEmpty())
+            .anyMatch(isAnnotationType(Consume.class).and(a -> ((Consume) a).context().isEmpty())
                 .or(isAnnotationType(BeanInject.class).and(a -> ((BeanInject) a).context().isEmpty()))
                 .or(isAnnotationType(EndpointInject.class).and(a -> ((EndpointInject)
a).context().isEmpty()))
                 .or(isAnnotationType(Produce.class).and(a -> ((Produce) a).context().isEmpty()))
                 .or(isAnnotationType(PropertyInject.class).and(a -> ((PropertyInject)
a).context().isEmpty())))
-            .findAny()
-            .isPresent()
             // Or an injection point for Camel primitives?
             || beans.stream()
             // Excluding internal components...
@@ -358,9 +354,7 @@ public class CdiCamelExtension implements Extension {
             .filter(ip -> getRawType(ip.getType()).getName().startsWith("org.apache.camel"))
             .map(InjectionPoint::getQualifiers)
             .flatMap(Set::stream)
-            .filter(isAnnotationType(Uri.class).or(isAnnotationType(Mock.class)).or(isEqual(DEFAULT)))
-            .findAny()
-            .isPresent();
+            .anyMatch(isAnnotationType(Uri.class).or(isAnnotationType(Mock.class)).or(isEqual(DEFAULT)));
     }
 
     private SyntheticBean<?> camelContextBean(BeanManager manager, Annotation... qualifiers)
{
@@ -409,7 +403,7 @@ public class CdiCamelExtension implements Extension {
         // FIXME: This does not work with OpenWebBeans for bean whose bean type is an
         // interface as the Object methods does not get forwarded to the bean instances!
         eagerBeans.forEach(type -> getReferencesByType(manager, type.getJavaClass(), ANY).toString());
-        manager.getBeans(Object.class, ANY, STARTUP).stream()
+        manager.getBeans(Object.class, ANY, STARTUP)
             .forEach(bean -> getReference(manager, bean.getBeanClass(), bean).toString());
 
         // Start Camel contexts

http://git-wip-us.apache.org/repos/asf/camel/blob/a37b24de/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiSpiHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiSpiHelper.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiSpiHelper.java
index 5071719..a69a1d8 100644
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiSpiHelper.java
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiSpiHelper.java
@@ -97,9 +97,7 @@ final class CdiSpiHelper {
     @SafeVarargs
     static boolean hasAnnotation(AnnotatedType<?> type, Class<? extends Annotation>...
annotations) {
         return Stream.of(annotations)
-            .filter(annotation -> hasAnnotation(type, annotation))
-            .findAny()
-            .isPresent();
+            .anyMatch(annotation -> hasAnnotation(type, annotation));
     }
 
     static boolean hasAnnotation(AnnotatedType<?> type, Class<? extends Annotation>
annotation) {
@@ -195,7 +193,7 @@ final class CdiSpiHelper {
         }
 
         return annotations.stream()
-            .sorted((a1, a2) -> a1.annotationType().getName().compareTo(a2.annotationType().getName()))
+            .sorted(comparing(a -> a.annotationType().getName()))
             .map(CdiSpiHelper::createAnnotationId)
             .collect(joining(",", "[", "]"));
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/a37b24de/components/camel-cdi/src/main/java/org/apache/camel/cdi/SyntheticAnnotated.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/SyntheticAnnotated.java
b/components/camel-cdi/src/main/java/org/apache/camel/cdi/SyntheticAnnotated.java
index 679a8b8..0faafde 100644
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/SyntheticAnnotated.java
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/SyntheticAnnotated.java
@@ -78,9 +78,6 @@ final class SyntheticAnnotated implements Annotated {
 
     @Override
     public boolean isAnnotationPresent(Class<? extends Annotation> type) {
-        return annotations.stream()
-            .filter(isAnnotationType(type))
-            .findAny()
-            .isPresent();
+        return annotations.stream().anyMatch(isAnnotationType(type));
     }
 }


Mime
View raw message