48 lines
2.1 KiB
Java
48 lines
2.1 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 - 1);
|
|
}
|
|
|
|
public ArrayList<APIFootballMatch> getAPIFootballMatchesFromConfig(JSONArray config) {
|
|
ArrayList<APIFootballMatch> apiFootballMatches = new ArrayList<>();
|
|
for (Object singleConfigObject : config) {
|
|
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;
|
|
matches.forEach(apiFootballMatch -> apiFootballMatch.setShowTable(finalShowTable));
|
|
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);
|
|
apiFootballMatches.add(match);
|
|
break;
|
|
}
|
|
}
|
|
return apiFootballMatches;
|
|
}
|
|
}
|