Reputation: 127
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.
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())));
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?
Upvotes: 0
Views: 205
Reputation: 149
despCostChangeDtl from an object to a list, so you should flatmap after map.
Upvotes: 1