Files
tlw-database-tool/src/main/java/de/jeyp91/apifootball/APIFootballMatchesProvider.java

59 lines
2.5 KiB
Java

package de.jeyp91.apifootball;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import java.util.ArrayList;
public class APIFootballMatchesProvider {
APIFootballConnector conn;
public APIFootballMatchesProvider(int season) {
this.conn = APIFootballConnector.getAPIFootballConnectorInstance(season);
}
public ArrayList<APIFootballMatch> getAPIFootballMatchesFromConfig(JSONObject matchdayConfig) {
boolean ko = false;
try {
ko = (boolean) matchdayConfig.get("ko");
} catch (Exception e) {
// Nothing to do here
}
ArrayList<APIFootballMatch> apiFootballMatches = new ArrayList<>();
for (Object singleConfigObject : (JSONArray) matchdayConfig.get("matchesConfig")) {
JSONObject singleConfig = (JSONObject) singleConfigObject;
String type = (String) singleConfig.get("type");
boolean showTable = false;
switch (type) {
case "AllMatchesOfMatchday":
int matchesLeague = ((Long) singleConfig.get("matchesLeague")).intValue();
int leagueMatchday = ((Long) singleConfig.get("leagueMatchday")).intValue();
ArrayList<APIFootballMatch> matches = conn.getMatchDataByLeagueAndMatchday(matchesLeague, leagueMatchday);
try {
showTable = (boolean) singleConfig.get("showTable");
} catch (Exception e) {
e.printStackTrace();
}
boolean finalShowTable = showTable;
boolean finalKo = ko;
matches.forEach(apiFootballMatch -> {
apiFootballMatch.setShowTable(finalShowTable);
apiFootballMatch.setKoMatch(finalKo);
});
apiFootballMatches.addAll(matches);
break;
case "SingleMatch":
int matchLeague = ((Long) singleConfig.get("matchLeague")).intValue();
int matchId = ((Long) singleConfig.get("matchId")).intValue();
APIFootballMatch match = conn.getMatchDataByLeagueAndMatchID(matchLeague, matchId);
showTable = (boolean) singleConfig.get("showTable");
match.setShowTable(showTable);
match.setKoMatch(ko);
apiFootballMatches.add(match);
break;
}
}
return apiFootballMatches;
}
}