Package com.targomo.client.api.response
Class ReachabilityResponse
java.lang.Object
com.targomo.client.api.response.ReachabilityResponse
-
Constructor Summary
ConstructorsConstructorDescriptionReachabilityResponse(TravelOptions travelOptions, ResponseCode code, long requestTime, long requestStart) Create a response with custom response code and without results.ReachabilityResponse(TravelOptions travelOptions, ResponseCode code, long requestTimeMillis, long totalTimeMillis, String message) ReachabilityResponse(TravelOptions travelOptions, org.json.JSONObject result, long requestStart) Create a response from JSON results, using given travel optionsReachabilityResponse(TravelOptions travelOptions, org.json.JSONObject result, long requestStart, java.util.function.Function<String, String> targetIdMapperFilter) Create a response from JSON results, using given travel options. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddClosestSource(String targetId, String closestSourceId) voidaddTravelTime(String targetId, Integer travelTime) Add travel time to a targetgetClosestSourceForTarget(String targetId) Map of target IDs to the individual closest source IDgetCode()longlongGet total time in millisecondsMap of source IDs - travel timesprotected voidmapResults(org.json.JSONObject result, java.util.function.Function<String, String> targetIdMapperFilter) Parse results in JSON to travel times map.
-
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 requestresult- Travel times in JSONrequestStart- 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 ResponseErrorExceptionCreate 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 requestresult- Travel times in JSONrequestStart- Start time of executiontargetIdMapperFilter- 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 requestcode- Response coderequestTime- Execution time in millisecondsrequestStart- 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 JSONtargetIdMapperFilter- a function that maps the target id to a different value or filters targets by returning null.
-
addTravelTime
Add travel time to a target- Parameters:
targetId- Target IDtravelTime- Travel time for the target
-
addClosestSource
-
getCode
- Returns:
- the code
-
getRequestTimeMillis
public long getRequestTimeMillis()- Returns:
- the requestTimeMillis
-
getTravelOptions
- Returns:
- the travelOptions
-
getTravelTimes
Map of source IDs - travel times- Returns:
- travel time map
-
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
-
getClosestSourceForTarget
-