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

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


The following commit(s) were added to refs/heads/master by this push:
     new 893b77c92c Utility class modernization
893b77c92c is described below

commit 893b77c92ca9e593d5c3e5741c8698cebc2fe000
Author: James Bognar <[email protected]>
AuthorDate: Thu Nov 6 08:47:41 2025 -0500

    Utility class modernization
---
 .../juneau/common/reflect/AnnotationInfo.java      | 12 +++++++++++
 .../apache/juneau/common/reflect/MethodInfo.java   |  3 ++-
 .../apache/juneau/common/utils/PredicateUtils.java | 23 ++++++++--------------
 3 files changed, 22 insertions(+), 16 deletions(-)

diff --git 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/AnnotationInfo.java
 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/AnnotationInfo.java
index bf7d8f1023..01190f5137 100644
--- 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/AnnotationInfo.java
+++ 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/AnnotationInfo.java
@@ -113,6 +113,18 @@ public class AnnotationInfo<T extends Annotation> {
                        .findFirst();
        }
 
+       /**
+        * Casts this annotation info to a specific annotation type.
+        *
+        * @param <A> The annotation type to cast to.
+        * @param type The annotation type to cast to.
+        * @return This annotation info cast to the specified type, or 
<jk>null</jk> if the cast is not valid.
+        */
+       @SuppressWarnings("unchecked")
+       public <A extends Annotation> AnnotationInfo<A> cast(Class<A> type) {
+               return type.isInstance(a) ? (AnnotationInfo<A>)this : null;
+       }
+
        /**
         * Returns <jk>true</jk> if this annotation has the specified 
annotation defined on it.
         *
diff --git 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/MethodInfo.java
 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/MethodInfo.java
index 58c09768b0..793d8b280b 100644
--- 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/MethodInfo.java
+++ 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/MethodInfo.java
@@ -450,7 +450,8 @@ public class MethodInfo extends ExecutableInfo implements 
Comparable<MethodInfo>
         */
        public <A extends Annotation> Stream<AnnotationInfo<A>> 
getAllAnnotationInfosParentFirst(Class<A> type) {
                return rstream(getAllAnnotationInfos())
-                       .flatMap(type(type));
+                       .map(x -> x.cast(type))
+                       .filter(notNull());
        }
 
        public Stream<MethodInfo> getMatching() {
diff --git 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/PredicateUtils.java
 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/PredicateUtils.java
index abcddef974..c7b0ab65c4 100644
--- 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/PredicateUtils.java
+++ 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/PredicateUtils.java
@@ -245,27 +245,20 @@ public final class PredicateUtils {
        }
 
        /**
-        * Returns a function that filters and casts {@link AnnotationInfo} 
objects to a specific annotation type.
-        *
-        * <p>
-        * This function is designed to be used with {@link 
Stream#flatMap(Function)} to both filter and type-cast
-        * in a single operation.
+        * Returns a predicate that tests if an object is not null.
         *
         * <h5 class='section'>Example:</h5>
         * <p class='bjava'>
-        *      List&lt;AnnotationInfo&lt;Annotation&gt;&gt; annotations = ...;
-        *      List&lt;MyAnnotation&gt; myAnnotations = annotations.stream()
-        *              .flatMap(type(MyAnnotation.<jk>class</jk>))
-        *              .map(AnnotationInfo::inner)
+        *      List&lt;String&gt; strings = ...;
+        *      List&lt;String&gt; nonNullStrings = strings.stream()
+        *              .filter(notNull())
         *              .collect(Collectors.toList());
         * </p>
         *
-        * @param <A> The annotation type.
-        * @param annotationType The annotation class to filter and cast to.
-        * @return A function that returns a stream containing the annotation 
if it matches the type, or an empty stream otherwise.
+        * @param <T> The input type of the predicate.
+        * @return A predicate that returns {@code true} if the input is not 
null, {@code false} otherwise.
         */
-       @SuppressWarnings("unchecked")
-       public static <A extends Annotation> Function<AnnotationInfo<?>, 
Stream<AnnotationInfo<A>>> type(Class<A> annotationType) {
-               return ai -> ai.isType(annotationType) ? 
Stream.of((AnnotationInfo<A>)ai) : Stream.empty();
+       public static <T> Predicate<T> notNull() {
+               return t -> t != null;
        }
 }

Reply via email to