package de.jeyp91.tippliga; import de.jeyp91.ResourceProvider; import de.jeyp91.tippligaforum.TippligaConfigProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import java.util.ArrayList; public class TLWMatchesCreatorTipperPokal extends TLWMatchesCreatorBase{ Logger logger = LoggerFactory.getLogger(TLWMatchesCreatorTipperPokal.class); int season; int league; ArrayList TLWMatches; JSONObject tipperList; JSONArray tipperTeamConfig; ArrayList matchdays; public TLWMatchesCreatorTipperPokal(int season, int league, String configFileName, ArrayList matchdays) { this.season = season; this.league = league; this.matchdays = matchdays; TippligaConfigProvider prov = new TippligaConfigProvider(season); this.tipperList = prov.getTippligaConfig(configFileName); this.tipperTeamConfig = ResourceProvider.getTipperTeamConfig(); this.TLWMatches = new ArrayList<>(); this.publicateMatchObjects(); } private void publicateMatchObjects() { int matchday = 1; for(int matchNo = 1; matchNo <= this.tipperList.size() / 2; matchNo++) { String homeName = this.tipperList.get(String.valueOf(2 * matchNo - 1)).toString(); String guestName = this.tipperList.get(String.valueOf(2 * matchNo)).toString(); int teamIdHome = getTeamIdFromTipperName(homeName); int teamIdGuest = getTeamIdFromTipperName(guestName); String matchDatetime = getDeliveryDateForMatchday(matchday); TLWMatch tlwMatch = new TLWMatch(this.season, this.league, matchday, matchNo, teamIdHome, teamIdGuest, matchDatetime, 1); tlwMatch.setShowTable(false); this.TLWMatches.add(tlwMatch); } } private int getTeamIdFromTipperName(String name) { int teamId = 0; for(Object config : tipperTeamConfig) { if (((JSONObject) config).get("team_name").toString().equals(name)) { teamId = ((Long) (((JSONObject) config).get("team_id"))).intValue(); } } if(teamId == 0) { logger.error("Did not find Tipper ID for " + name); } return teamId; } public ArrayList getMatches() { return this.TLWMatches; } private String getDeliveryDateForMatchday(int matchday) { String deliveryDate = ""; for (TLWMatchday matchdayObject : this.matchdays) { if(matchdayObject.getMatchday() == matchday) { deliveryDate = matchdayObject.getDeliveryDate(); } } return deliveryDate; } }