Remove code duplication in RootBeanDefinition

This commit is contained in:
Sam Brannen 2023-06-15 14:59:33 +02:00
parent 367f381fea
commit 5672284f53
1 changed files with 15 additions and 22 deletions

View File

@ -541,23 +541,12 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
if (isExternallyManagedInitMethod(initMethod)) { if (isExternallyManagedInitMethod(initMethod)) {
return true; return true;
} }
if (this.externallyManagedInitMethods != null) { return hasAnyExternallyManagedMethod(this.externallyManagedInitMethods, initMethod);
for (String candidate : this.externallyManagedInitMethods) {
int indexOfDot = candidate.lastIndexOf('.');
if (indexOfDot >= 0) {
String methodName = candidate.substring(indexOfDot + 1);
if (methodName.equals(initMethod)) {
return true;
}
}
}
}
return false;
} }
} }
/** /**
* Return all externally managed initialization methods (as an immutable Set). * Get all externally managed initialization methods (as an immutable Set).
* <p>See {@link #registerExternallyManagedInitMethod} for details * <p>See {@link #registerExternallyManagedInitMethod} for details
* regarding the format for the initialization methods in the returned set. * regarding the format for the initialization methods in the returned set.
* @since 5.3.11 * @since 5.3.11
@ -627,19 +616,23 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
if (isExternallyManagedDestroyMethod(destroyMethod)) { if (isExternallyManagedDestroyMethod(destroyMethod)) {
return true; return true;
} }
if (this.externallyManagedDestroyMethods != null) { return hasAnyExternallyManagedMethod(this.externallyManagedDestroyMethods, destroyMethod);
for (String candidate : this.externallyManagedDestroyMethods) { }
int indexOfDot = candidate.lastIndexOf('.'); }
if (indexOfDot >= 0) {
String methodName = candidate.substring(indexOfDot + 1); private static boolean hasAnyExternallyManagedMethod(Set<String> candidates, String methodName) {
if (methodName.equals(destroyMethod)) { if (candidates != null) {
return true; for (String candidate : candidates) {
} int indexOfDot = candidate.lastIndexOf('.');
if (indexOfDot > 0) {
String candidateMethodName = candidate.substring(indexOfDot + 1);
if (candidateMethodName.equals(methodName)) {
return true;
} }
} }
} }
return false;
} }
return false;
} }
/** /**