I have the following method:
public String getAllDangerousProductsName(Offer offer){
return offer.getOfferRows().stream()
.filter(row -> row.isDangerousGood())
.map(row -> row.getItemInformation().getOfferTexts().getName())
.collect(Collectors.joining(","));
}
I want to reuse this method for row.isBulkyGood(). What I am doing currently is
public String getAllBulkyProductsName(Offer offer){
return offer.getOfferRows().stream()
.filter(row -> row.isBulkyGood())
.map(row -> row.getItemInformation().getOfferTexts().getName())
.collect(Collectors.joining(","));
}
... which is basically code repetition. Is there a way I can pass the function as method parameter to optimize this to have one method for both the filter condition?