Skip to content

Commit 8c487a0

Browse files
committed
Improved support for AM/MR rolling stock
1 parent 582ac38 commit 8c487a0

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/NmbsToMlgDessinsAdapter.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,42 @@ private NmbsToMlgDessinsAdapter() {
1212

1313
}
1414

15-
static NmbsTrainType convert(String parentType, String subType, String orientation, int firstClassSeats) {
15+
static NmbsTrainType convert(String parentType, String subType, String orientation, int firstClassSeats, int position) {
16+
subType = subType.toUpperCase();
1617
if (parentType.startsWith("HLE")) {
1718
return convertHle(parentType, subType, orientation);
18-
} else if (parentType.startsWith("AM") || parentType.startsWith("MR") || parentType.startsWith("AR")) {
19+
} else if (parentType.startsWith("AM") || parentType.startsWith("MR") || parentType.startsWith("AR") || parentType.startsWith("M08")) {
1920
return convertAm(parentType, subType, orientation, firstClassSeats);
2021
} else if (parentType.startsWith("I") || parentType.startsWith("M")) {
21-
return convertCarriage(parentType, subType, orientation, firstClassSeats);
22+
return convertCarriage(parentType, subType, orientation, firstClassSeats, position);
2223
} else {
2324
return new NmbsTrainType(parentType, subType, orientation);
2425
}
2526
}
2627

27-
private static NmbsTrainType convertCarriage(String parentType, String subType, String orientation, int firstClassSeats) {
28+
private static NmbsTrainType convertCarriage(String parentType, String subType, String orientation, int firstClassSeats, int position) {
2829
String newParentType = parentType;
2930
String newSubType = subType;
31+
String newOrientation = orientation;
3032
switch (parentType) {
3133
case "M4":
3234
switch (subType) {
3335
case "A":
3436
case "AU":
37+
case "AYU":
3538
newSubType = "B_A";
3639
break;
3740
case "AD":
3841
case "AUD":
3942
newSubType = "B_AD";
4043
break;
44+
case "ADU":
4145
case "ADX":
46+
if (position <= 2) {
47+
newOrientation = "R";
48+
} else {
49+
newOrientation = "L";
50+
}
4251
newSubType = "B_ADX";
4352
break;
4453
case "B":
@@ -109,31 +118,34 @@ private static NmbsTrainType convertCarriage(String parentType, String subType,
109118
}
110119
break;
111120
}
112-
return new NmbsTrainType(newParentType, newSubType, orientation);
121+
return new NmbsTrainType(newParentType, newSubType, newOrientation);
113122
}
114123

115124
private static NmbsTrainType convertAm(String parentType, String subType, String orientation, int firstClassSeats) {
116125
String newParentType = parentType;
117126
String newSubType = subType;
118-
119127
switch (parentType) {
120128
case "AM08":
121129
case "AM08M":
130+
newParentType = "AM08";
122131
switch (subType) {
123132
case "A":
133+
newSubType = "A";
134+
break;
124135
case "C":
125136
newSubType = "0_C";
126137
break;
127138
case "B":
128139
newSubType = "0_B";
129140
break;
130141
}
131-
newParentType = "AM08";
132142
break;
133143
case "AM08P":
134144
newParentType = "AM08";
135145
switch (subType) {
136146
case "A":
147+
newSubType = "A";
148+
break;
137149
case "C":
138150
newSubType = "5_C";
139151
break;

opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/VehicleCompositionParser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ VehicleCompositionImpl parseVehicleComposition(Context appContext, JSONObject re
3737
boolean confirmed = !longestSegment.getJSONObject("composition").getString("source").equalsIgnoreCase("planning");
3838
VehicleCompositionUnit[] vehicleCompositionUnits = new VehicleCompositionUnit[units.length()];
3939
for (int i = 0; i < units.length(); i++) {
40-
vehicleCompositionUnits[i] = parseVehicleCompositionUnit(appContext, units.getJSONObject(i));
40+
vehicleCompositionUnits[i] = parseVehicleCompositionUnit(appContext, units.getJSONObject(i), i);
4141
}
4242
return new VehicleCompositionImpl(vehicleCompositionUnits, confirmed);
4343
}
@@ -58,7 +58,7 @@ private JSONObject getLongestComposition(JSONArray segmentsArray) throws JSONExc
5858
return longestSegment;
5959
}
6060

61-
private VehicleCompositionUnit parseVehicleCompositionUnit(Context appContext, JSONObject jsonObject) throws JSONException {
61+
private VehicleCompositionUnit parseVehicleCompositionUnit(Context appContext, JSONObject jsonObject, int position) throws JSONException {
6262
String parentType = jsonObject.getJSONObject("materialType").getString("parent_type").toUpperCase();
6363
String subType = jsonObject.getJSONObject("materialType").getString("sub_type").toUpperCase();
6464
String orientation = jsonObject.getJSONObject("materialType").getString("orientation").substring(0, 1).toUpperCase();
@@ -70,7 +70,7 @@ private VehicleCompositionUnit parseVehicleCompositionUnit(Context appContext, J
7070
int numberOfFirstClassSeats = jsonObject.getInt("seatsFirstClass");
7171
int numberOfSecondClassSeats = jsonObject.getInt("seatsSecondClass");
7272

73-
NmbsTrainType trainType = NmbsToMlgDessinsAdapter.convert(parentType, subType, orientation, numberOfFirstClassSeats);
73+
NmbsTrainType trainType = NmbsToMlgDessinsAdapter.convert(parentType, subType, orientation, numberOfFirstClassSeats, position);
7474
int resourceId = getResourceIdForTrain(appContext, trainType);
7575
return new VehicleCompositionUnitImpl(resourceId, publicFacingNumber, trainType.parentType, hasToilet, hasAirco, canPassToNextUnit, numberOfFirstClassSeats, numberOfSecondClassSeats);
7676
}

0 commit comments

Comments
 (0)