Skip to content

Commit 874a4b0

Browse files
committed
Update GHMRequest for curbside
1 parent de47919 commit 874a4b0

File tree

3 files changed

+66
-8
lines changed

3 files changed

+66
-8
lines changed

client-hc/src/main/java/com/graphhopper/api/GHMRequest.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public class GHMRequest extends GHRequest {
1818
private List<GHPoint> toPoints;
1919
private List<String> fromPointHints;
2020
private List<String> toPointHints;
21+
private List<String> fromCurbSides;
22+
private List<String> toCurbSides;
2123
private int called = 0;
2224
boolean identicalLists = true;
2325
private final Set<String> outArrays = new HashSet<>(5);
@@ -33,6 +35,8 @@ public GHMRequest(int size) {
3335
toPoints = new ArrayList<>(size);
3436
fromPointHints = new ArrayList<>(size);
3537
toPointHints = new ArrayList<>(size);
38+
fromCurbSides = new ArrayList<>(size);
39+
toCurbSides = new ArrayList<>(size);
3640
}
3741

3842
/**
@@ -105,6 +109,20 @@ public List<String> getFromPointHints() {
105109
return fromPointHints;
106110
}
107111

112+
public GHMRequest addFromCurbSide(String curbSide) {
113+
fromCurbSides.add(curbSide);
114+
return this;
115+
}
116+
117+
public GHMRequest setFromCurbSides(List<String> curbSides) {
118+
fromCurbSides = curbSides;
119+
return this;
120+
}
121+
122+
public List<String> getFromCurbSides() {
123+
return fromCurbSides;
124+
}
125+
108126
public GHMRequest addToPoint(GHPoint point) {
109127
toPoints.add(point);
110128
identicalLists = false;
@@ -131,6 +149,20 @@ public List<String> getToPointHints() {
131149
return toPointHints;
132150
}
133151

152+
public GHMRequest addToCurbSide(String curbSide) {
153+
toCurbSides.add(curbSide);
154+
return this;
155+
}
156+
157+
public GHMRequest setToCurbSides(List<String> curbSides) {
158+
toCurbSides = curbSides;
159+
return this;
160+
}
161+
162+
public List<String> getToCurbSides() {
163+
return toCurbSides;
164+
}
165+
134166
@Override
135167
public GHRequest setPointHints(List<String> pointHints) {
136168
this.fromPointHints = pointHints;
@@ -149,6 +181,24 @@ public boolean hasPointHints() {
149181
this.toPointHints.size() == this.toPoints.size() && !toPoints.isEmpty();
150182
}
151183

184+
@Override
185+
public GHRequest setCurbSides(List<String> curbSides) {
186+
fromCurbSides = curbSides;
187+
toCurbSides = curbSides;
188+
return this;
189+
}
190+
191+
@Override
192+
public List<String> getCurbSides() {
193+
throw new IllegalStateException("Use getFromCurbSides or getToCurbSides");
194+
}
195+
196+
@Override
197+
public boolean hasCurbSides() {
198+
return fromCurbSides.size() == fromPoints.size() && !fromPoints.isEmpty() &&
199+
toCurbSides.size() == toPoints.size() && !toPoints.isEmpty();
200+
}
201+
152202
/**
153203
* @param failFast if false the matrix calculation will be continued even when some points are not connected
154204
*/

client-hc/src/main/java/com/graphhopper/api/GHMatrixBatchRequester.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,17 @@ public MatrixResponse route(GHMRequest ghRequest) {
7171
if (ghRequest.identicalLists) {
7272
requestJson.putArray("points").addAll(createPointList(ghRequest.getFromPoints()));
7373
requestJson.putArray("point_hints").addAll(createStringList(ghRequest.getFromPointHints()));
74+
requestJson.putArray("curbsides").addAll(createStringList(ghRequest.getFromCurbSides()));
7475
} else {
7576
ArrayNode fromPointList = createPointList(ghRequest.getFromPoints());
7677
ArrayNode toPointList = createPointList(ghRequest.getToPoints());
7778
requestJson.putArray("from_points").addAll(fromPointList);
7879
requestJson.putArray("from_point_hints").addAll(createStringList(ghRequest.getFromPointHints()));
7980
requestJson.putArray("to_points").addAll(toPointList);
8081
requestJson.putArray("to_point_hints").addAll(createStringList(ghRequest.getToPointHints()));
82+
// todonow: there should be some kind of test
83+
requestJson.putArray("from_curbsides").addAll(createStringList(ghRequest.getFromCurbSides()));
84+
requestJson.putArray("to_curbsides").addAll(createStringList(ghRequest.getToPointHints()));
8185
}
8286

8387
requestJson.putArray("out_arrays").addAll(outArrayListJson);
@@ -168,9 +172,7 @@ public MatrixResponse route(GHMRequest ghRequest) {
168172
throw new IllegalStateException("Maximum number of iterations reached " + maxIterations + ", increasing should only be necessary for big matrices. For smaller ones this is a bug, please contact us");
169173
}
170174

171-
} catch (InterruptedException ex) {
172-
throw new RuntimeException(ex);
173-
} catch (IOException ex) {
175+
} catch (InterruptedException | IOException ex) {
174176
throw new RuntimeException(ex);
175177
}
176178

client-hc/src/main/java/com/graphhopper/api/GHMatrixSyncRequester.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,20 @@ private void initIgnore() {
4747
public MatrixResponse route(GHMRequest ghRequest) {
4848
String pointsStr;
4949
String pointHintsStr;
50+
String curbSidesStr;
5051
if (ghRequest.identicalLists) {
51-
pointsStr = createPointQuery(ghRequest.getFromPoints(), "point");
52+
pointsStr = createPointQuery("point", ghRequest.getFromPoints());
5253
pointHintsStr = createUrlString("point_hint", ghRequest.getFromPointHints());
54+
curbSidesStr = createUrlString("curbside", ghRequest.getFromCurbSides());
5355
} else {
54-
pointsStr = createPointQuery(ghRequest.getFromPoints(), "from_point");
55-
pointsStr += "&" + createPointQuery(ghRequest.getToPoints(), "to_point");
56+
pointsStr = createPointQuery("from_point", ghRequest.getFromPoints());
57+
pointsStr += "&" + createPointQuery("to_point", ghRequest.getToPoints());
5658

5759
pointHintsStr = createUrlString("from_point_hint", ghRequest.getFromPointHints());
5860
pointHintsStr += "&" + createUrlString("to_point_hint", ghRequest.getToPointHints());
61+
62+
curbSidesStr = createUrlString("from_curbside", ghRequest.getFromCurbSides());
63+
curbSidesStr += "&" + createUrlString("to_curbside", ghRequest.getToCurbSides());
5964
}
6065

6166
String outArrayStr = "";
@@ -73,7 +78,8 @@ public MatrixResponse route(GHMRequest ghRequest) {
7378
}
7479

7580
String url = buildURL("", ghRequest);
76-
url += "&" + pointsStr + "&" + pointHintsStr + "&" + outArrayStr;
81+
// todonow: there should be some kind of test
82+
url += "&" + pointsStr + "&" + pointHintsStr + "&" + curbSidesStr + "&" + outArrayStr;
7783
if (!Helper.isEmpty(ghRequest.getVehicle())) {
7884
url += "&vehicle=" + ghRequest.getVehicle();
7985
}
@@ -115,7 +121,7 @@ private String createUrlString(String paramName, List<String> params) {
115121
return result.toString();
116122
}
117123

118-
private String createPointQuery(List<GHPoint> list, String pointName) {
124+
private String createPointQuery(String pointName, List<GHPoint> list) {
119125
StringBuilder pointsStr = new StringBuilder();
120126
for (GHPoint p : list) {
121127
if (pointsStr.length() > 0)

0 commit comments

Comments
 (0)