Skip to content

Commit e6e9c4e

Browse files
committed
Refactor ReflectionUtils
1 parent ee30af4 commit e6e9c4e

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2014-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,16 +17,18 @@
1717

1818
import java.lang.annotation.Annotation;
1919
import java.lang.reflect.Method;
20-
import java.util.HashSet;
20+
import java.util.Arrays;
2121
import java.util.Set;
22+
import java.util.stream.Collectors;
2223

2324
import org.springframework.core.annotation.AnnotationUtils;
2425

2526
/**
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.
2829
*
2930
* @author Michael Minella
31+
* @author Mahmoud Ben Hassine
3032
* @since 2.2.6
3133
*/
3234
public class ReflectionUtils {
@@ -42,21 +44,10 @@ private ReflectionUtils() {
4244
* @return a set of {@link java.lang.reflect.Method} instances if any are found, an
4345
* empty set if not.
4446
*/
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());
6051
}
6152

6253
}

0 commit comments

Comments
 (0)