Skip to content

Commit

Permalink
Simplify code with Elvis operator
Browse files Browse the repository at this point in the history
Signed-off-by: Wouter Born <github@maindrain.net>
  • Loading branch information
wborn committed Oct 24, 2020
1 parent f88e56f commit e7a902c
Showing 1 changed file with 2 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,7 @@ public Iterable<HistoricItem> query(FilterCriteria filter) {
return List.of();
}
Optional<MapDbItem> item = deserialize(json);
if (!item.isPresent()) {
return List.of();
}
return List.of(item.get());
return item.isPresent() ? List.of(item.get()) : List.of();
}

private String serialize(MapDbItem item) {
Expand All @@ -182,10 +179,7 @@ private void commit() {
}

private static <T> Stream<T> streamOptional(Optional<T> opt) {
if (!opt.isPresent()) {
return Stream.empty();
}
return Stream.of(opt.get());
return opt.isPresent() ? Stream.of(opt.get()) : Stream.empty();
}

@Override
Expand Down

0 comments on commit e7a902c

Please sign in to comment.