-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
GraphHopperMatrixWeb.java
46 lines (37 loc) · 1.31 KB
/
GraphHopperMatrixWeb.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.graphhopper.api;
import com.graphhopper.util.Helper;
import okhttp3.MediaType;
/**
* @author Peter Karich
*/
public class GraphHopperMatrixWeb {
static final String SERVICE_URL = "service_url";
public static final String KEY = "key";
static final MediaType MT_JSON = MediaType.parse("application/json; charset=utf-8");
private final GHMatrixAbstractRequester requester;
private String key;
public GraphHopperMatrixWeb() {
this(new GHMatrixBatchRequester());
}
public GraphHopperMatrixWeb(String serviceUrl) {
this(new GHMatrixBatchRequester(serviceUrl));
}
public GraphHopperMatrixWeb(GHMatrixAbstractRequester requester) {
this.requester = requester;
}
public GraphHopperMatrixWeb setKey(String key) {
if (key == null || key.isEmpty()) {
throw new IllegalStateException("Key cannot be empty");
}
this.key = key;
return this;
}
public MatrixResponse route(GHMRequest request) {
if (!Helper.isEmpty(key))
request.getHints().put(KEY, key);
if (!request.getPathDetails().isEmpty())
throw new IllegalArgumentException("Path details are not supported for the Matrix API");
request.compactPointHints();
return requester.route(request);
}
}