Skip to content

Commit

Permalink
PR feedback - Use Optional to make code more readable.
Browse files Browse the repository at this point in the history
Signed-off-by: David Venable <[email protected]>
  • Loading branch information
dlvenable committed Sep 27, 2022
1 parent d497df2 commit 53ebb6c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -113,13 +114,17 @@ private List<PluginSetting> getProcessorsFromPluginModel(


private static PluginSetting getPluginSettingFromPluginModel(final PluginModel pluginModel) {
final Map<String, Object> settingsMap = pluginModel.getPluginSettings();
return new PluginSetting(pluginModel.getPluginName(), settingsMap == null ? new HashMap<>() : settingsMap);
final Map<String, Object> settingsMap = Optional
.ofNullable(pluginModel.getPluginSettings())
.orElseGet(HashMap::new);
return new PluginSetting(pluginModel.getPluginName(), settingsMap);
}

private static RoutedPluginSetting getRoutedPluginSettingFromSinkModel(final SinkModel sinkModel) {
final Map<String, Object> settingsMap = sinkModel.getPluginSettings();
return new RoutedPluginSetting(sinkModel.getPluginName(), settingsMap == null ? new HashMap<>() : settingsMap, sinkModel.getRoutes());
final Map<String, Object> settingsMap = Optional
.ofNullable(sinkModel.getPluginSettings())
.orElseGet(HashMap::new);
return new RoutedPluginSetting(sinkModel.getPluginName(), settingsMap, sinkModel.getRoutes());
}

private Integer getWorkersFromPipelineModel(final PipelineModel pipelineModel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void testInvalidDelayConfiguration() {
@Test
void testSinksWithRoutes() {
final List<Collection<String>> orderedSinkRoutes = new ArrayList<>();
for (SinkModel sink : sinks) {
for (final SinkModel sink : sinks) {
final Set<String> routes = Collections.singleton(UUID.randomUUID().toString());
when(sink.getRoutes()).thenReturn(routes);
orderedSinkRoutes.add(routes);
Expand Down

0 comments on commit 53ebb6c

Please sign in to comment.