I need some alternative for the following code to be more readable. ssrFlightList
is nested list.
I tried with forEach
:
ssrFlightList.stream().forEach(
x -> x.getSsrPassengerList().stream().forEach(
y -> y.getSsrItemList().stream().forEach(
z -> z.getSsrCodeList().stream().forEach(t -> {
if ("BSML".equalsIgnoreCase(t.getCode())) {
ssrCodeListStr.set(t.getText());
}
})
)));
And this is flatMap
example too:
Optional<SSRItemCode> itemCode = ssrFlightList
.stream()
.flatMap(firstNode -> firstNode.getSsrPassengerList().stream())
.flatMap(s -> s.getSsrItemList().stream())
.flatMap(s -> s.getSsrCodeList().stream())
.filter(s1 -> s1.getCode().equals("BSML"))
.findFirst();
itemCode.isPresent() ? ssrCodeListStr.set(itemCode.get().getText());
I'm looking for an alternative way to get ssrCodeListStr
text.