Skip to content

Commit e34a7ba

Browse files
committed
Remove code duplication in RootBeanDefinition
1 parent 62eb9b3 commit e34a7ba

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -506,23 +506,12 @@ boolean hasAnyExternallyManagedInitMethod(String initMethod) {
506506
if (isExternallyManagedInitMethod(initMethod)) {
507507
return true;
508508
}
509-
if (this.externallyManagedInitMethods != null) {
510-
for (String candidate : this.externallyManagedInitMethods) {
511-
int indexOfDot = candidate.lastIndexOf('.');
512-
if (indexOfDot >= 0) {
513-
String methodName = candidate.substring(indexOfDot + 1);
514-
if (methodName.equals(initMethod)) {
515-
return true;
516-
}
517-
}
518-
}
519-
}
520-
return false;
509+
return hasAnyExternallyManagedMethod(this.externallyManagedInitMethods, initMethod);
521510
}
522511
}
523512

524513
/**
525-
* Return all externally managed initialization methods (as an immutable Set).
514+
* Get all externally managed initialization methods (as an immutable Set).
526515
* <p>See {@link #registerExternallyManagedInitMethod} for details
527516
* regarding the format for the initialization methods in the returned set.
528517
* @since 5.3.11
@@ -583,19 +572,23 @@ boolean hasAnyExternallyManagedDestroyMethod(String destroyMethod) {
583572
if (isExternallyManagedDestroyMethod(destroyMethod)) {
584573
return true;
585574
}
586-
if (this.externallyManagedDestroyMethods != null) {
587-
for (String candidate : this.externallyManagedDestroyMethods) {
588-
int indexOfDot = candidate.lastIndexOf('.');
589-
if (indexOfDot >= 0) {
590-
String methodName = candidate.substring(indexOfDot + 1);
591-
if (methodName.equals(destroyMethod)) {
592-
return true;
593-
}
575+
return hasAnyExternallyManagedMethod(this.externallyManagedDestroyMethods, destroyMethod);
576+
}
577+
}
578+
579+
private static boolean hasAnyExternallyManagedMethod(Set<String> candidates, String methodName) {
580+
if (candidates != null) {
581+
for (String candidate : candidates) {
582+
int indexOfDot = candidate.lastIndexOf('.');
583+
if (indexOfDot > 0) {
584+
String candidateMethodName = candidate.substring(indexOfDot + 1);
585+
if (candidateMethodName.equals(methodName)) {
586+
return true;
594587
}
595588
}
596589
}
597-
return false;
598590
}
591+
return false;
599592
}
600593

601594
/**

0 commit comments

Comments
 (0)