Skip to content

Commit 10e0e47

Browse files
committed
Some classes are renamed (from distance to cost)
1 parent 60ca653 commit 10e0e47

File tree

6 files changed

+54
-54
lines changed

6 files changed

+54
-54
lines changed

src/main/java/com/osrm/client/DistanceMatrix.java renamed to src/main/java/com/osrm/client/CostMatrix.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6-
public class DistanceMatrix {
6+
public class CostMatrix {
77
private int[][] matrix;
88

9-
public DistanceMatrix(int size) {
9+
public CostMatrix(int size) {
1010
this.matrix = new int[size][size];
1111
}
1212

@@ -23,13 +23,13 @@ public List<List<Float>> asList() {
2323
for (int x = 0; x < matrix.length; x++) {
2424
List<Float> row = new ArrayList<>();
2525
for (int y = 0; y < matrix.length; y++) {
26-
Float distance = Float.MAX_VALUE;
26+
Float cost = Float.MAX_VALUE;
2727
try {
28-
distance = Double.valueOf(matrix[x][y]).floatValue();
28+
cost = Double.valueOf(matrix[x][y]).floatValue();
2929
} catch (NumberFormatException e) {
3030
e.printStackTrace();
3131
}
32-
row.add(distance);
32+
row.add(cost);
3333
}
3434
list.add(row);
3535
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.osrm.client;
2+
3+
public interface CostMatrixResponse {
4+
CostMatrix toCostMatrix();
5+
}

src/main/java/com/osrm/client/DistanceResponse.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/main/java/com/osrm/client/OSRMClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public OSRMClient(String uri) throws EmptyUrlException {
3131
}
3232

3333

34-
public OSRMDistanceResponse getDistanceMatrix(List<GeoLocation> locations, double speedRate, String country,
35-
String token, String profile,
36-
String options) throws OptimizationDistanceMatrixException {
34+
public OSRMCostMatrixResponse getDistanceMatrix(List<GeoLocation> locations, double speedRate, String country,
35+
String token, String profile,
36+
String options) throws OptimizationDistanceMatrixException {
3737
Builder requestBuilder = new Builder();
3838

3939
requestBuilder.readTimeout(900000, TimeUnit.MILLISECONDS);
@@ -69,7 +69,7 @@ public OSRMDistanceResponse getDistanceMatrix(List<GeoLocation> locations, doubl
6969
try {
7070
response = client.newCall(request).execute();
7171
if (response.isSuccessful()) {
72-
return OSRMDistanceResponse.fromJSON(response.body().string());
72+
return OSRMCostMatrixResponse.fromJSON(response.body().string());
7373
}
7474
} catch (Exception e) {
7575
System.out.print(e.getMessage());
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.osrm.client;
2+
3+
import com.google.gson.Gson;
4+
import com.google.gson.annotations.SerializedName;
5+
6+
import java.util.List;
7+
8+
9+
public class OSRMCostMatrixResponse implements CostMatrixResponse {
10+
11+
@SerializedName("matrix")
12+
private final List<List<Integer>> costTable;
13+
14+
public OSRMCostMatrixResponse(List<List<Integer>> costTable) {
15+
this.costTable = costTable;
16+
}
17+
18+
private List<List<Integer>> getCostTable() {
19+
return costTable;
20+
}
21+
22+
public CostMatrix toCostMatrix() {
23+
CostMatrix matrix = new CostMatrix(getCostTable().size());
24+
int i = 0;
25+
for (List<Integer> rows : this.getCostTable()) {
26+
int j = 0;
27+
for (Integer col : rows) {
28+
matrix.setValueAtCoord(i, j, col);
29+
j++;
30+
}
31+
i++;
32+
}
33+
return matrix;
34+
}
35+
36+
37+
public static OSRMCostMatrixResponse fromJSON (String json) {
38+
return new Gson().fromJson(json, OSRMCostMatrixResponse.class);
39+
}
40+
}

src/main/java/com/osrm/client/OSRMDistanceResponse.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)