I was just writing this little code to find the cheapest offer out of a list and I'm wondering if this could be written more elegant with some lambda-function?
private Offer getBestOffer(List<Offer> allOffers, int amount) {
Offer bestOffer = null;
BigDecimal bestPrice = null;
for (Offer offer : allOffers) {
BigDecimal unitCosts = offer.getUnitPrice().multiply(new BigDecimal(amount));
BigDecimal completePrice = offer.getBasicCosts().add(unitCosts);
if (bestPrice == null || completePrice.compareTo(bestPrice) == -1) {
bestOffer = offer;
bestPrice = completePrice;
}
}
return bestOffer;
}
Or is this not really a good use case for a lambda-function?