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("/products-count") | |
| public Map<Long, Integer> getOrdersWithProductCount() { | |
| return orderRepo.findAll().stream(). | |
| collect(Collectors.toMap(o -> o.getId(), o -> o.getProducts().size())); | |
| } |
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("/group-by-customer") | |
| public Map<Customer, List<Order>> getOrdersByCustomer () { | |
| Map<com.mycompany.functional.programming.exercises.models.Customer, | |
| List<com.mycompany.functional.programming.exercises.models.Order>> ordersByCustomer = orderRepo. | |
| findAll().stream().collect(Collectors.groupingBy(com.mycompany.functional.programming.exercises.models. | |
| Order::getCustomer)); | |
| Map<Customer, List<Order>> ordersByCustomerTransformed = new HashMap(); | |
| ordersByCustomer.forEach((k,v) -> { | |
| Customer customer = new Customer(k.getId(), k.getName(), k.getTier()); | |
| List<Order> orders = v.stream().map(o -> new Order(o.getId(), o.getOrderDate(), o.getDeliveryDate(), o.getStatus())). |
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("/product-total-sum") | |
| public Map<Order, Double> getProductTotalSumByOrder() { | |
| return orderRepo.findAll().stream().collect(Collectors.toMap(o -> new Order(o.getId(), o.getOrderDate(), | |
| o.getDeliveryDate(), o.getStatus()), o -> o.getProducts().stream().mapToDouble(p -> | |
| p.getPrice()).sum())); | |
| } |
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("/product-category") | |
| Map<String, List<String>> getProductsByCategory(List<Product> productList) { | |
| return productRepos.findAll().stream().collect(Collectors.groupingBy(com.mycompany.functional.programming. | |
| exercises.models.Product::getCategory, Collectors.mapping(product -> product.getName(), | |
| Collectors.toList()))); | |
| } |
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("/most-expensive") | |
| Map<String, Optional<Product>> getMostExpensiveProductByCategory () { | |
| Map<String, Optional<com.mycompany.functional.programming.exercises.models.Product>> mostExpensiveByCategory = productRepos.findAll().stream().collect(Collectors.groupingBy( | |
| com.mycompany.functional.programming.exercises.models.Product::getCategory, | |
| Collectors.maxBy(Comparator.comparing(com.mycompany.functional.programming.exercises.models. | |
| Product::getPrice) | |
| ) | |
| )); | |
| Map<String, Optional<Product>> ordersByCustomerTransformed = new HashMap(); | |
| mostExpensiveByCategory.entrySet().stream().forEach(e -> { |
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
| database = postgres # Determines which of PostgreSQL or Cassandra | |
| # this node will use as its datastore. | |
| # Accepted values are `postgres`, | |
| # `cassandra`, and `off`. | |
| pg_host = 127.0.0.1 # Host of the Postgres server. | |
| pg_port = 5432 # Port of the Postgres server. | |
| pg_timeout = 5000 # Defines the timeout (in ms), for connecting, | |
| # reading and writing. |
OlderNewer