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 870df22726 Utility class modernization
870df22726 is described below
commit 870df227269d48e448beb268779d9bf3ed3716e2
Author: James Bognar <[email protected]>
AuthorDate: Tue Nov 4 08:12:39 2025 -0500
Utility class modernization
---
.../juneau/common/reflect/ParameterInfo.java | 31 +++-------------------
.../org/apache/juneau/httppart/HttpPartSchema.java | 2 +-
.../juneau/common/reflect/ParamInfoTest.java | 4 +--
.../org/apache/juneau/reflect/ParamInfoTest.java | 4 +--
4 files changed, 7 insertions(+), 34 deletions(-)
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ParameterInfo.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ParameterInfo.java
index 65fdd3e109..134a149066 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ParameterInfo.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ParameterInfo.java
@@ -25,6 +25,7 @@ import java.lang.annotation.*;
import java.lang.reflect.*;
import java.util.*;
import java.util.function.*;
+import java.util.stream.*;
import org.apache.juneau.common.collections.*;
@@ -78,19 +79,6 @@ public class ParameterInfo extends ElementInfo implements
Annotatable {
return stream(parameter.getAnnotations()).map(a ->
AnnotationInfo.of(this, a)).toList();
}
- /**
- * Performs an action on this object if the specified predicate test
passes.
- *
- * @param test A test to apply to determine if action should be
executed. Can be <jk>null</jk>.
- * @param action An action to perform on this object.
- * @return This object.
- */
- public ParameterInfo accept(Predicate<ParameterInfo> test,
Consumer<ParameterInfo> action) {
- if (matches(test))
- action.accept(this);
- return this;
- }
-
/**
* Returns <jk>true</jk> if this parameter can accept the specified
value.
*
@@ -120,20 +108,9 @@ public class ParameterInfo extends ElementInfo implements
Annotatable {
return forEachAnnotation(AnnotationProvider.DEFAULT, type,
filter, action);
}
- /**
- * Performs an action on all matching annotations declared on this
parameter.
- *
- * @param <A> The annotation type to look for.
- * @param type The annotation type to look for.
- * @param filter A predicate to apply to the entries to determine if
action should be performed. Can be <jk>null</jk>.
- * @param action An action to perform on the entry.
- * @return This object.
- */
- public <A extends Annotation> ParameterInfo
forEachDeclaredAnnotation(Class<A> type, Predicate<A> filter, Consumer<A>
action) {
- for (var a : getAnnotations())
- if (type.isInstance(a))
- consumeIf(filter, action, type.cast(a));
- return this;
+ @SuppressWarnings("unchecked")
+ public <A extends Annotation> Stream<AnnotationInfo<A>>
getAnnotations(Class<A> type) {
+ return getAnnotationInfos().stream().filter(x ->
x.isType(type)).map(x -> (AnnotationInfo<A>)x);
}
/**
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/HttpPartSchema.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/HttpPartSchema.java
index 4f46ebf85e..f10406a68e 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/HttpPartSchema.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/HttpPartSchema.java
@@ -2564,7 +2564,7 @@ public class HttpPartSchema {
Builder apply(Class<? extends Annotation> c, ParameterInfo mpi)
{
apply(c, mpi.getParameterType().innerType());
- mpi.forEachDeclaredAnnotation(c, x -> true,
this::apply);
+ mpi.getAnnotations(c).forEach(x -> apply(x.inner()));
return this;
}
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/common/reflect/ParamInfoTest.java
b/juneau-utest/src/test/java/org/apache/juneau/common/reflect/ParamInfoTest.java
index c3b11428a9..fddaf49920 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/common/reflect/ParamInfoTest.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/common/reflect/ParamInfoTest.java
@@ -186,9 +186,7 @@ class ParamInfoTest extends TestBase {
}
private static <T extends Annotation> List<T>
declaredAnnotations(ParameterInfo pi, Class<T> type) {
- var l = new ArrayList<T>();
- pi.forEachDeclaredAnnotation(type, x -> true, l::add);
- return l;
+ return pi.getAnnotations(type).map(x -> x.inner()).toList();
}
@Test void getDeclaredAnnotation() {
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/reflect/ParamInfoTest.java
b/juneau-utest/src/test/java/org/apache/juneau/reflect/ParamInfoTest.java
index a5d06dc50b..92728b6700 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/reflect/ParamInfoTest.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/reflect/ParamInfoTest.java
@@ -187,9 +187,7 @@ class ParamInfoTest extends TestBase {
}
private static <T extends Annotation> List<T>
declaredAnnotations(ParameterInfo pi, Class<T> type) {
- var l = new ArrayList<T>();
- pi.forEachDeclaredAnnotation(type, x -> true, l::add);
- return l;
+ return pi.getAnnotations(type).map(x -> x.inner()).toList();
}
@Test void getDeclaredAnnotation() {