Skip to content

Commit 3e5fd48

Browse files
committed
Add size for FlattenListOfPoints
1 parent be6d8b8 commit 3e5fd48

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

services-geojson/src/main/java/com/mapbox/geojson/FlattenListOfPoints.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ public double[] getAltitudes() {
112112
return altitudes;
113113
}
114114

115+
/**
116+
* @return the total number of points stored in this flattened structure
117+
*/
118+
public int size() {
119+
return flattenLngLatPoints.length / 2;
120+
}
121+
115122
/**
116123
* Creates a list of {@link Point}s and returns it.
117124
* <p>

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,43 @@ public void constructor_withArrays_nullAltitudes() {
3939
assertNull(flatten.getAltitudes());
4040
}
4141

42+
@Test
43+
public void size_emptyFlatten_returnsZero() {
44+
double[] lngLatArray = new double[]{};
45+
FlattenListOfPoints flatten = new FlattenListOfPoints(lngLatArray, null);
46+
47+
assertEquals(0, flatten.size());
48+
}
49+
50+
@Test
51+
public void size_singlePoint_returnsOne() {
52+
double[] lngLatArray = new double[]{1.0, 2.0};
53+
FlattenListOfPoints flatten = new FlattenListOfPoints(lngLatArray, null);
54+
55+
assertEquals(1, flatten.size());
56+
}
57+
58+
@Test
59+
public void size_multiplePoints_returnsCorrectCount() {
60+
double[] lngLatArray = new double[]{1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
61+
FlattenListOfPoints flatten = new FlattenListOfPoints(lngLatArray, null);
62+
63+
assertEquals(3, flatten.size());
64+
}
65+
66+
@Test
67+
public void size_fromListOfPoints_returnsCorrectCount() {
68+
List<Point> points = new ArrayList<>();
69+
points.add(Point.fromLngLat(1.0, 2.0));
70+
points.add(Point.fromLngLat(3.0, 4.0));
71+
points.add(Point.fromLngLat(5.0, 6.0));
72+
points.add(Point.fromLngLat(7.0, 8.0));
73+
74+
FlattenListOfPoints flatten = new FlattenListOfPoints(points);
75+
76+
assertEquals(4, flatten.size());
77+
}
78+
4279
@Test
4380
public void constructor_withEmptyList_createsEmptyFlatten() {
4481
List<Point> points = new ArrayList<>();

0 commit comments

Comments
 (0)