Skip to content

Commit 6388bac

Browse files
committed
Extract duplicated code into a separate method
1 parent 0bdacdd commit 6388bac

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

spring-core/src/main/java/org/springframework/util/ClassUtils.java

+12-14
Original file line numberDiff line numberDiff line change
@@ -1120,13 +1120,7 @@ public static Method getMethod(Class<?> clazz, String methodName, @Nullable Clas
11201120
}
11211121
}
11221122
else {
1123-
Set<Method> candidates = new HashSet<>(1);
1124-
Method[] methods = clazz.getMethods();
1125-
for (Method method : methods) {
1126-
if (methodName.equals(method.getName())) {
1127-
candidates.add(method);
1128-
}
1129-
}
1123+
Set<Method> candidates = findMethodCandidatesByName(clazz, methodName);
11301124
if (candidates.size() == 1) {
11311125
return candidates.iterator().next();
11321126
}
@@ -1165,13 +1159,7 @@ public static Method getMethodIfAvailable(Class<?> clazz, String methodName, @Nu
11651159
}
11661160
}
11671161
else {
1168-
Set<Method> candidates = new HashSet<>(1);
1169-
Method[] methods = clazz.getMethods();
1170-
for (Method method : methods) {
1171-
if (methodName.equals(method.getName())) {
1172-
candidates.add(method);
1173-
}
1174-
}
1162+
Set<Method> candidates = findMethodCandidatesByName(clazz, methodName);
11751163
if (candidates.size() == 1) {
11761164
return candidates.iterator().next();
11771165
}
@@ -1362,4 +1350,14 @@ public static Method getStaticMethod(Class<?> clazz, String methodName, Class<?>
13621350
}
13631351
}
13641352

1353+
private static Set<Method> findMethodCandidatesByName(Class<?> clazz, String methodName) {
1354+
Set<Method> candidates = new HashSet<>(1);
1355+
Method[] methods = clazz.getMethods();
1356+
for (Method method : methods) {
1357+
if (methodName.equals(method.getName())) {
1358+
candidates.add(method);
1359+
}
1360+
}
1361+
return candidates;
1362+
}
13651363
}

0 commit comments

Comments
 (0)