Skip to content

Commit 5672284

Browse files
committed
Remove code duplication in RootBeanDefinition
1 parent 367f381 commit 5672284

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
@@ -541,23 +541,12 @@ boolean hasAnyExternallyManagedInitMethod(String initMethod) {
541541
if (isExternallyManagedInitMethod(initMethod)) {
542542
return true;
543543
}
544-
if (this.externallyManagedInitMethods != null) {
545-
for (String candidate : this.externallyManagedInitMethods) {
546-
int indexOfDot = candidate.lastIndexOf('.');
547-
if (indexOfDot >= 0) {
548-
String methodName = candidate.substring(indexOfDot + 1);
549-
if (methodName.equals(initMethod)) {
550-
return true;
551-
}
552-
}
553-
}
554-
}
555-
return false;
544+
return hasAnyExternallyManagedMethod(this.externallyManagedInitMethods, initMethod);
556545
}
557546
}
558547

559548
/**
560-
* Return all externally managed initialization methods (as an immutable Set).
549+
* Get all externally managed initialization methods (as an immutable Set).
561550
* <p>See {@link #registerExternallyManagedInitMethod} for details
562551
* regarding the format for the initialization methods in the returned set.
563552
* @since 5.3.11
@@ -627,19 +616,23 @@ boolean hasAnyExternallyManagedDestroyMethod(String destroyMethod) {
627616
if (isExternallyManagedDestroyMethod(destroyMethod)) {
628617
return true;
629618
}
630-
if (this.externallyManagedDestroyMethods != null) {
631-
for (String candidate : this.externallyManagedDestroyMethods) {
632-
int indexOfDot = candidate.lastIndexOf('.');
633-
if (indexOfDot >= 0) {
634-
String methodName = candidate.substring(indexOfDot + 1);
635-
if (methodName.equals(destroyMethod)) {
636-
return true;
637-
}
619+
return hasAnyExternallyManagedMethod(this.externallyManagedDestroyMethods, destroyMethod);
620+
}
621+
}
622+
623+
private static boolean hasAnyExternallyManagedMethod(Set<String> candidates, String methodName) {
624+
if (candidates != null) {
625+
for (String candidate : candidates) {
626+
int indexOfDot = candidate.lastIndexOf('.');
627+
if (indexOfDot > 0) {
628+
String candidateMethodName = candidate.substring(indexOfDot + 1);
629+
if (candidateMethodName.equals(methodName)) {
630+
return true;
638631
}
639632
}
640633
}
641-
return false;
642634
}
635+
return false;
643636
}
644637

645638
/**

0 commit comments

Comments
 (0)