Skip to content

Conversation

Pankraz76
Copy link
Owner

@Pankraz76
Copy link
Owner Author

nice approach looks perfectly fine to me.

Copy link
Owner Author

@Pankraz76 Pankraz76 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well done

}
}
}
return candidateBeanName;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe filtering would highlight the main condition:

.filter(entry -> entry.getValue().isAutowireCandidate() && entry.getValue().isDefaultCandidate())

protected String determineEffectivelyPrimaryCandidate(Map<String, Object> candidates, Class<?> requiredType) {
    return candidates.entrySet().stream()
        .map(entry -> Map.entry(entry.getKey(), transformedBeanName(entry.getKey())))
        .filter(entry -> containsBeanDefinition(entry.getValue()))
        .map(entry -> Map.entry(entry.getKey(), getMergedLocalBeanDefinition(entry.getValue())))
        .filter(entry -> entry.getValue().isAutowireCandidate() && entry.getValue().isDefaultCandidate())
        .map(Map.Entry::getKey)
        .reduce((a, b) -> null) // Ensures only one candidate; otherwise, null
        .orElse(null);
}

Its although nice, if a method has only has one return statement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve BeanFactory/ObjectProvider to select the only one default candidate among non-default candidates
2 participants