Answered step by step
Verified Expert Solution
Link Copied!

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

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 their prices converted to EUR currency.
You're given a stream (java.util.stream.Stream) of SoldProduct
objects. Sold Product is defined as follows:
@Value
class SoldProduct {
String name;
BigDecimal price;
String currency:
}
(@Value comes from lombok tool and will make this class immutable - generate toString, equals and hashCode, make all fields
private and final, add getters for all the fields and add single all arguments constructor).
Write a function, which will map the Stream Sold Product instance of Sold ProductsAggregate to an which is defined as follows:
@Value
class SoldProductsAggregate {
List SimpleSold Product> 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 rate(String currency);
}
Unfortunately EURExchangeService is
a bit buggy and may return some invalid values (like null, empty or negative). You should handle it by ignoring them.?
If an argument you get as input to SoldProductsAggregate.aggregate()
is null, empty Stream
and so on-then you must not return null In case of such argument vou must convert it to empty Stream Before doing the mapping

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems X Special Issue On Database And Expert Systems Applications Lncs 8220

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2013th Edition

3642412203, 978-3642412202

More Books

Students also viewed these Databases questions

Question

3. Contrast relational contexts in organizations

Answered: 1 week ago

Question

2. Describe ways in which organizational culture is communicated

Answered: 1 week ago

Question

1. Describe and compare approaches to managing an organization

Answered: 1 week ago