1
1
/*
2
- * Copyright 2014 the original author or authors.
2
+ * Copyright 2014-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
17
17
18
18
import java .lang .annotation .Annotation ;
19
19
import java .lang .reflect .Method ;
20
- import java .util .HashSet ;
20
+ import java .util .Arrays ;
21
21
import java .util .Set ;
22
+ import java .util .stream .Collectors ;
22
23
23
24
import org .springframework .core .annotation .AnnotationUtils ;
24
25
25
26
/**
26
- * Provides reflection based utilities for Spring Batch that are not available via Spring
27
- * Core
27
+ * Provides reflection based utilities for Spring Batch that are not available in Spring
28
+ * Framework.
28
29
*
29
30
* @author Michael Minella
31
+ * @author Mahmoud Ben Hassine
30
32
* @since 2.2.6
31
33
*/
32
34
public class ReflectionUtils {
@@ -42,21 +44,10 @@ private ReflectionUtils() {
42
44
* @return a set of {@link java.lang.reflect.Method} instances if any are found, an
43
45
* empty set if not.
44
46
*/
45
- @ SuppressWarnings ("rawtypes" )
46
- public static final Set <Method > findMethod (Class clazz , Class <? extends Annotation > annotationType ) {
47
-
48
- Method [] declaredMethods = org .springframework .util .ReflectionUtils .getAllDeclaredMethods (clazz );
49
- Set <Method > results = new HashSet <>();
50
-
51
- for (Method curMethod : declaredMethods ) {
52
- Annotation annotation = AnnotationUtils .findAnnotation (curMethod , annotationType );
53
-
54
- if (annotation != null ) {
55
- results .add (curMethod );
56
- }
57
- }
58
-
59
- return results ;
47
+ public static Set <Method > findMethod (Class <?> clazz , Class <? extends Annotation > annotationType ) {
48
+ return Arrays .stream (org .springframework .util .ReflectionUtils .getAllDeclaredMethods (clazz ))
49
+ .filter (method -> AnnotationUtils .findAnnotation (method , annotationType ) != null )
50
+ .collect (Collectors .toSet ());
60
51
}
61
52
62
53
}
0 commit comments