Skip to content

Commit 51fb820

Browse files
committed
Replaces org.apache.commons:commons-lang3 with TextUtils subset (#44)
1 parent 6ef36c8 commit 51fb820

5 files changed

Lines changed: 49 additions & 14 deletions

File tree

libjava/lib/build.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ dependencies {
99
compile 'com.squareup.retrofit2:converter-gson:2.0.1'
1010
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.1'
1111

12-
// Apache commons for StringUtils
13-
compile 'org.apache.commons:commons-lang3:3.4'
14-
1512
// Testing
1613
testCompile 'junit:junit:4.12'
1714
testCompile 'org.hamcrest:hamcrest-junit:2.0.0.0'

libjava/lib/src/main/java/com/mapbox/services/commons/utils/MapboxUtils.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.mapbox.services.commons.utils;
22

3-
import org.apache.commons.lang3.StringUtils;
4-
53
/**
64
* Misc utils around Mapbox services.
75
*/
@@ -16,7 +14,7 @@ public class MapboxUtils {
1614
* @return true if the provided access token is valid, false otherwise.
1715
*/
1816
public static boolean isAccessTokenValid(String accessToken) {
19-
if (StringUtils.isEmpty(accessToken)) return false;
17+
if (TextUtils.isEmpty(accessToken)) return false;
2018
if (!accessToken.startsWith("pk.") && !accessToken.startsWith("sk.")) return false;
2119
return true;
2220
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.mapbox.services.commons.utils;
2+
3+
/**
4+
* Some code from https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/text/TextUtils.java
5+
*
6+
* We avoid including a full library like org.apache.commons:commons-lang3 to avoid
7+
* an unnecessary large number of methods, which is inconvenient to Android devs.
8+
*/
9+
public class TextUtils {
10+
11+
/**
12+
* Returns true if the string is null or 0-length.
13+
* @param str the string to be examined
14+
* @return true if str is null or zero length
15+
*/
16+
public static boolean isEmpty(CharSequence str) {
17+
if (str == null || str.length() == 0)
18+
return true;
19+
else
20+
return false;
21+
}
22+
23+
/**
24+
* Returns a string containing the tokens joined by delimiters.
25+
* @param tokens an array objects to be joined. Strings will be formed from
26+
* the objects by calling object.toString().
27+
*/
28+
public static String join(CharSequence delimiter, Object[] tokens) {
29+
StringBuilder sb = new StringBuilder();
30+
boolean firstTime = true;
31+
for (Object token: tokens) {
32+
if (firstTime) {
33+
firstTime = false;
34+
} else {
35+
sb.append(delimiter);
36+
}
37+
sb.append(token);
38+
}
39+
return sb.toString();
40+
}
41+
42+
}

libjava/lib/src/main/java/com/mapbox/services/directions/v4/MapboxDirections.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
import com.mapbox.services.commons.MapboxBuilder;
55
import com.mapbox.services.commons.MapboxService;
66
import com.mapbox.services.commons.ServicesException;
7+
import com.mapbox.services.commons.utils.TextUtils;
78
import com.mapbox.services.directions.v4.models.DirectionsResponse;
89
import com.mapbox.services.directions.v4.models.Waypoint;
910

10-
import org.apache.commons.lang3.StringUtils;
11-
1211
import java.io.IOException;
1312
import java.util.ArrayList;
1413
import java.util.Arrays;
@@ -266,7 +265,7 @@ public String getWaypoints() {
266265
}
267266

268267
// The waypoints parameter should be a semicolon-separated list of locations to visit
269-
waypointsFormatted = StringUtils.join(pieces, ";");
268+
waypointsFormatted = TextUtils.join(";", pieces.toArray());
270269
return waypointsFormatted;
271270
}
272271

libjava/lib/src/main/java/com/mapbox/services/directions/v5/MapboxDirections.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
import com.mapbox.services.commons.ServicesException;
77
import com.mapbox.services.commons.models.Bearing;
88
import com.mapbox.services.commons.models.Position;
9+
import com.mapbox.services.commons.utils.TextUtils;
910
import com.mapbox.services.directions.v5.models.DirectionsResponse;
1011

11-
import org.apache.commons.lang3.StringUtils;
12-
1312
import java.io.IOException;
1413
import java.util.ArrayList;
1514
import java.util.List;
@@ -292,7 +291,7 @@ public String getCoordinates() {
292291
coordinate.getLatitude()));
293292
}
294293

295-
return StringUtils.join(coordinatesFormatted, ";");
294+
return TextUtils.join(";", coordinatesFormatted.toArray());
296295
}
297296

298297
@Override
@@ -324,7 +323,7 @@ public String getBearings() {
324323
bearings[i].getRange());
325324
}
326325

327-
return StringUtils.join(bearingsFormatted, ";");
326+
return TextUtils.join(";", bearingsFormatted);
328327
}
329328

330329
public String getGeometries() {
@@ -355,7 +354,7 @@ public String getRadiuses() {
355354
radiusesFormatted[i] = String.format(Locale.US, "%f", radiuses[i]);
356355
}
357356

358-
return StringUtils.join(radiusesFormatted, ";");
357+
return TextUtils.join(";", radiusesFormatted);
359358
}
360359

361360
public Boolean isSteps() {

0 commit comments

Comments
 (0)