Skip to content

Commit db2d775

Browse files
author
Cameron Mace
authored
Fix sonarqube issues (#647)
* removed wiki to place docs in doc folder and fixed readme image * Removes some unused imports and corrected package names * More and more clean up * Added some direction test
1 parent 2bbe98d commit db2d775

12 files changed

Lines changed: 236 additions & 89 deletions

File tree

Lines changed: 125 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,140 @@
11
package com.mapbox.samples;
22

3-
import com.mapbox.directions.v5.DirectionsCriteria;
43
import com.mapbox.directions.v5.MapboxDirections;
54
import com.mapbox.directions.v5.models.DirectionsResponse;
65
import com.mapbox.geojson.Point;
76
import retrofit2.Call;
87
import retrofit2.Callback;
98
import retrofit2.Response;
109

10+
import java.io.IOException;
11+
1112
/**
12-
* Shows how to make a request using the minimum required params.
13+
* Shows how to make a directions request using some of the parameters offered.
1314
*/
14-
public class BasicDirections {
15-
public static void main(String[] args) {
16-
17-
// 1. Build the directions request using the provided builder.
18-
MapboxDirections directions = buildMapboxDirections();
19-
20-
directions.enqueueCall(new Callback<DirectionsResponse>() {
21-
@Override
22-
public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
23-
System.out.println(response.code());
24-
System.out.println(call.request().url());
25-
System.out.println(response.body().routes().get(0).legs().get(0).steps().get(0).maneuver().location().latitude());
26-
System.out.println(response.body().routes().get(0).distance());
27-
System.out.println(response.body().routes().get(0).routeOptions().profile());
28-
System.out.println(response.body().routes().get(0).routeOptions().alternatives());
29-
System.out.println(response.body().routes().get(0).routeOptions().user());
30-
System.out.println(response.body().routes().get(0).legs().get(0).steps().get(0).maneuver().toString());
31-
System.out.println(response.body().routes().get(0).legs().get(0).steps().get(0)
32-
.voiceInstructions().get(0).announcement());
33-
System.out.println(response.body().routes().get(0).legs().get(0).annotation().congestion().size());
34-
System.out.println("Distance: " + response.body().routes().get(0).legs().get(0).steps().get(0).bannerInstructions().get(0).distanceAlongGeometry());
35-
}
36-
37-
@Override
38-
public void onFailure(Call<DirectionsResponse> call, Throwable throwable) {
39-
System.out.println(call.request().url());
40-
System.out.println(throwable);
41-
}
42-
});
15+
public class BasicDirections implements Callback<DirectionsResponse> {
16+
17+
public static void main(String[] args) throws IOException {
18+
19+
buildMapboxDirectionsRequest();
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
33+
}
34+
35+
private static void buildMapboxDirectionsRequest() throws IOException {
36+
37+
MapboxDirections.Builder builder = MapboxDirections.builder();
38+
39+
// 1. Pass in all the required information to get a simple directions route.
40+
builder.accessToken("pk.eyJ1IjoiY2FtbWFjZSIsImEiOiI5OGQxZjRmZGQ2YjU3Mzk1YjJmZTQ5ZDY2MTg1NDJiOCJ9.hIFoCKGAGOwQkKyVPvrxvQ");
41+
builder.origin(Point.fromLngLat(-95.6332, 29.7890));
42+
builder.destination(Point.fromLngLat(-95.3591, 29.7576));
43+
44+
// 2. That's it! Now execute the command and get the response.
45+
Response<DirectionsResponse> response = builder.build().executeCall();
46+
47+
// 3. Log information from the response
48+
System.out.println("Check that the response is successful" + response.isSuccessful());
49+
System.out.println(("Get the first routes distance from origin to destination: "
50+
+ response.body().routes().get(0).distance()));
51+
52+
53+
54+
//
55+
//
56+
//
57+
//
58+
//
59+
// return MapboxDirections.builder()
60+
// .origin(Point.fromLngLat(-95.6332, 29.7890))
61+
// .destination(Point.fromLngLat(-95.3591, 29.7576))
62+
// .bannerInstructions(true)
63+
// .voiceInstructions(true)
64+
// .annotations(DirectionsCriteria.ANNOTATION_CONGESTION)
65+
// .overview(DirectionsCriteria.OVERVIEW_FULL)
66+
// .addBearing(null, null)
67+
// .radiuses(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY)
68+
// .steps(true)
69+
// .build();
70+
}
71+
72+
73+
@Override
74+
public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
75+
4376
}
4477

45-
private static MapboxDirections buildMapboxDirections() {
46-
return MapboxDirections.builder()
47-
.accessToken("pk.eyJ1IjoiY2FtbWFjZSIsImEiOiI5OGQxZjRmZGQ2YjU3Mzk1YjJmZTQ5ZDY2MTg1NDJiOCJ9.hIFoCKGAGOwQkKyVPvrxvQ")
48-
.origin(Point.fromLngLat(-95.6332, 29.7890))
49-
.destination(Point.fromLngLat(-95.3591, 29.7576))
50-
.bannerInstructions(true)
51-
.voiceInstructions(true)
52-
.annotations(DirectionsCriteria.ANNOTATION_CONGESTION)
53-
.overview(DirectionsCriteria.OVERVIEW_FULL)
54-
.addBearing(null, null)
55-
.radiuses(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY)
56-
.steps(true)
57-
// .voiceUnits(DirectionsCriteria.METRIC)
58-
.build();
78+
@Override
79+
public void onFailure(Call<DirectionsResponse> call, Throwable t) {
80+
5981
}
6082
}
83+
84+
85+
86+
87+
88+
89+
90+
91+
92+
93+
94+
95+
96+
97+
98+
99+
100+
101+
102+
103+
104+
105+
106+
107+
108+
109+
110+
111+
//
112+
//
113+
//
114+
// // 1. Build the directions request using the provided builder.
115+
// MapboxDirections directions = buildMapboxDirections();
116+
//
117+
//// 2. Use either
118+
// directions.enqueueCall(new Callback<DirectionsResponse>() {
119+
//@Override
120+
//public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
121+
// System.out.println(response.code());
122+
// System.out.println(call.request().url());
123+
// System.out.println(response.body().routes().get(0).legs().get(0).steps().get(0).maneuver().location().latitude());
124+
// System.out.println(response.body().routes().get(0).distance());
125+
// System.out.println(response.body().routes().get(0).routeOptions().profile());
126+
// System.out.println(response.body().routes().get(0).routeOptions().alternatives());
127+
// System.out.println(response.body().routes().get(0).routeOptions().user());
128+
// System.out.println(response.body().routes().get(0).legs().get(0).steps().get(0).maneuver().toString());
129+
// System.out.println(response.body().routes().get(0).legs().get(0).steps().get(0)
130+
// .voiceInstructions().get(0).announcement());
131+
// System.out.println(response.body().routes().get(0).legs().get(0).annotation().congestion().size());
132+
// System.out.println("Distance: " + response.body().routes().get(0).legs().get(0).steps().get(0).bannerInstructions().get(0).distanceAlongGeometry());
133+
// }
134+
//
135+
//@Override
136+
//public void onFailure(Call<DirectionsResponse> call, Throwable throwable) {
137+
// System.out.println(call.request().url());
138+
// System.out.println(throwable);
139+
// }
140+
// });

services-core/src/main/java/com/mapbox/services/utils/TextUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.math.RoundingMode;
44
import java.text.DecimalFormat;
55
import java.text.DecimalFormatSymbols;
6-
import java.util.Arrays;
76
import java.util.List;
87
import java.util.Locale;
98

services-directions/src/main/java/com/mapbox/directions/v5/MapboxDirections.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
package com.mapbox.directions.v5;
22

3+
import java.io.IOException;
4+
import java.lang.annotation.Annotation;
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
import java.util.Locale;
8+
import java.util.logging.Level;
9+
import java.util.logging.Logger;
10+
311
import android.support.annotation.FloatRange;
412
import android.support.annotation.NonNull;
513
import android.support.annotation.Nullable;
@@ -30,14 +38,6 @@
3038
import retrofit2.Retrofit;
3139
import retrofit2.converter.gson.GsonConverterFactory;
3240

33-
import java.io.IOException;
34-
import java.lang.annotation.Annotation;
35-
import java.util.ArrayList;
36-
import java.util.List;
37-
import java.util.Locale;
38-
import java.util.logging.Level;
39-
import java.util.logging.Logger;
40-
4141
/**
4242
* The Directions API allows the calculation of routes between coordinates. The fastest route can be
4343
* returned with geometries, turn-by-turn instructions, and much more. The Mapbox Directions API
@@ -58,7 +58,7 @@
5858
@AutoValue
5959
public abstract class MapboxDirections extends MapboxService<DirectionsResponse> {
6060

61-
private static final Logger logger = Logger.getLogger(MapboxDirections.class.getName());
61+
private static final Logger LOGGER = Logger.getLogger(MapboxDirections.class.getName());
6262

6363
private okhttp3.Call.Factory callFactory;
6464
private Call<DirectionsResponse> call;
@@ -134,8 +134,6 @@ public Response<DirectionsResponse> executeCall() throws IOException {
134134
Response<DirectionsResponse> response = getCall().execute();
135135
if (!response.isSuccessful()) {
136136
errorDidOccur(null, response);
137-
} else {
138-
return Response.success(response.body(), response.headers());
139137
}
140138
List<DirectionsRoute> routes = response.body().routes();
141139
return Response.success(response.body().toBuilder().routes(
@@ -158,8 +156,6 @@ public void onResponse(Call<DirectionsResponse> call, Response<DirectionsRespons
158156
if (!response.isSuccessful()) {
159157
errorDidOccur(callback, response);
160158
return;
161-
162-
// TODO test whether routes an empty list is created or null
163159
} else if (response.body() == null || response.body().routes().isEmpty()) {
164160
// If null just pass the original object back since there's nothing to modify.
165161
callback.onResponse(call, response);
@@ -178,7 +174,7 @@ public void onFailure(Call<DirectionsResponse> call, Throwable throwable) {
178174

179175
private void errorDidOccur(@Nullable Callback<DirectionsResponse> callback,
180176
@NonNull Response<DirectionsResponse> response) {
181-
// Response gave an error, we try to logger any messages into the logger here.
177+
// Response gave an error, we try to LOGGER any messages into the LOGGER here.
182178
Converter<ResponseBody, DirectionsError> errorConverter =
183179
retrofit.responseBodyConverter(DirectionsError.class, new Annotation[0]);
184180
if (callback == null) {
@@ -188,7 +184,7 @@ private void errorDidOccur(@Nullable Callback<DirectionsResponse> callback,
188184
callback.onFailure(call,
189185
new Throwable(errorConverter.convert(response.errorBody()).message()));
190186
} catch (IOException ioException) {
191-
logger.log(Level.WARNING, "Failed to complete your request. ", ioException);
187+
LOGGER.log(Level.WARNING, "Failed to complete your request. ", ioException);
192188
}
193189
}
194190

@@ -658,6 +654,13 @@ public Builder radiuses(@FloatRange(from = 0) double... radiuses) {
658654
*/
659655
public abstract Builder bannerInstructions(@Nullable Boolean bannerInstructions);
660656

657+
/**
658+
* Specify what unit you'd like voice and banner instructions to use.
659+
*
660+
* @param voiceUnits either Imperial (default) or Metric
661+
* @return this builder for chaining options together
662+
* @since 3.0.0
663+
*/
661664
public abstract Builder voiceUnits(@Nullable @VoiceUnitCriteria String voiceUnits);
662665

663666
/**

services-directions/src/main/java/com/mapbox/directions/v5/models/StepManeuver.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.mapbox.directions.v5.models;
22

33
import android.support.annotation.FloatRange;
4-
import android.support.annotation.NonNull;
54
import android.support.annotation.Nullable;
65
import com.google.auto.value.AutoValue;
76
import com.google.gson.Gson;

0 commit comments

Comments
 (0)