@@ -89,29 +89,24 @@ public MatrixResponse route(GHMRequest ghRequest) {
89
89
outArraysList .add ("weights" );
90
90
}
91
91
92
- ArrayNode outArrayListJson = objectMapper .createArrayNode ();
93
- for (String str : outArraysList ) {
94
- outArrayListJson .add (str );
95
- }
96
-
97
92
boolean hasElevation = false ;
98
93
if (ghRequest .identicalLists ) {
99
- requestJson . putArray ( "points" ). addAll ( createPointList ( ghRequest .getFromPoints () ));
100
- requestJson . putArray ( "point_hints" ). addAll ( createStringList ( ghRequest .getFromPointHints () ));
101
- requestJson . putArray ( "curbsides" ). addAll ( createStringList ( ghRequest .getFromCurbsides () ));
94
+ createPointArray ( requestJson , "points" , ghRequest .getFromPoints ());
95
+ createStringArray ( requestJson , "point_hints" , ghRequest .getFromPointHints ());
96
+ createStringArray ( requestJson , "curbsides" , ghRequest .getFromCurbsides ());
102
97
} else {
103
- ArrayNode fromPointList = createPointList ( ghRequest .getFromPoints ());
104
- ArrayNode toPointList = createPointList ( ghRequest .getToPoints ());
105
- requestJson . putArray ( "from_points" ). addAll ( fromPointList );
106
- requestJson . putArray ( "from_point_hints" ). addAll ( createStringList ( ghRequest .getFromPointHints () ));
107
- requestJson . putArray ( "to_points" ). addAll ( toPointList );
108
- requestJson . putArray ( "to_point_hints" ). addAll ( createStringList ( ghRequest . getToPointHints ()));
109
- requestJson . putArray ( "from_curbsides" ). addAll ( createStringList ( ghRequest .getFromCurbsides () ));
110
- requestJson . putArray ( "to_curbsides" ). addAll ( createStringList ( ghRequest .getToPointHints () ));
98
+ createPointArray ( requestJson , "from_points" , ghRequest .getFromPoints ());
99
+ createStringArray ( requestJson , "from_point_hints" , ghRequest .getFromPointHints ());
100
+
101
+ createPointArray ( requestJson , "to_points" , ghRequest .getToPoints ( ));
102
+ createStringArray ( requestJson , "to_point_hints" , ghRequest . getToPointHints () );
103
+
104
+ createStringArray ( requestJson , "from_curbsides" , ghRequest .getFromCurbsides ());
105
+ createStringArray ( requestJson , "to_curbsides" , ghRequest .getToCurbsides ( ));
111
106
}
112
107
113
- requestJson . putArray ( "snap_preventions" ). addAll ( createStringList ( ghRequest .getSnapPreventions () ));
114
- requestJson . putArray ( "out_arrays" ). addAll ( outArrayListJson );
108
+ createStringArray ( requestJson , "snap_preventions" , ghRequest .getSnapPreventions ());
109
+ createStringArray ( requestJson , "out_arrays" , outArraysList );
115
110
requestJson .put ("vehicle" , ghRequest .getVehicle ());
116
111
requestJson .put ("elevation" , hasElevation );
117
112
requestJson .put ("fail_fast" , ghRequest .getFailFast ());
@@ -222,22 +217,26 @@ protected String postJson(String url, JsonNode data) throws IOException {
222
217
}
223
218
}
224
219
225
- private ArrayNode createStringList (List <String > list ) {
220
+ private void createStringArray (ObjectNode requestJson , String name , List <String > stringList ) {
221
+ if (stringList .isEmpty ())
222
+ return ;
226
223
ArrayNode outList = objectMapper .createArrayNode ();
227
- for (String str : list ) {
224
+ for (String str : stringList ) {
228
225
outList .add (str );
229
226
}
230
- return outList ;
227
+ requestJson . putArray ( name ). addAll ( outList ) ;
231
228
}
232
229
233
- private ArrayNode createPointList (List <GHPoint > list ) {
230
+ private void createPointArray (ObjectNode requestJson , String name , List <GHPoint > pList ) {
231
+ if (pList .isEmpty ())
232
+ return ;
234
233
ArrayNode outList = objectMapper .createArrayNode ();
235
- for (GHPoint p : list ) {
234
+ for (GHPoint p : pList ) {
236
235
ArrayNode entry = objectMapper .createArrayNode ();
237
236
entry .add (p .lon );
238
237
entry .add (p .lat );
239
238
outList .add (entry );
240
239
}
241
- return outList ;
240
+ requestJson . putArray ( name ). addAll ( outList ) ;
242
241
}
243
242
}
0 commit comments