Source:
<code>public void run(PortBindings portBindings, Configuration conf, Map<String, String> parameters) { metricPusherCreatorProducer.create(parameters) .ifPresent(metricPusherCreator -> { logger.info("Using MetricPusherCreatorProducer: {}", metricPusherCreator); metricPusherProducer.create(metricPusherCreator, parameters) .ifPresent(metricPusher -> { logger.info("Using MetricPusher: {}", metricPusher); fileSystemProducer.create(conf) .ifPresent(fs -> { logger.info("Using FileSystem: {}", fs); reportLocationsFinder.find(parameters) .ifPresent(paths -> { logger.info("Using report locations of size: {}", paths.size()); labelNamesByMetricNameProducer.create(parameters) .ifPresent(labelNamesByMetricName -> { logger.info("Using label map of size: {}", labelNamesByMetricName.size()); <START> List<Optional<List<Gauge>>> optionals = paths.stream() .map(path -> reportEntryReader.read(fs, new Path(path)) .flatMap(reportEntries -> reportEntryConverter.convert(reportEntries, path, labelNamesByMetricName))) .collect(Collectors.toList()); <END> unwrapOptionals(optionals) .map(gauges -> gauges.stream().flatMap(Collection::stream).collect(Collectors.toList())) .ifPresent(gauges -> { logger.info("Using gauges of size: {}", gauges.size()); gaugesRegistrar.register(gauges) .ifPresent(registry -> { logger.info("Using registry: {}", registry); jobNameProducer.create(parameters) .ifPresent(jobName -> { logger.info("Using job name: {}", jobName); metricPusher.pushSafe(registry, jobName); }); }); }); }); }); }); }); }); }</code><technical_language>If reportEntryReader.read returned a List<Entry> reportEntryConverter.convert a Stream<Gauge> I replace this Stream<Gauge> gauges = paths.stream().flatMap(path -> convert(read(...), ...); avoid unwrapOptionals</technical_language>

Target:
public void run(PortBindings portBindings, Configuration conf, Map<String, String> parameters) { metricPusherCreatorProducer.create(parameters) .ifPresent(metricPusherCreator -> { logger.info("Using MetricPusherCreatorProducer: {}", metricPusherCreator); metricPusherProducer.create(metricPusherCreator, parameters) .ifPresent(metricPusher -> { logger.info("Using MetricPusher: {}", metricPusher); fileSystemProducer.create(conf) .ifPresent(fs -> { logger.info("Using FileSystem: {}", fs); reportLocationsFinder.find(parameters) .ifPresent(paths -> { logger.info("Using report locations of size: {}", paths.size()); labeledMetricConfByPatternProducer.create(parameters) .ifPresent(labeledMetricConfByPattern -> { logger.info("Using label map of size: {}", labeledMetricConfByPattern.size()); List<Optional<List<ReportEntry>>> collect = paths.stream() .map(path -> reportEntryReader.read(fs, new Path(path))) .collect(Collectors.toList()); unwrapOptionals(collect) .map(x -> x.stream().flatMap(Collection::stream).collect(Collectors.toList())) .ifPresent(reportEntries -> { logger.info("Using report entries of size: {}", reportEntries.size()); reportEntryConverter.convert(reportEntries, parameters.get(REPORTS_DIR_PATH), labeledMetricConfByPattern) .ifPresent(gauges -> { logger.info("Using gauges of size: {}", gauges.size()); gaugesRegistrar.register(gauges) .ifPresent(registry -> { logger.info("Using registry: {}", registry); groupingKeyProducer.create(parameters) .ifPresent(groupingKey -> { logger.info("Using grouping key of size: {}", groupingKey.size()); metricPusher.pushSafe(registry, JOB, groupingKey); }); }); }); }); }); }); }); }); }); }