package de.jeyp91.tippliga; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Objects; import de.jeyp91.App; import de.jeyp91.BaseMatch; import de.jeyp91.teamidmatcher.TeamIDMatcher; import de.jeyp91.apifootball.APIFootballMatch; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * */ public class TLWMatch extends BaseMatch{ private static final Logger logger = LoggerFactory.getLogger(TLWMatch.class); private Integer season = null; private Integer league = null; private Integer matchNo = null; private String groupId = null; private String formulaHome = null; private String formulaGuest = null; private String trend = null; private Float odd1 = null; private Float oddX = null; private Float odd2 = null; private Float rating = null; public TLWMatch(ResultSet rset) { final int SEASON = 1; final int LEAGUE = 2; final int MATCH_NO = 3; final int TEAM_ID_HOME = 4; final int TEAM_ID_GUEST = 5; final int GOALS_HOME = 6; final int GOALS_GUEST = 7; final int MATCHDAY = 8; final int STATUS = 9; final int MATCH_DATETIME = 10; final int GROUP_ID = 11; final int FORMULA_HOME = 12; final int FORMULA_GUEST = 13; final int KO_MATCH = 14; final int GOALS_OVERTIME_HOME = 15; final int GOALS_OVERTIME_GUEST = 16; final int SHOW_TABLE = 17; final int TREND = 18; final int ODD1 = 19; final int ODDX = 20; final int ODD2 = 21; final int RATING = 22; try { this.season = Integer.parseInt(rset.getString(SEASON)); this.league = Integer.parseInt(rset.getString(LEAGUE)); this.matchNo = Integer.parseInt(rset.getString(MATCH_NO)); this.teamIdHome = Integer.parseInt(rset.getString(TEAM_ID_HOME)); this.teamIdGuest = Integer.parseInt(rset.getString(TEAM_ID_GUEST)); this.goalsHome = rset.getString(GOALS_HOME).isEmpty()?null:Integer.parseInt(rset.getString(GOALS_HOME)); this.goalsGuest = rset.getString(GOALS_GUEST).isEmpty()?null:Integer.parseInt(rset.getString(GOALS_GUEST)); this.matchday = Integer.parseInt(rset.getString(MATCHDAY)); this.status = Integer.parseInt(rset.getString(STATUS)); this.matchDatetime = rset.getString(MATCH_DATETIME); this.groupId = rset.getString(GROUP_ID); this.formulaHome = rset.getString(FORMULA_HOME); this.formulaGuest = rset.getString(FORMULA_GUEST); this.koMatch = Integer.parseInt(rset.getString(KO_MATCH)); this.goalsOvertimeHome = rset.getString(GOALS_OVERTIME_HOME).isEmpty()?null:Integer.parseInt(rset.getString(GOALS_OVERTIME_HOME)); this.goalsOvertimeGuest = rset.getString(GOALS_OVERTIME_GUEST).isEmpty()?null:Integer.parseInt(rset.getString(GOALS_OVERTIME_GUEST)); this.showTable = Integer.parseInt(rset.getString(SHOW_TABLE)); this.trend = rset.getString(TREND); this.odd1 = Float.parseFloat(rset.getString(ODD1)); this.oddX = Float.parseFloat(rset.getString(ODDX)); this.odd2 = Float.parseFloat(rset.getString(ODD2)); this.rating = Float.parseFloat(rset.getString(RATING)); } catch (SQLException e) { /* TODO */ e.printStackTrace(); } } public TLWMatch(APIFootballMatch apiFootballMatch, int season, int league, int matchday, int matchNo, int status, int koMatch, boolean showTable) { this.season = season; this.league = league; this.matchday = matchday; this.matchNo = matchNo; this.teamIdHome = TeamIDMatcher.getTippligaIdFromApiFootballId(apiFootballMatch, TeamIDMatcher.HOME); this.teamIdGuest = TeamIDMatcher.getTippligaIdFromApiFootballId(apiFootballMatch, TeamIDMatcher.GUEST); this.goalsHome = apiFootballMatch.getGoalsHome(); this.goalsOvertimeHome = apiFootballMatch.getGoalsOvertimeHome(); this.goalsOvertimeGuest = apiFootballMatch.getGoalsOvertimeGuest(); this.goalsGuest = apiFootballMatch.getGoalsGuest(); this.goalsHome = apiFootballMatch.getGoalsHome(); this.goalsGuest = apiFootballMatch.getGoalsGuest(); this.matchDatetime = apiFootballMatch.getMatchDateTime().replace("T", " ").substring(0, 19); this.groupId = this.getGroupFromMatchdayString(apiFootballMatch.getRound()); this.formulaHome = ""; this.formulaGuest = ""; this.status = status; this.koMatch = koMatch; this.showTable = showTable ? 0 : 1; this.teamNameHome = apiFootballMatch.getTeamNameHome(); this.teamNameGuest = apiFootballMatch.getTeamNameGuest(); } public TLWMatch(int season, int league, int matchday, int matchNo, String matchDatetime, int status, int koMatch) { this.season = season; this.matchday = matchday; this.league = league; this.matchNo = matchNo; this.status = status; this.koMatch = koMatch; this.matchDatetime = matchDatetime; } public TLWMatch(int season, int league, int matchday, int matchNo, int teamIdHome, int teamIdGuest, String matchDatetime, int koMatch) { this.season = season; this.matchday = matchday; this.league = league; this.matchNo = matchNo; this.teamIdHome = teamIdHome; this.teamIdGuest = teamIdGuest; this.matchDatetime = matchDatetime; this.status = 0; this.koMatch = koMatch; } public TLWMatch(TLWMatch referenceMatch) { this.season = referenceMatch.season; this.league = referenceMatch.league; this.matchday = referenceMatch.matchday; this.teamIdHome = referenceMatch.teamIdHome; this.teamIdGuest = referenceMatch.teamIdGuest; this.goalsHome = referenceMatch.goalsHome; this.goalsGuest = referenceMatch.goalsGuest; this.matchDatetime = referenceMatch.matchDatetime; this.matchNo = referenceMatch.matchNo; this.groupId = referenceMatch.groupId; this.formulaHome = referenceMatch.formulaHome; this.formulaGuest = referenceMatch.formulaGuest; this.status = referenceMatch.status; this.koMatch = referenceMatch.koMatch; this.goalsOvertimeHome = referenceMatch.goalsOvertimeHome; this.goalsOvertimeGuest = referenceMatch.goalsOvertimeGuest; this.showTable = referenceMatch.showTable; this.trend = referenceMatch.trend; this.odd1 = referenceMatch.odd1; this.oddX = referenceMatch.oddX; this.odd2 = referenceMatch.odd2; this.rating = referenceMatch.rating; } public TLWMatch(String formulaHome, String formulaGuest, String matchDateTime) { this.teamIdHome = 0; this.teamIdGuest = 0; this.formulaHome = formulaHome; this.formulaGuest = formulaGuest; this.matchDatetime = matchDateTime; } public Integer getSeason() { return this.season; } public Integer getLeague() { return this.league; } public Integer getMatchNo() { return this.matchNo; } public String getGroupId() { return this.groupId; } public String getFormulaHome() { String formula = "'D'"; if (this.formulaHome != null) { formula = this.formulaHome; } return formula; } public String getFormulaGuest() { String formula = "'D'"; if (this.formulaGuest != null) { formula = this.formulaGuest; } return formula; } public String getSQLQueryInsert() { return "INSERT INTO phpbb_footb_matches VALUES (" + getSQLQueryValues() + ");"; } public String getSQLQueryReplace() { return "REPLACE INTO phpbb_footb_matches VALUES (" + getSQLQueryValues() + ");"; } public String getSQLQueryValues() { return this.season + ", " + this.league + ", " + this.matchNo + ", " + nullToSqlEmptyString(this.teamIdHome) + ", " + nullToSqlEmptyString(this.teamIdGuest) + ", " + nullToSqlEmptyString(this.goalsHome) + ", " + nullToSqlEmptyString(this.goalsGuest) + ", " + this.matchday + ", " + this.status + ", " + nullToSqlEmptyString(this.matchDatetime) + ", " + nullToSqlEmptyString(this.groupId) + ", " + getFormulaHome() + ", " + getFormulaGuest() + ", " + nullToSqlEmptyString(this.koMatch) + ", " + nullToSqlEmptyString(this.goalsOvertimeHome) + ", " + nullToSqlEmptyString(this.goalsOvertimeGuest) + ", " + nullToSqlEmptyString(this.showTable) + ", " + "'','0.00','0.00','0.00','0.00'"; } private String nullToSqlEmptyString(Integer number) { return number != null ? number.toString() : "''"; } private String nullToSqlEmptyString(String string) { return string != null ? "'"+string+"'" : "''"; } public void setGoalsHome(int goals) { this.goalsHome = goals; } public void setGoalsGuest(int goals) { this.goalsGuest = goals; } public void setGoalsOvertimeHome(int goals) { this.goalsOvertimeHome = goals; } public void setGoalsOvertimeGuest(int goals) { this.goalsOvertimeGuest = goals; } public void setMatchDateTime(String matchDateTime) { this.matchDatetime = matchDateTime; } public void updateMatch(APIFootballMatch apiFootballMatch) { this.teamIdHome = TeamIDMatcher.getTippligaIdFromApiFootballId(apiFootballMatch, TeamIDMatcher.HOME); this.teamIdGuest = TeamIDMatcher.getTippligaIdFromApiFootballId(apiFootballMatch, TeamIDMatcher.GUEST); this.teamNameHome = apiFootballMatch.getTeamNameHome(); this.teamNameGuest = apiFootballMatch.getTeamNameGuest(); this.goalsHome = apiFootballMatch.getGoalsHome(); this.goalsGuest = apiFootballMatch.getGoalsGuest(); this.matchDatetime = apiFootballMatch.getMatchDateTime().replace("T", " ").substring(0, 19); } private String getGroupFromMatchdayString(String matchdayString) { if(matchdayString.startsWith("Group ")) { return matchdayString.substring(6, 7); } else { return ""; } } public static boolean isSameMatchPlaceholder (TLWMatch tlwMatch, TLWMatch placeholderConfigMatch) { String placeholderConfigMatchDateTime = placeholderConfigMatch.getMatchDateTime(); String tlwMatchDateTime = tlwMatch.getMatchDateTime(); String placeholderConfigMatchFormulaHome = placeholderConfigMatch.getFormulaHome(); String tlwMatchFormulaHome = tlwMatch.getFormulaHome(); String placeholderConfigMatchFormulaGuest = placeholderConfigMatch.getFormulaGuest(); String tlwMatchFormulaGuest = tlwMatch.getFormulaGuest(); if(Objects.equals(tlwMatchDateTime, placeholderConfigMatchDateTime) && Objects.equals(tlwMatchFormulaHome, placeholderConfigMatchFormulaHome) && Objects.equals(tlwMatchFormulaGuest, placeholderConfigMatchFormulaGuest)) { return true; } if(Objects.equals(tlwMatchDateTime, placeholderConfigMatchDateTime) && Objects.equals(tlwMatch.getTeamIdHome(), null) && Objects.equals(tlwMatch.getTeamIdGuest(), null)) { return true; } return false; } }