Skip to content

Commit fea0fc1

Browse files
author
“osana”
committed
removed dependency of Turf library on services-core
1 parent 82837f3 commit fea0fc1

21 files changed

Lines changed: 296 additions & 79 deletions

File tree

services-core/build.gradle

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ dependencies {
4949
// OkHttp
5050
api dependenciesList.okhttp3Logging
5151

52-
// AutoValue
53-
compileOnly dependenciesList.autoValue
54-
compileOnly dependenciesList.autoValueGson
55-
5652
// Test Dependencies
5753
testOutput sourceSets.test.output
5854
}

services-core/src/test/java/com/mapbox/core/TestUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.util.Scanner;
1515

1616
import static java.nio.charset.StandardCharsets.UTF_8;
17-
import static org.junit.Assert.assertEquals;
1817
import static org.junit.Assert.assertThat;
1918
import static org.junit.Assert.assertTrue;
2019

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ public static Builder builder() {
6565
public abstract String name();
6666

6767
/**
68-
* Any road designations associated with the road or path leading from this step's
69-
* maneuver to the next step's maneuver. Optionally included, if data is available.
68+
* Any road designations associated with the road or path leading from this step's
69+
* maneuver to the next step's maneuver. Optionally included, if data is available.
7070
* If multiple road designations are associated with the road, they are separated by semicolons.
7171
* A road designation typically consists of an alphabetic network code (identifying the road type
7272
* or numbering system), a space or hyphen, and a route number. You should not assume that

services-geojson/build.gradle

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ dependencies {
1111
// Annotations
1212
compileOnly dependenciesList.supportAnnotation
1313

14-
// AutoValue
15-
compileOnly dependenciesList.autoValue
16-
compileOnly dependenciesList.autoValueGson
17-
1814
// Test Dependencies
1915
testImplementation dependenciesList.okhttp3Mockwebserver
2016
testImplementation project(path: ':services-core', configuration: 'testOutput')
21-
testImplementation project(":services-turf")
2217
}

services-geojson/src/test/java/com/mapbox/geojson/LineStringTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
import static org.junit.Assert.assertNotNull;
66
import static org.junit.Assert.assertNull;
77

8-
import com.mapbox.core.TestUtils;
9-
import com.mapbox.core.constants.Constants;
10-
118
import org.junit.Rule;
129
import org.junit.Test;
1310
import org.junit.rules.ExpectedException;
@@ -20,6 +17,9 @@ public class LineStringTest extends TestUtils {
2017

2118
private static final String SAMPLE_LINESTRING_FIXTURE = "sample-linestring.json";
2219

20+
private static final int PRECISION_6 = 6;
21+
private static final int PRECISION_5 = 5;
22+
2323
@Rule
2424
public ExpectedException thrown = ExpectedException.none();
2525

@@ -40,7 +40,7 @@ public void fromLngLats_generatedFromMultipoint() throws Exception {
4040
points.add(Point.fromLngLat(4.0,8.0));
4141
MultiPoint multiPoint = MultiPoint.fromLngLats(points);
4242
LineString lineString = LineString.fromLngLats(multiPoint);
43-
assertEquals("_gayB_c`|@_wemJ_kbvD", lineString.toPolyline(Constants.PRECISION_6));
43+
assertEquals("_gayB_c`|@_wemJ_kbvD", lineString.toPolyline(PRECISION_6));
4444
}
4545

4646
@Test

services-geojson/src/test/java/com/mapbox/geojson/MultiLineStringTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import static org.junit.Assert.assertNotNull;
66
import static org.junit.Assert.assertNull;
77

8-
import com.mapbox.core.TestUtils;
9-
108
import org.junit.Rule;
119
import org.junit.Test;
1210
import org.junit.rules.ExpectedException;
@@ -19,6 +17,9 @@ public class MultiLineStringTest extends TestUtils {
1917

2018
private static final String SAMPLE_MULTILINESTRING = "sample-multilinestring.json";
2119

20+
private static final int PRECISION_6 = 6;
21+
private static final int PRECISION_5 = 5;
22+
2223
@Rule
2324
public ExpectedException thrown = ExpectedException.none();
2425

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.mapbox.geojson;
2+
3+
import com.google.gson.JsonParser;
4+
5+
import org.hamcrest.Matchers;
6+
7+
import java.io.ByteArrayInputStream;
8+
import java.io.ByteArrayOutputStream;
9+
import java.io.IOException;
10+
import java.io.InputStream;
11+
import java.io.ObjectInputStream;
12+
import java.io.ObjectOutputStream;
13+
import java.io.Serializable;
14+
import java.util.Scanner;
15+
16+
import static java.nio.charset.StandardCharsets.UTF_8;
17+
import static org.junit.Assert.assertThat;
18+
import static org.junit.Assert.assertTrue;
19+
20+
public class TestUtils {
21+
22+
public static final double DELTA = 1E-10;
23+
public static final String ACCESS_TOKEN = "pk.XXX";
24+
25+
public void compareJson(String expectedJson, String actualJson) {
26+
JsonParser parser = new JsonParser();
27+
assertThat(parser.parse(actualJson), Matchers.equalTo(parser.parse(expectedJson)));
28+
}
29+
30+
protected String loadJsonFixture(String filename) throws IOException {
31+
ClassLoader classLoader = getClass().getClassLoader();
32+
InputStream inputStream = classLoader.getResourceAsStream(filename);
33+
Scanner scanner = new Scanner(inputStream, UTF_8.name()).useDelimiter("\\A");
34+
return scanner.hasNext() ? scanner.next() : "";
35+
}
36+
37+
public static <T extends Serializable> byte[] serialize(T obj)
38+
throws IOException {
39+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
40+
ObjectOutputStream oos = new ObjectOutputStream(baos);
41+
oos.writeObject(obj);
42+
oos.close();
43+
return baos.toByteArray();
44+
}
45+
46+
public static <T extends Serializable> T deserialize(byte[] bytes, Class<T> cl)
47+
throws IOException, ClassNotFoundException {
48+
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
49+
ObjectInputStream ois = new ObjectInputStream(bais);
50+
Object object = ois.readObject();
51+
return cl.cast(object);
52+
}
53+
54+
/**
55+
* Comes from Google Utils Test Case
56+
*/
57+
public static void expectNearNumber(double expected, double actual, double epsilon) {
58+
assertTrue(String.format("Expected %f to be near %f", actual, expected),
59+
Math.abs(expected - actual) <= epsilon);
60+
}
61+
}

services-geojson/src/test/java/com/mapbox/geojson/utils/PolylineUtilsTest.java

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
import static org.junit.Assert.assertNotNull;
88
import static org.junit.Assert.assertTrue;
99

10-
import com.mapbox.core.TestUtils;
11-
import com.mapbox.core.constants.Constants;
1210
import com.mapbox.geojson.LineString;
1311
import com.mapbox.geojson.Point;
12+
import com.mapbox.geojson.TestUtils;
13+
1414
import org.junit.Test;
1515

1616
import java.io.IOException;
@@ -20,6 +20,9 @@
2020

2121
public class PolylineUtilsTest extends TestUtils {
2222

23+
private static final int PRECISION_6 = 6;
24+
private static final int PRECISION_5 = 5;
25+
2326
// Delta for Coordinates comparison
2427
private static final double DELTA = 0.000001;
2528

@@ -34,7 +37,7 @@ public class PolylineUtilsTest extends TestUtils {
3437

3538
@Test
3639
public void testDecodePath() {
37-
List<Point> latLngs = decode(TEST_LINE, Constants.PRECISION_5);
40+
List<Point> latLngs = decode(TEST_LINE, PRECISION_5);
3841

3942
int expectedLength = 21;
4043
assertEquals("Wrong length.", expectedLength, latLngs.size());
@@ -46,15 +49,15 @@ public void testDecodePath() {
4649

4750
@Test
4851
public void testEncodePath5() {
49-
List<Point> path = decode(TEST_LINE, Constants.PRECISION_5);
50-
String encoded = encode(path, Constants.PRECISION_5);
52+
List<Point> path = decode(TEST_LINE, PRECISION_5);
53+
String encoded = encode(path, PRECISION_5);
5154
assertEquals(TEST_LINE, encoded);
5255
}
5356

5457
@Test
5558
public void testDecodeEncodePath6() {
56-
List<Point> path = decode(TEST_LINE6, Constants.PRECISION_6);
57-
String encoded = encode(path, Constants.PRECISION_6);
59+
List<Point> path = decode(TEST_LINE6, PRECISION_6);
60+
String encoded = encode(path, PRECISION_6);
5861
assertEquals(TEST_LINE6, encoded);
5962
}
6063

@@ -65,8 +68,8 @@ public void testFromPolyline6() {
6568
Point.fromLngLat(2.2862036, 48.8267868),
6669
Point.fromLngLat(2.4, 48.9)
6770
);
68-
String encoded = encode(originalPath, Constants.PRECISION_6);
69-
List<Point> path = LineString.fromPolyline(encoded, Constants.PRECISION_6).coordinates();
71+
String encoded = encode(originalPath, PRECISION_6);
72+
List<Point> path = LineString.fromPolyline(encoded, PRECISION_6).coordinates();
7073

7174
assertEquals(originalPath.size(), path.size());
7275
for (int i = 0; i < originalPath.size(); i++) {
@@ -78,8 +81,8 @@ public void testFromPolyline6() {
7881
@Test
7982
public void testFromPolylineAndDecode() {
8083

81-
List<Point> path1 = LineString.fromPolyline(TEST_LINE6, Constants.PRECISION_6).coordinates();
82-
List<Point> path2 = decode(TEST_LINE6, Constants.PRECISION_6);
84+
List<Point> path1 = LineString.fromPolyline(TEST_LINE6, PRECISION_6).coordinates();
85+
List<Point> path2 = decode(TEST_LINE6, PRECISION_6);
8386

8487
assertEquals(path1.size(), path2.size());
8588
for (int i = 0; i < path1.size(); i++) {
@@ -95,8 +98,8 @@ public void testEncodeDecodePath6() {
9598
Point.fromLngLat(2.4, 48.9)
9699
);
97100

98-
String encoded = encode(originalPath, Constants.PRECISION_6);
99-
List<Point> path = decode(encoded, Constants.PRECISION_6);
101+
String encoded = encode(originalPath, PRECISION_6);
102+
List<Point> path = decode(encoded, PRECISION_6);
100103
assertEquals(originalPath.size(), path.size());
101104

102105
for (int i = 0; i < originalPath.size(); i++) {
@@ -108,20 +111,20 @@ public void testEncodeDecodePath6() {
108111

109112
@Test
110113
public void decode_neverReturnsNullButRatherAnEmptyList() throws Exception {
111-
List<Point> path = decode("", Constants.PRECISION_5);
114+
List<Point> path = decode("", PRECISION_5);
112115
assertNotNull(path);
113116
assertEquals(0, path.size());
114117
}
115118

116119
@Test
117120
public void encode_neverReturnsNull() throws Exception {
118-
String encodedString = encode(new ArrayList<Point>(), Constants.PRECISION_6);
121+
String encodedString = encode(new ArrayList<Point>(), PRECISION_6);
119122
assertNotNull(encodedString);
120123
}
121124

122125
@Test
123126
public void simplify_neverReturnsNullButRatherAnEmptyList() throws Exception {
124-
List<Point> simplifiedPath = simplify(new ArrayList<Point>(), Constants.PRECISION_6);
127+
List<Point> simplifiedPath = simplify(new ArrayList<Point>(), PRECISION_6);
125128
assertNotNull(simplifiedPath);
126129
}
127130

@@ -130,14 +133,14 @@ public void simplify_returnSameListWhenListSizeIsLessThanOrEqualToTwo(){
130133
final List<Point> path = new ArrayList<>();
131134
path.add(Point.fromLngLat(0, 0));
132135
path.add(Point.fromLngLat(10, 0));
133-
List<Point> simplifiedPath = simplify(path, Constants.PRECISION_6, true);
136+
List<Point> simplifiedPath = simplify(path, PRECISION_6, true);
134137
assertTrue("Returned list is different from input list", path == simplifiedPath);
135138
}
136139

137140
@Test
138141
public void simplify_withHighestQuality() throws IOException{
139142
List<Point> path = createPointListFromResourceFile(SIMPLIFICATION_INPUT);
140-
List<Point> simplifiedPath = simplify(path, Constants.PRECISION_5, true);
143+
List<Point> simplifiedPath = simplify(path, PRECISION_5, true);
141144
List<Point> expectedSimplifiedPath = createPointListFromResourceFile(SIMPLIFICATION_EXPECTED_OUTPUT);
142145
assertTrue("Wrong number of points retained",simplifiedPath.size() == expectedSimplifiedPath.size());
143146
int counter = 0;

services-turf/build.gradle

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,8 @@ apply plugin: 'java-library'
55
apply from: "../gradle/dependencies.gradle"
66

77
dependencies {
8-
api project(":services-core")
98
api project(":services-geojson")
109

1110
// Annotations
1211
compileOnly dependenciesList.supportAnnotation
13-
14-
// AutoValue
15-
compileOnly dependenciesList.autoValue
16-
compileOnly dependenciesList.autoValueGson
17-
18-
// Test Dependencies
19-
testImplementation project(path: ':services-core', configuration: 'testOutput')
2012
}

services-turf/src/main/java/com/mapbox/turf/TurfAssertions.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.mapbox.geojson.Feature;
44
import com.mapbox.geojson.FeatureCollection;
55
import com.mapbox.geojson.GeoJson;
6-
import com.mapbox.core.utils.TextUtils;
76
import com.mapbox.geojson.Point;
87

98
/**
@@ -43,7 +42,7 @@ public static Point getCoord(Feature obj) {
4342
* @since 1.2.0
4443
*/
4544
public static void geojsonType(GeoJson value, String type, String name) {
46-
if (TextUtils.isEmpty(type) || TextUtils.isEmpty(name)) {
45+
if (type == null || type.length() == 0 || name == null || name.length() == 0) {
4746
throw new TurfException("Type and name required");
4847
}
4948
if (value == null || !value.type().equals(type)) {
@@ -63,7 +62,7 @@ public static void geojsonType(GeoJson value, String type, String name) {
6362
* @since 1.2.0
6463
*/
6564
public static void featureOf(Feature feature, String type, String name) {
66-
if (TextUtils.isEmpty(name)) {
65+
if (name == null || name.length() == 0) {
6766
throw new TurfException(".featureOf() requires a name");
6867
}
6968
if (feature == null || !feature.type().equals("Feature") || feature.geometry() == null) {
@@ -87,7 +86,7 @@ public static void featureOf(Feature feature, String type, String name) {
8786
* @since 1.2.0
8887
*/
8988
public static void collectionOf(FeatureCollection featureCollection, String type, String name) {
90-
if (TextUtils.isEmpty(name)) {
89+
if (name == null || name.length() == 0) {
9190
throw new TurfException("collectionOf() requires a name");
9291
}
9392
if (featureCollection == null || !featureCollection.type().equals("FeatureCollection")

0 commit comments

Comments
 (0)