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 0cb5c6aac9 Utility class modernization
0cb5c6aac9 is described below

commit 0cb5c6aac9dee9618ea8744035a1f6df35a7b837
Author: James Bognar <[email protected]>
AuthorDate: Thu Nov 6 14:54:12 2025 -0500

    Utility class modernization
---
 .../apache/juneau/httppart/bean/ResponseBeanMeta.java  |  4 ++--
 .../main/java/org/apache/juneau/rest/RestContext.java  | 10 +++++-----
 .../rest/swagger/BasicSwaggerProviderSession.java      | 12 ++++++------
 .../apache/juneau/common/reflect/ClassInfo_Test.java   | 18 +++++++++---------
 4 files changed, 22 insertions(+), 22 deletions(-)

diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/bean/ResponseBeanMeta.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/bean/ResponseBeanMeta.java
index 13f5f9d20d..0dc372e62a 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/bean/ResponseBeanMeta.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/bean/ResponseBeanMeta.java
@@ -160,8 +160,8 @@ public class ResponseBeanMeta {
                        return null;
                var b = new Builder(annotations);
                b.apply(ci.innerType());
-               ci.forEachAnnotation(Response.class, x -> true, x -> 
b.apply(x));
-               ci.forEachAnnotation(StatusCode.class, x -> true, x -> 
b.apply(x));
+               rstream(ci.getAnnotationInfos()).map(x -> 
x.cast(Response.class)).filter(Objects::nonNull).map(AnnotationInfo::inner).forEach(x
 -> b.apply(x));
+               rstream(ci.getAnnotationInfos()).map(x -> 
x.cast(StatusCode.class)).filter(Objects::nonNull).map(AnnotationInfo::inner).forEach(x
 -> b.apply(x));
                return b.build();
        }
 
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
index cc7490f82f..05578dce4d 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
@@ -3851,7 +3851,7 @@ public class RestContext extends Context {
                        // @formatter:on
 
                        // Apply @Rest(beanStore).
-                       
ClassInfo.of(resourceClass).forEachAnnotation(Rest.class, x -> 
isNotVoid(x.beanStore()), x -> v.get().type(x.beanStore()));
+                       
rstream(ClassInfo.of(resourceClass).getAnnotationInfos()).map(x -> 
x.cast(Rest.class)).filter(Objects::nonNull).map(AnnotationInfo::inner).filter(x
 -> isNotVoid(x.beanStore())).forEach(x -> v.get().type(x.beanStore()));
 
                        // Replace with bean from:  @RestInject public [static] 
BeanStore xxx(<args>)
                        // @formatter:off
@@ -3913,10 +3913,10 @@ public class RestContext extends Context {
                        var v = Value.<Config>empty();
 
                        // Find our config file.  It's the last non-empty 
@RestResource(config).
-                       var vr = 
beanStore.getBean(VarResolver.class).orElseThrow(() -> new 
IllegalArgumentException("VarResolver not found."));
-                       var cfv = Value.<String>empty();
-                       
ClassInfo.of(resourceClass).forEachAnnotation(Rest.class, x -> 
isNotEmpty(x.config()), x -> cfv.set(vr.resolve(x.config())));
-                       var cf = cfv.orElse("");
+               var vr = beanStore.getBean(VarResolver.class).orElseThrow(() -> 
new IllegalArgumentException("VarResolver not found."));
+               var cfv = Value.<String>empty();
+               rstream(ClassInfo.of(resourceClass).getAnnotationInfos()).map(x 
-> 
x.cast(Rest.class)).filter(Objects::nonNull).map(AnnotationInfo::inner).filter(x
 -> isNotEmpty(x.config())).forEach(x -> cfv.set(vr.resolve(x.config())));
+               var cf = cfv.orElse("");
 
                        // If not specified or value is set to SYSTEM_DEFAULT, 
use system default config.
                        if (v.isEmpty() && "SYSTEM_DEFAULT".equals(cf))
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
index 5fec4c1807..1e1fb50b0e 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
@@ -440,7 +440,7 @@ public class BasicSwaggerProviderSession {
                                                        JsonMap om = 
responses.getMap(String.valueOf(code), true);
                                                        merge(om, a);
                                                        JsonMap schema = 
getSchema(om.getMap("schema"), m.getGenericReturnType(), bs);
-                                                       
eci.forEachAnnotation(Schema.class, x -> true, x -> merge(schema, x));
+                                                       
rstream(eci.getAnnotationInfos()).map(x -> 
x.cast(Schema.class)).filter(Objects::nonNull).map(AnnotationInfo::inner).forEach(x
 -> merge(schema, x));
                                                        
pushupSchemaFields(RESPONSE, om, schema);
                                                        om.appendIf(nem, 
"schema", schema);
                                                }
@@ -504,7 +504,7 @@ public class BasicSwaggerProviderSession {
                                JsonMap om = responses.getMap("200", true);
                                var pt2 = 
ClassInfo.of(m.getGenericReturnType());
                                JsonMap schema = getSchema(om.getMap("schema"), 
m.getGenericReturnType(), bs);
-                               pt2.forEachAnnotation(Schema.class, x -> true, 
x -> merge(schema, x));
+                               rstream(pt2.getAnnotationInfos()).map(x -> 
x.cast(Schema.class)).filter(Objects::nonNull).map(AnnotationInfo::inner).forEach(x
 -> merge(schema, x));
                                pushupSchemaFields(RESPONSE, om, schema);
                                om.appendIf(nem, "schema", schema);
                                addBodyExamples(sm, om, true, 
m.getGenericReturnType(), locale);
@@ -518,10 +518,10 @@ public class BasicSwaggerProviderSession {
                                if (pt.is(Value.class) && 
(mpi.hasAnnotation(Header.class) || pt.hasAnnotation(Header.class))) {
                                        List<Header> la = list();
                                        mpi.forEachAnnotation(Header.class, x 
-> true, x -> la.add(x));
-                                       pt.forEachAnnotation(Header.class, x -> 
true, x -> la.add(x));
+                                       rstream(pt.getAnnotationInfos()).map(x 
-> 
x.cast(Header.class)).filter(Objects::nonNull).map(AnnotationInfo::inner).forEach(x
 -> la.add(x));
                                        List<StatusCode> la2 = list();
                                        mpi.forEachAnnotation(StatusCode.class, 
x -> true, x -> la2.add(x));
-                                       pt.forEachAnnotation(StatusCode.class, 
x -> true, x -> la2.add(x));
+                                       rstream(pt.getAnnotationInfos()).map(x 
-> 
x.cast(StatusCode.class)).filter(Objects::nonNull).map(AnnotationInfo::inner).forEach(x
 -> la2.add(x));
                                        Set<Integer> codes = getCodes(la2, 200);
                                        String name = 
HeaderAnnotation.findName(mpi).orElse(null);
                                        Type type = 
Value.unwrap(mpi.getParameterType().innerType());
@@ -539,10 +539,10 @@ public class BasicSwaggerProviderSession {
                                } else if (mpi.hasAnnotation(Response.class) || 
pt.hasAnnotation(Response.class)) {
                                        List<Response> la = list();
                                        mpi.forEachAnnotation(Response.class, x 
-> true, x -> la.add(x));
-                                       pt.forEachAnnotation(Response.class, x 
-> true, x -> la.add(x));
+                                       rstream(pt.getAnnotationInfos()).map(x 
-> 
x.cast(Response.class)).filter(Objects::nonNull).map(AnnotationInfo::inner).forEach(x
 -> la.add(x));
                                        List<StatusCode> la2 = list();
                                        mpi.forEachAnnotation(StatusCode.class, 
x -> true, x -> la2.add(x));
-                                       pt.forEachAnnotation(StatusCode.class, 
x -> true, x -> la2.add(x));
+                                       rstream(pt.getAnnotationInfos()).map(x 
-> 
x.cast(StatusCode.class)).filter(Objects::nonNull).map(AnnotationInfo::inner).forEach(x
 -> la2.add(x));
                                        Set<Integer> codes = getCodes(la2, 200);
                                        Type type = 
Value.unwrap(mpi.getParameterType().innerType());
                                        for (var a : la) {
diff --git 
a/juneau-utest/src/test/java/org/apache/juneau/common/reflect/ClassInfo_Test.java
 
b/juneau-utest/src/test/java/org/apache/juneau/common/reflect/ClassInfo_Test.java
index 11c3b88c7f..f96e899552 100644
--- 
a/juneau-utest/src/test/java/org/apache/juneau/common/reflect/ClassInfo_Test.java
+++ 
b/juneau-utest/src/test/java/org/apache/juneau/common/reflect/ClassInfo_Test.java
@@ -572,26 +572,26 @@ public class ClassInfo_Test extends TestBase {
        }
 
        @Test void getAnnotations() {
-               check("@A(2),@A(1),@A(5),@A(3),@A(6),@A(7)", 
rstream(g3.getAnnotationInfos(A.class).toList()).map(AnnotationInfo::inner).toList());
-               check("@A(2),@A(1),@A(5),@A(3),@A(6),@A(7)", 
rstream(g4.getAnnotationInfos(A.class).toList()).map(AnnotationInfo::inner).toList());
-               check("@A(3)", 
rstream(g5.getAnnotationInfos(A.class).toList()).map(AnnotationInfo::inner).toList());
+               check("@A(2),@A(1),@A(5),@A(3),@A(6),@A(7)", 
rstream(g3.getAnnotationInfos()).map(x -> 
x.cast(A.class)).filter(Objects::nonNull).map(AnnotationInfo::inner).toList());
+               check("@A(2),@A(1),@A(5),@A(3),@A(6),@A(7)", 
rstream(g4.getAnnotationInfos()).map(x -> 
x.cast(A.class)).filter(Objects::nonNull).map(AnnotationInfo::inner).toList());
+               check("@A(3)", rstream(g5.getAnnotationInfos()).map(x -> 
x.cast(A.class)).filter(Objects::nonNull).map(AnnotationInfo::inner).toList());
        }
 
        @Test void forEachAnnotation() {
                var l1 = list();
-               g3.forEachAnnotation(A.class, null, x -> l1.add(x.value()));
-               assertList(l1, "2", "1", "3", "5", "6", "7");
+               rstream(g3.getAnnotationInfos()).map(x -> 
x.cast(A.class)).filter(Objects::nonNull).map(AnnotationInfo::inner).forEach(x 
-> l1.add(x.value()));
+               assertList(l1, "2", "1", "5", "3", "6", "7");
 
                var l2 = list();
-               g4.forEachAnnotation(A.class, null, x -> l2.add(x.value()));
-               assertList(l2, "2", "1", "3", "5", "6", "7");
+               rstream(g4.getAnnotationInfos()).map(x -> 
x.cast(A.class)).filter(Objects::nonNull).map(AnnotationInfo::inner).forEach(x 
-> l2.add(x.value()));
+               assertList(l2, "2", "1", "5", "3", "6", "7");
 
                var l3 = list();
-               g5.forEachAnnotation(A.class, null, x -> l3.add(x.value()));
+               rstream(g5.getAnnotationInfos()).map(x -> 
x.cast(A.class)).filter(Objects::nonNull).map(AnnotationInfo::inner).forEach(x 
-> l3.add(x.value()));
                assertList(l3, "3");
 
                var l4 = list();
-               g3.forEachAnnotation(A.class, x -> x.value() == 5, x -> 
l4.add(x.value()));
+               rstream(g3.getAnnotationInfos()).map(x -> 
x.cast(A.class)).filter(Objects::nonNull).map(AnnotationInfo::inner).filter(x 
-> x.value() == 5).forEach(x -> l4.add(x.value()));
                assertList(l4, "5");
        }
 

Reply via email to