Answered step by step
Verified Expert Solution
Question
1 Approved Answer
While working on an e - commerce service,you need to build a simple aggregator for a report,which will hold sold products and a sum of
While working on an ecommerce service,you need to build a simple aggregator for a report,which will hold sold products and a sum of their prices converted to EUR currency. You're given a streamjavautil.stream.Stream of SoldProduct objects.SoldProduct is defined as follows: @Value class SoldProduct String name; Bigdecimal price; String currency; @Value comes from lombok tool and will make this class immutablegenerate toString,equals and hashcode, make all fields private and final,add getters for all the fields and add single all arguments contructor Write a function,Which will map the Stream to an instance of SoldProductsAggregate which is defined as follows: @Value class SoldProductsAggregate List products; BigDecimal total; and SimpleSoldProduct @Value class SimpleSoldProduct String name; BigDecimal price; To convert price to EUR use EURExchangeService which implements ExchangeService: interface ExchangeService Optional rateString currency; Unfortunately EURExchangeService is a bit buggy and may be return some invalid valueslike null,empty or negative You should handle it by ignoring them. If an argumemt you get as input to SoldProductsAggregates.aggregate is null,empty Stream and so onthenyou must not return null.In case of such argument, you must convert it to empty Stream before doing the mapping.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started