Skip to content

Commit 3ec8fad

Browse files
committed
Added overloaded API to support Annotation arrays instead of collections
1 parent a3d876c commit 3ec8fad

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

src/main/java/org/bbottema/javareflection/TypeUtils.java

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,17 +298,36 @@ public static boolean containsAnnotation(List<Annotation> myListOfAnnotations, C
298298

299299
/**
300300
* @return Whether a given list of Annotation contains a certain annotation type.
301+
* @see #findAnnotation(Annotation[], Class)
301302
*/
302-
@SuppressWarnings({"WeakerAccess", "unchecked"})
303-
@Nullable
304-
public static <T extends Annotation> T findAnnotation(List<Annotation> myListOfAnnotations, Class<T> annotationClass) {
305-
for (Annotation annotation : myListOfAnnotations) {
306-
if (annotation.annotationType() == annotationClass) {
307-
return (T) annotation;
308-
}
309-
}
310-
return null;
303+
@SuppressWarnings("WeakerAccess")
304+
public static boolean containsAnnotation(Annotation[] myListOfAnnotations, Class<? extends Annotation> annotationClass) {
305+
return findAnnotation(myListOfAnnotations, annotationClass) != null;
311306
}
307+
308+
/**
309+
* @return Whether a given list of Annotation contains a certain annotation type.
310+
* @see #findAnnotation(Annotation[], Class)
311+
*/
312+
@SuppressWarnings({"WeakerAccess"})
313+
@Nullable
314+
public static <T extends Annotation> T findAnnotation(List<Annotation> myListOfAnnotations, Class<T> annotationClass) {
315+
return findAnnotation(myListOfAnnotations.toArray(new Annotation[0]), annotationClass);
316+
}
317+
318+
/**
319+
* @return Whether a given list of Annotation contains a certain annotation type.
320+
*/
321+
@SuppressWarnings({"WeakerAccess", "unchecked"})
322+
@Nullable
323+
public static <T extends Annotation> T findAnnotation(Annotation[] myListOfAnnotations, Class<T> annotationClass) {
324+
for (Annotation annotation : myListOfAnnotations) {
325+
if (annotation.annotationType() == annotationClass) {
326+
return (T) annotation;
327+
}
328+
}
329+
return null;
330+
}
312331

313332
/**
314333
* Shortcut helper method that replaces an item in an array and returns the array itself.

0 commit comments

Comments
 (0)