From 53ebb6c835ef6f30272581f7dc17fd7e2a147b8a Mon Sep 17 00:00:00 2001 From: David Venable Date: Tue, 27 Sep 2022 14:57:03 -0500 Subject: [PATCH] PR feedback - Use Optional to make code more readable. Signed-off-by: David Venable --- .../parser/model/PipelineConfiguration.java | 13 +++++++++---- .../parser/model/PipelineConfigurationTests.java | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/data-prepper-core/src/main/java/org/opensearch/dataprepper/parser/model/PipelineConfiguration.java b/data-prepper-core/src/main/java/org/opensearch/dataprepper/parser/model/PipelineConfiguration.java index d1a1c9b30c..930aad17ef 100644 --- a/data-prepper-core/src/main/java/org/opensearch/dataprepper/parser/model/PipelineConfiguration.java +++ b/data-prepper-core/src/main/java/org/opensearch/dataprepper/parser/model/PipelineConfiguration.java @@ -15,6 +15,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; public class PipelineConfiguration { @@ -113,13 +114,17 @@ private List getProcessorsFromPluginModel( private static PluginSetting getPluginSettingFromPluginModel(final PluginModel pluginModel) { - final Map settingsMap = pluginModel.getPluginSettings(); - return new PluginSetting(pluginModel.getPluginName(), settingsMap == null ? new HashMap<>() : settingsMap); + final Map settingsMap = Optional + .ofNullable(pluginModel.getPluginSettings()) + .orElseGet(HashMap::new); + return new PluginSetting(pluginModel.getPluginName(), settingsMap); } private static RoutedPluginSetting getRoutedPluginSettingFromSinkModel(final SinkModel sinkModel) { - final Map settingsMap = sinkModel.getPluginSettings(); - return new RoutedPluginSetting(sinkModel.getPluginName(), settingsMap == null ? new HashMap<>() : settingsMap, sinkModel.getRoutes()); + final Map settingsMap = Optional + .ofNullable(sinkModel.getPluginSettings()) + .orElseGet(HashMap::new); + return new RoutedPluginSetting(sinkModel.getPluginName(), settingsMap, sinkModel.getRoutes()); } private Integer getWorkersFromPipelineModel(final PipelineModel pipelineModel) { diff --git a/data-prepper-core/src/test/java/org/opensearch/dataprepper/parser/model/PipelineConfigurationTests.java b/data-prepper-core/src/test/java/org/opensearch/dataprepper/parser/model/PipelineConfigurationTests.java index a25db7c141..b732936797 100644 --- a/data-prepper-core/src/test/java/org/opensearch/dataprepper/parser/model/PipelineConfigurationTests.java +++ b/data-prepper-core/src/test/java/org/opensearch/dataprepper/parser/model/PipelineConfigurationTests.java @@ -206,7 +206,7 @@ void testInvalidDelayConfiguration() { @Test void testSinksWithRoutes() { final List> orderedSinkRoutes = new ArrayList<>(); - for (SinkModel sink : sinks) { + for (final SinkModel sink : sinks) { final Set routes = Collections.singleton(UUID.randomUUID().toString()); when(sink.getRoutes()).thenReturn(routes); orderedSinkRoutes.add(routes);