Extract duplicated code into a separate method

This commit is contained in:
stsypanov 2019-02-11 16:44:31 +02:00 committed by Juergen Hoeller
parent 92053bb84e
commit d2bfca7900
1 changed files with 12 additions and 14 deletions

View File

@ -1120,13 +1120,7 @@ public abstract class ClassUtils {
}
}
else {
Set<Method> candidates = new HashSet<>(1);
Method[] methods = clazz.getMethods();
for (Method method : methods) {
if (methodName.equals(method.getName())) {
candidates.add(method);
}
}
Set<Method> candidates = findMethodCandidatesByName(clazz, methodName);
if (candidates.size() == 1) {
return candidates.iterator().next();
}
@ -1165,13 +1159,7 @@ public abstract class ClassUtils {
}
}
else {
Set<Method> candidates = new HashSet<>(1);
Method[] methods = clazz.getMethods();
for (Method method : methods) {
if (methodName.equals(method.getName())) {
candidates.add(method);
}
}
Set<Method> candidates = findMethodCandidatesByName(clazz, methodName);
if (candidates.size() == 1) {
return candidates.iterator().next();
}
@ -1362,4 +1350,14 @@ public abstract class ClassUtils {
}
}
private static Set<Method> findMethodCandidatesByName(Class<?> clazz, String methodName) {
Set<Method> candidates = new HashSet<>(1);
Method[] methods = clazz.getMethods();
for (Method method : methods) {
if (methodName.equals(method.getName())) {
candidates.add(method);
}
}
return candidates;
}
}