I am trying to write a groovy script code, but found out that groovy script does not support lambda expressions. Can someone help me convert this piece of code so that it works for groovy script as well?
if(CollectionUtils.isNotEmpty(orderModel.getFreeProductSets())){
orderModel.getFreeProductSets().forEach(orderFreeProductSetModel -> {
if(CollectionUtils.isNotEmpty(orderFreeProductSetModel.getFreeProducts())){
modelService.removeAll(orderFreeProductSetModel.getFreeProducts());
}
else{
System.out.println("no entry found for orderFreeProductSetModel");
}
});
modelService.removeAll(orderModel.getFreeProductSets());
}
else{
System.out.println("FreeProductSets is empty");
}
Thank you.
CodePudding user response:
You can try something like this :
if (CollectionUtils.isNotEmpty(orderModel.getFreeProductSets())) {
orderModel.getFreeProductSets().each{ orderFreeProductSetModel ->
if (CollectionUtils.isNotEmpty(orderFreeProductSetModel.getFreeProducts())) {
modelService.removeAll(orderFreeProductSetModel.getFreeProducts());
} else {
System.out.println("no entry found for orderFreeProductSetModel");
}
};
modelService.removeAll(orderModel.getFreeProductSets());
} else {
System.out.println("FreeProductSets is empty");
}
You just needed to use foreach{} instead of foreach()