I have recently switched from C++ to Java and facing tough times to deal with the syntax and lambda functions. So there is one method which got updated. I am confused editing the code correspondingly.
So initially getCostChangeDtl() used to return data of type CostChangeDtl but now the same method returns a list of CostChangeDtl. So I made some changes accordingly still facing some issues.
Before
costChangeDetails.forEach(
costChangeDetail -> changeDtls.addAll(costChangeDetail.getItems().stream().map(item -> {
CostChangeDtl despCostChangeDtl = getCostChangeDtl(ccd, costChangeDetail, item,
metrics);
if (despCostChangeDtl.getItemID() == null)
{
String consumerGtin = item.item.getConsumerDetails().getConsumerGtin();
missingSkuGtins.add(
format("%s | %s ", consumerGtin, costChangeDetail.getLocation().getId()));
}
return despCostChangeDtl;
}).filter(despCostChangeDtl -> despCostChangeDtl.getItemID() != null)
.collect(Collectors.toList())));
After
costChangeDetails.forEach(
costChangeDetail -> changeDtls.addAll(costChangeDetail.getItems().stream().map(item -> {
List<CostChangeDtl> despCostChangeDtl = getCostChangeDtl(ccd, costChangeDetail, item,
metrics);
for (CostChangeDtl costChangeDtl : despCostChangeDtl) {
if (costChangeDtl.getItemID() == null)
{
String consumerGtin = item.item.getConsumerDetails().getConsumerGtin();
missingSkuGtins.add(
format("%s | %s ", consumerGtin, costChangeDetail.getLocation().getId()));
}
}
return despCostChangeDtl;
}).filter(despCostChangeDtl -> despCostChangeDtl.getItemID() != null)
.collect(Collectors.toList())));
Now I am getting an error in despCostChangeDtl.getItemID() as expected since it is despCostChangeDtl is now a list. How to fix this particular issue?

despCostChangeDtlto literally anything else inside your call tofilter(), and prepending a call tostream()before you callfilter()?List<CostChangeDtl>in step 1. Then apply filter over all the items in step 2. I will post an answer separately because it difficult to write it here.