I have a code fragment that I want to make more concise yet readable using Java 8 features like lambdas/streams etc.
Basically, there is a list of items and each item has a list of errors. If there is at least one item with at least one error, "failure" needs to be returned. If no items with any error, return "success".
Optional<List<Item>> optionalItemList = Optional.ofNullable(message.getItems());
if (optionalItemList.isPresent())
for (Item item : optionalItemList.get()) {
Optional<List<Error>> optionalErrorList = Optional.ofNullable((item.getErrors()));
if(optionalErrorList.isPresent())
if (!optionalErrorList.get().isEmpty()) {
return "failure";
}
}
return "success";