Created
September 25, 2022 10:28
-
-
Save GayanM/96b1da4fe1c2d370b39939ebcc67697c to your computer and use it in GitHub Desktop.
Obtain a collection of statistic figures (i.e. sum, average, max, min, count) for all products of given category
This file contains hidden or 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
| @RequestMapping("/statistics") | |
| public DoubleSummaryStatistics getStatistics(@RequestParam("category") final Optional<String> category) { | |
| return productRepos.findAll().stream().filter(p -> category.get().equalsIgnoreCase(p.getCategory())). | |
| mapToDouble(p -> p.getPrice()).summaryStatistics(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment