I have PrimaryDTO class which contains a List<SecondaryDTO> and this SecondaryDTO itself contains a Set<SecondaryCategoryDTO> and finally this SecondaryCategoryDTO contains a boolean status.
In the below statement, I want to check if any status is true then go inside if statement else don't enter.
if(Optional.ofNullable(PrimaryDTO.getSecondaryDTOs()).
orElse(PrimaryDTO.getSecondaryDTOs()).stream().filter(Objects::nonNull)
.map(x->x.getSecondaryCategories()).anyMatch(z-> z.isStatus()==true))
But, in the above syntax, z.isStatus() is giving error as it is saying z to be a set. I am already iterating Set via .map with getSecondaryCategories(). I am not getting why it is taking it as set?
Optional.ofNullable(PrimaryDTO.getSecondaryDTOs()). orElse(PrimaryDTO.getSecondaryDTOs())? Doesn’t it always evaluate toPrimaryDTO.getSecondaryDTOs(), no matter whether it isnull? Besides that, you are not iterating theSet, you are just mapping to it. Perhaps, you meant.flatMap(x -> x.getSecondaryCategories().stream())…