Rework rounds parser to support wrongly sorted league rounds

This commit is contained in:
Julian Arndt
2023-09-10 17:40:12 +02:00
parent b411f5d57f
commit ba68057c0f

View File

@@ -41,13 +41,17 @@ public class APIFootballMatch extends BaseMatch {
public static int getMatchdayFromRoundString(int season, String round, int leagueId) {
round = round.replace(" ", "_");
Integer matchday = null;
APIFootballConnector con = APIFootballConnector.getAPIFootballConnectorInstance(season);
JSONObject roundsObject = con.getMatchdays(leagueId);
JSONArray roundsArray = (JSONArray)(((JSONObject) roundsObject.get("api")).get("fixtures"));
for (int i = 0; i < roundsArray.size(); i++) {
if(roundsArray.get(i).toString().equals(round)) {
matchday = i + 1;
break;
if (round.startsWith("Regular_Season_-_")) {
matchday = Integer.parseInt(round.replace("Regular_Season_-_", ""));
} else {
APIFootballConnector con = APIFootballConnector.getAPIFootballConnectorInstance(season);
JSONObject roundsObject = con.getMatchdays(leagueId);
JSONArray roundsArray = (JSONArray)(((JSONObject) roundsObject.get("api")).get("fixtures"));
for (int i = 0; i < roundsArray.size(); i++) {
if(roundsArray.get(i).toString().equals(round)) {
matchday = i + 1;
break;
}
}
}
return matchday;