Github user apiri commented on a diff in the pull request:
https://github.com/apache/nifi-minifi/pull/108#discussion_r161095169
--- Diff:
minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-runtime/src/main/java/org/apache/nifi/minifi/FlowEnricher.java
---
@@ -130,17 +127,13 @@ private void enrichComponent(EnrichingElementAdapter
componentToEnrich, Map<Stri
componentToEnrich.setBundleInformation(enrichingBundleCoordinate);
componentToEnrich.setDependsUponBundleCoordinate(enrichingBundleDetails.getDependencyCoordinate());
} else {
-
- // mUltiple options
+ // multiple options
final Set<String> componentToEnrichBundleVersions =
componentToEnrichVersionToBundles.values().stream()
.map(bundle ->
bundle.getBundleDetails().getCoordinate().getVersion()).collect(Collectors.toSet());
- final String componentToEnrichId =
componentToEnrich.getComponentId();
- String bundleVersion =
componentToEnrichBundleVersions.stream().sorted().reduce((version,
otherVersion) -> otherVersion).orElse(null);
- if (bundleVersion != null) {
-
componentToEnrich.setBundleInformation(componentToEnrichVersionToBundles.get(bundleVersion).getBundleDetails().getCoordinate());
- }
- logger.info("Enriching {} with bundle {}", new Object[]{});
-
+ final String bundleVersion =
componentToEnrichBundleVersions.stream().sorted().reduce((version,
otherVersion) -> otherVersion).orElse(null);
+ final BundleCoordinate enrichingCoordinate =
componentToEnrichVersionToBundles.get(bundleVersion).getBundleDetails().getCoordinate();
--- End diff --
Probably doesn't hurt but my thought when I looked at it again was that
given that we have already determined that there is a non-empty collection of
possible candidates and we are just selecting the greatest of these through the
reduction, there will be a guaranteed value. What makes it awkward is the
orElse that was left behind. I suppose I could change this to just #get() and
the meaning would be a little clearer. What do you think makes the most sense?
---