Class ReachabilityResponse

java.lang.Object
com.targomo.client.api.response.ReachabilityResponse

public class ReachabilityResponse extends Object
  • Constructor Details

    • ReachabilityResponse

      public ReachabilityResponse(TravelOptions travelOptions, org.json.JSONObject result, long requestStart) throws ResponseErrorException
      Create a response from JSON results, using given travel options
      Parameters:
      travelOptions - travel options, from the request
      result - Travel times in JSON
      requestStart - Start time of execution
      Throws:
      ResponseErrorException
    • ReachabilityResponse

      public ReachabilityResponse(TravelOptions travelOptions, org.json.JSONObject result, long requestStart, java.util.function.Function<String,String> targetIdMapperFilter) throws ResponseErrorException
      Create a response from JSON results, using given travel options. If cached targets are used that are shared among multiple statistics it may be necessary to filter the targets and map their ids. To improve performance this can be done while parsing the response by passing a mapper/filter function.
      Parameters:
      travelOptions - travel options, from the request
      result - Travel times in JSON
      requestStart - Start time of execution
      targetIdMapperFilter - a function that maps the target id to a different value or filters targets by returning null.
      Throws:
      ResponseErrorException
    • ReachabilityResponse

      public ReachabilityResponse(TravelOptions travelOptions, ResponseCode code, long requestTime, long requestStart)
      Create a response with custom response code and without results. Can be used in case of errors.
      Parameters:
      travelOptions - Travel options used in request
      code - Response code
      requestTime - Execution time in milliseconds
      requestStart - Start time of execution
    • ReachabilityResponse

      public ReachabilityResponse(TravelOptions travelOptions, ResponseCode code, long requestTimeMillis, long totalTimeMillis, String message)
  • Method Details

    • mapResults

      protected void mapResults(org.json.JSONObject result, java.util.function.Function<String,String> targetIdMapperFilter)
      Parse results in JSON to travel times map. Applies the given function to each target id to modify the id or filter the target.
      Parameters:
      result - resulting JSON
      targetIdMapperFilter - a function that maps the target id to a different value or filters targets by returning null.
    • addTravelTime

      public void addTravelTime(String targetId, Integer travelTime)
      Add travel time to a target
      Parameters:
      targetId - Target ID
      travelTime - Travel time for the target
    • addClosestSource

      public void addClosestSource(String targetId, String closestSourceId)
    • getCode

      public ResponseCode getCode()
      Returns:
      the code
    • getRequestTimeMillis

      public long getRequestTimeMillis()
      Returns:
      the requestTimeMillis
    • getTravelOptions

      public TravelOptions getTravelOptions()
      Returns:
      the travelOptions
    • getTravelTimes

      public Map<String,Integer> getTravelTimes()
      Map of source IDs - travel times
      Returns:
      travel time map
    • getClosestSourceIds

      public Map<String,String> getClosestSourceIds()
      Map of target IDs to the individual closest source ID
      Returns:
      target id - source id
    • getTotalTime

      public long getTotalTime()
      Get total time in milliseconds
      Returns:
      total time
    • getMessage

      public String getMessage()
    • getClosestSourceForTarget

      public String getClosestSourceForTarget(String targetId)