O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

Let's recall how a user called the lambda-friendly API:

double timeSec = 10.0;int trafficUnitsNumber = 10;SpeedModel speedModel = (t, wp, hp) -> ...;BiConsumer<TrafficUnit, Double> printResults = (tu, sp) -> ...;BiPredicate<TrafficUnit, Double> limitSpeed = (tu, sp) -> ...;Traffic api = new TrafficImpl(Month.APRIL, DayOfWeek.FRIDAY, 17,                               "USA", "Denver", "Main103S");api.speedAfterStart(timeSec, trafficUnitsNumber, speedModel,                     limitSpeed, printResults);

As we have already noticed, the freedom of the speed calculation manipulation with such an API (without changing it) extends to the formula of the speed calculation, device and format of the output, and the selection of traffic. This is not bad in our simplistic application, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required