This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Merchant> findTopMerchants(List<Merchant> merchants, int month) { | |
// Local record | |
record MerchantSales(Merchant merchant, double sales) {} | |
return merchants.stream() | |
.map(merchant -> new MerchantSales(merchant, computeSales(merchant, month))) | |
.sorted((m1, m2) -> Double.compare(m2.sales(), m1.sales())) | |
.map(MerchantSales::merchant) | |
.collect(toList()); | |
} |