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

There's more...

The pipeline allows you to add another filter (or any other operation) easily:

Predicate<TrafficUnit> limitTraffic = tu ->    tu.getVehicleType() == Vehicle.VehicleType.CAR    || tu.getVehicleType() == Vehicle.VehicleType.TRUCK;getTrafficUnitStream(trafficUnitsNumber)   .filter(limitTraffic)   .map(TrafficUnitWrapper::new)   .map(tuw -> tuw.setSpeedModel(speedModel))   .map(tuw -> tuw.calcSpeed(timeSec))   .filter(tuw -> limitSpeed.test(tuw.getTrafficUnit(),                                   tuw.getSpeed()))   .forEach(tuw -> printResults.accept(tuw.getTrafficUnit(),                                        tuw.getSpeed()));

It is especially important when many types of data have to be processed. It's worth mentioning that having a filter before the calculations is the best way to improve performance because it ...

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