Simplify getMergedValue to use Optional.flatMap
@@ -49,14 +49,10 @@ public interface QueryResult extends Serializable {
}
static <T> Optional<T> getMergedValue(QueryResult response, Class<? extends T> clazz, BinaryOperator<T> mergeFunction) {
- if (response.getData().isPresent()) {
- return response.getData().get().getResult()
- .stream()
+ return response.getData().flatMap(data -> data.getResult().stream()
.<T>map(result -> result.getTypedValue(clazz).orElse(null))
- .reduce(mergeFunction);
- } else {
- return Optional.empty();
- }
+ .reduce(mergeFunction)
+ );
}
static <T> Map<String, ? extends T> getValueMap(final QueryResult response, final String label, final Class<? extends T> clazz) {
