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 21011f6a25 Utility class modernization
21011f6a25 is described below
commit 21011f6a25dfdf9c34f29f6c19fc951a615a17f2
Author: James Bognar <[email protected]>
AuthorDate: Wed Nov 5 08:53:53 2025 -0500
Utility class modernization
---
.../juneau/common/reflect/AnnotationInfo.java | 51 +++++++++-------------
.../apache/juneau/common/reflect/ClassInfo.java | 10 -----
.../juneau/common/reflect/ConstructorInfo.java | 11 -----
.../apache/juneau/common/reflect/FieldInfo.java | 10 -----
.../apache/juneau/common/reflect/MethodInfo.java | 23 ----------
.../juneau/common/reflect/ParameterInfo.java | 11 -----
.../src/main/java/org/apache/juneau/Context.java | 2 +-
7 files changed, 21 insertions(+), 97 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 283ae8dd2e..b001a29ef0 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
@@ -70,19 +70,6 @@ public class AnnotationInfo<T extends Annotation> {
this.rank = findRank(a);
}
- /**
- * 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 AnnotationInfo<?> accept(Predicate<AnnotationInfo<?>> test,
Consumer<AnnotationInfo<?>> action) {
- if (matches(test))
- action.accept(this);
- return this;
- }
-
/**
* Performs an action on all matching values on this annotation.
*
@@ -169,16 +156,6 @@ public class AnnotationInfo<T extends Annotation> {
return this.a.annotationType() == type;
}
- /**
- * Returns <jk>true</jk> if this object passes the specified predicate
test.
- *
- * @param test The test to perform.
- * @return <jk>true</jk> if this object passes the specified predicate
test.
- */
- public boolean matches(Predicate<AnnotationInfo<?>> test) {
- return test(test, this);
- }
-
/**
* Converts this object to a readable map for debugging purposes.
*
@@ -308,17 +285,24 @@ public class AnnotationInfo<T extends Annotation> {
var pi = classInfo.getPackage();
if (nn(pi))
for (var ai : pi.getAnnotations())
- ai.accept(filter, action);
+ if (filter == null || filter.test(ai))
+ action.accept(ai);
var interfaces = classInfo.getInterfaces();
for (int i = interfaces.size() - 1; i >= 0; i--)
for (var a :
interfaces.get(i).inner().getDeclaredAnnotations())
- for (var a2 : splitRepeated(a))
- AnnotationInfo.of(interfaces.get(i),
a2).accept(filter, action);
+ for (var a2 : splitRepeated(a)) {
+ var ai =
AnnotationInfo.of(interfaces.get(i), a2);
+ if (filter == null || filter.test(ai))
+ action.accept(ai);
+ }
var parents = classInfo.getParents();
for (int i = parents.size() - 1; i >= 0; i--)
for (var a :
parents.get(i).inner().getDeclaredAnnotations())
- for (var a2 : splitRepeated(a))
- AnnotationInfo.of(parents.get(i),
a2).accept(filter, action);
+ for (var a2 : splitRepeated(a)) {
+ var ai =
AnnotationInfo.of(parents.get(i), a2);
+ if (filter == null || filter.test(ai))
+ action.accept(ai);
+ }
}
/**
@@ -479,19 +463,24 @@ public class AnnotationInfo<T extends Annotation> {
private static void forEachDeclaredAnnotationInfo(ClassInfo ci,
Predicate<AnnotationInfo<?>> filter, Consumer<AnnotationInfo<?>> action) {
if (nn(ci))
for (var ai : ci.getDeclaredAnnotationInfos())
- ai.accept(filter, action);
+ if (filter == null || filter.test(ai))
+ action.accept(ai);
}
private static void forEachDeclaredAnnotationInfo(PackageInfo pi,
Predicate<AnnotationInfo<?>> filter, Consumer<AnnotationInfo<?>> action) {
if (nn(pi))
for (var ai : pi.getAnnotations())
- ai.accept(filter, action);
+ if (filter == null || filter.test(ai))
+ action.accept(ai);
}
private static void forEachDeclaredMethodAnnotationInfo(MethodInfo
methodInfo, ClassInfo ci, Predicate<AnnotationInfo<?>> filter,
Consumer<AnnotationInfo<?>> action) {
MethodInfo mi = methodInfo.findMatchingOnClass(ci);
if (nn(mi))
- mi.getDeclaredAnnotationInfos().forEach(ai ->
ai.accept(filter, action));
+ mi.getDeclaredAnnotationInfos().forEach(ai -> {
+ if (filter == null || filter.test(ai))
+ action.accept(ai);
+ });
}
/**
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ClassInfo.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ClassInfo.java
index 91fda7a635..34d8292c16 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ClassInfo.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ClassInfo.java
@@ -2347,16 +2347,6 @@ public class ClassInfo extends ElementInfo implements
Annotatable {
return lastAnnotation(null, type, filter);
}
- /**
- * Returns <jk>true</jk> if this object passes the specified predicate
test.
- *
- * @param test The test to perform.
- * @return <jk>true</jk> if this object passes the specified predicate
test.
- */
- public boolean matches(Predicate<ClassInfo> test) {
- return test(test, this);
- }
-
/**
* Shortcut for calling
<c>Class.getDeclaredConstructor().newInstance()</c> on the underlying class.
*
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ConstructorInfo.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ConstructorInfo.java
index 52c5df832c..5e66ab1873 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ConstructorInfo.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ConstructorInfo.java
@@ -207,17 +207,6 @@ public class ConstructorInfo extends ExecutableInfo
implements Comparable<Constr
public <T> T newInstanceFuzzy(Object...args) throws ExecutableException
{
return
newInstance(ClassUtils.getMatchingArgs(c.getParameterTypes(), args));
}
-
- /**
- * Returns <jk>true</jk> if this object passes the specified predicate
test.
- *
- * @param test The test to perform.
- * @return <jk>true</jk> if this object passes the specified predicate
test.
- */
- public boolean matches(Predicate<ConstructorInfo> test) {
- return test(test, this);
- }
-
//-----------------------------------------------------------------------------------------------------------------
// Annotatable interface methods
//-----------------------------------------------------------------------------------------------------------------
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/FieldInfo.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/FieldInfo.java
index 2ccaccf821..4acdc3dc3f 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/FieldInfo.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/FieldInfo.java
@@ -357,16 +357,6 @@ public class FieldInfo extends AccessibleInfo implements
Comparable<FieldInfo>,
return v.isVisible(f);
}
- /**
- * Returns <jk>true</jk> if this object passes the specified predicate
test.
- *
- * @param test The test to perform.
- * @return <jk>true</jk> if this object passes the specified predicate
test.
- */
- public boolean matches(Predicate<FieldInfo> test) {
- return test(test, this);
- }
-
/**
* Sets the field value on the specified object.
*
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 eabca7bb79..bccffcc565 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
@@ -182,19 +182,6 @@ public class MethodInfo extends ExecutableInfo implements
Comparable<MethodInfo>
.forEach(pi -> addMatchingMethodsFromInterface(result,
pi));
}
- /**
- * 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 MethodInfo accept(Predicate<MethodInfo> test,
Consumer<MethodInfo> action) {
- if (matches(test))
- action.accept(this);
- return this;
- }
-
@Override /* Overridden from ExecutableInfo */
public MethodInfo accessible() {
super.accessible();
@@ -761,16 +748,6 @@ public class MethodInfo extends ExecutableInfo implements
Comparable<MethodInfo>
*/
public boolean isBridge() { return m.isBridge(); }
- /**
- * Returns <jk>true</jk> if this object passes the specified predicate
test.
- *
- * @param test The test to perform.
- * @return <jk>true</jk> if this object passes the specified predicate
test.
- */
- public boolean matches(Predicate<MethodInfo> test) {
- return test(test, this);
- }
-
/**
* Returns <jk>true</jk> if this method matches the specified method by
name and parameter types.
*
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 e2c6b5e808..0fac6f5522 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
@@ -434,17 +434,6 @@ public class ParameterInfo extends ElementInfo implements
Annotatable {
public boolean isType(Class<?> c) {
return getParameterType().is(c);
}
-
- /**
- * Returns <jk>true</jk> if this object passes the specified predicate
test.
- *
- * @param test The test to perform.
- * @return <jk>true</jk> if this object passes the specified predicate
test.
- */
- public boolean matches(Predicate<ParameterInfo> test) {
- return test(test, this);
- }
-
//-----------------------------------------------------------------------------------------------------------------
// High Priority Methods (direct Parameter API compatibility)
//-----------------------------------------------------------------------------------------------------------------
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Context.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Context.java
index 62baaa93c3..2011d50a82 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Context.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Context.java
@@ -730,7 +730,7 @@ public abstract class Context implements AnnotationProvider
{
if (mi == null) {
var c = ClassInfo.of(type);
for (var ci : c.getPublicConstructors()) {
- if (ci.matches(x ->
x.hasNumParameters(1) && ! x.getParameter(0).getParameterType().is(type))) {
+ if (ci.hasNumParameters(1) && !
ci.getParameter(0).getParameterType().is(type)) {
// @formatter:off
mi = c.getPublicMethod(
x -> x.isStatic()