Source:
<code>private static ArrayList<TimeDistanceReport> calculateTimeDistanceResult( long userId, Collection<Long> deviceIds, Collection<Long> groupIds, Double latitude, Double longitude) { ArrayList<TimeDistanceReport> result = new ArrayList<>(); List<List<Double>> sourceLocations = new ArrayList<>(); ArrayList<Double> destinationLocation = new ArrayList<>(); destinationLocation.add(longitude); destinationLocation.add(latitude); for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) { Context.getPermissionsManager().checkDevice(userId, deviceId); List<Double> deviceLocation = new ArrayList<>(); deviceLocation.add(Context.getIdentityManager().getLastPosition(deviceId).getLongitude()); deviceLocation.add(Context.getIdentityManager().getLastPosition(deviceId).getLatitude()); sourceLocations.add(deviceLocation); } TimeDistanceResponse timeDistanceResponse = Context.getMatrix().getTimeDistanceMatrix(sourceLocations, destinationLocation); int deviceIndex = 0; <START> for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) { <END> Context.getPermissionsManager().checkDevice(userId, deviceId); TimeDistanceReport timeDistanceReport = new TimeDistanceReport(); timeDistanceReport.setDeviceId(deviceId); timeDistanceReport.setDeviceName(Context.getIdentityManager().getById(deviceId).getName()); timeDistanceReport.setDistance(timeDistanceResponse.getDistance(deviceIndex)); timeDistanceReport.setTime(timeDistanceResponse.getDuration(deviceIndex) * 1000); result.add(timeDistanceReport); deviceIndex++; } return result; }</code><technical_language>I standard indexed for loop more sense here</technical_language>

Target:
private static ArrayList<TimeDistanceReport> calculateTimeDistanceResult( long userId, Collection<Long> deviceIds, Collection<Long> groupIds, Double latitude, Double longitude) { ArrayList<TimeDistanceReport> result = new ArrayList<>(); List<List<Double>> sourceLocations = new ArrayList<>(); List<Double> destinationLocation = new ArrayList<>(); destinationLocation.add(longitude); destinationLocation.add(latitude); List<Long> deviceList = new ArrayList<>(ReportUtils.getDeviceList(deviceIds, groupIds)); for (long deviceId: deviceList) { Context.getPermissionsManager().checkDevice(userId, deviceId); List<Double> deviceLocation = new ArrayList<>(); deviceLocation.add(Context.getIdentityManager().getLastPosition(deviceId).getLongitude()); deviceLocation.add(Context.getIdentityManager().getLastPosition(deviceId).getLatitude()); sourceLocations.add(deviceLocation); } TimeDistanceResponse timeDistanceResponse = Context .getTimeDistanceMatrix() .getTimeDistanceMatrix(sourceLocations, destinationLocation); for (int deviceIndex = 0; deviceIndex < deviceList.size(); deviceIndex++) { long deviceId = deviceList.get(deviceIndex); Context.getPermissionsManager().checkDevice(userId, deviceId); TimeDistanceReport timeDistanceReport = new TimeDistanceReport(); timeDistanceReport.setDeviceId(deviceId); timeDistanceReport.setDeviceName(Context.getIdentityManager().getById(deviceId).getName()); timeDistanceReport.setDistance(timeDistanceResponse.getDistance(deviceIndex)); timeDistanceReport.setTime(timeDistanceResponse.getDuration(deviceIndex) * 1000); result.add(timeDistanceReport); } return result; }