Java Reference
In-Depth Information
Listing 11.14. The
Discount
service
11.4.2. Using the Discount service
Because the Discount service is a remote service, you again add a simulated delay of 1 second to
it, as shown in the following listing. As you did in
section 11.3
, first try to reimplement the
findPrices method to fit these new requirements in the most obvious (but sadly sequential and
synchronous) way.
Listing 11.15. Simplest
findPrices
implementation that uses the
Discount
service
The desired result is obtained by pipelining three map operations on the stream of shops:
The first operation transforms each shop into a
String
that encodes the price and discount code of the
requested product for that shop.
The second operation parses those
String
s, converting each of them in a
Quote
object.
Finally, the third one contacts the remote
Discount
service that will calculate the final discounted
price and return another
String
containing the name of the shop with that price.
Search WWH ::
Custom Search