request
.getCustomer()
.stream()
.filter(custDetails -> custDetails.getCorrespondenceAddress() != null)
.forEach(
custDetails -> {
if (validateNotNull(
custDetails.getCorrespondenceAddress().getHasCorrespondenceAddress())) {
customAttributesList.add(
generateCustomAttributeHasCorrespondenceAddress(
custDetails.getCorrespondenceAddress().getHasCorrespondenceAddress(),
customerCountCorrespondenceAddress));
}
if (validateNotNull(
custDetails
.getCorrespondenceAddress()
.getCorrespondenceAddressPostcode())) {
customAttributesList.add(
generateCustomAttributeCorrespondenceAddressPostcode(
custDetails
.getCorrespondenceAddress()
.getCorrespondenceAddressPostcode(),
customerCountCorrespondenceAddressPostcode));
}
customerCountCorrespondenceAddress++;
customerCountCorrespondenceAddressPostcode++;
});
Here request contains a list of customers, list of customer is having correspondence address, correspondence addrress is having 2 fields. I am trying to map these fields to a custom attribute list. Is there any way to replace the if in for each block with some streams method?
Looking at your code, might need to call stream 2 times. One for address and other for postalCode.