SHARE
TWEET

Untitled

a guest Jun 18th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public List<Integer> fetchVehicleIds(String datasetId) throws ApiException {
  2.  
  3.     VehiclesApi vehiclesApi = new VehiclesApi();
  4.  
  5.     List<Integer> vehicleIds;
  6.     vehicleIds = vehiclesApi.vehiclesGetIds(datasetId).getVehicleIds();
  7.  
  8.     return vehicleIds;
  9. }
  10.  
  11.  public List<VehicleResponse> fetchVehicleDetails(String datasetId, List<Integer> vehicleIds) throws InterruptedException, ApiException {
  12.  
  13.     CountDownLatch latch = new CountDownLatch(vehicleIds.size());
  14.     List<VehicleResponse> vehiclesList = new ArrayList<>();
  15.  
  16.     for (Integer vehicleId: vehicleIds) {
  17.         populateEachVehicleDetail(datasetId, vehicleId, vehiclesList, latch);
  18.     }
  19.  
  20.     latch.await();
  21.  
  22.     return vehiclesList;
  23. }
  24.  
  25. private void populateEachVehicleDetail(String datasetId, Integer vehicleId, List<VehicleResponse> vehiclesList, CountDownLatch latch) throws ApiException {
  26.  
  27.     ApiCallback<VehicleResponse> vehicleResponseApiCallback = new ApiCallback<VehicleResponse>() {
  28.         @Override
  29.         synchronized public void onSuccess(VehicleResponse result, int statusCode, Map<String, List<String>> responseHeaders) {
  30.             vehiclesList.add(result);
  31.             latch.countDown();
  32.         }
  33.     };
  34.  
  35.     VehiclesApi vehiclesApi = new VehiclesApi();
  36.     vehiclesApi.vehiclesGetVehicleAsync(datasetId,vehicleId,vehicleResponseApiCallback);
  37.  
  38. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top