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...

This experience has made us aware that using an inner private class can make the functionality untestable in isolation. Let's try and get rid of the private class CountByLane. This leads us to the third version of the TrafficDensity3 class (we have shown the code that has changed in bold):

Integer[] trafficByLane(Stream<TrafficUnit> stream, int trafficUnitsNumber, double timeSec,SpeedModel speedModel, double[] speedLimitByLane) {  int lanesCount = speedLimitByLane.length;  Map<Integer, Integer> trafficByLane = new HashMap<>();  for(int i = 1; i <= lanesCount; i++){    trafficByLane.put(i, 0);  }  stream.limit(trafficUnitsNumber)    .map(TrafficUnitWrapper::new)    .map(tuw -> tuw.setSpeedModel(speedModel)) .map(tuw -> calcSpeed(tuw.getVehicle() ...

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