Improve updater
This commit is contained in:
@@ -1,2 +1,93 @@
|
||||
<<<<<<< HEAD
|
||||
package de.jeyp91.tippliga;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class TLWTeamsUpdater {
|
||||
|
||||
Integer season;
|
||||
Integer league;
|
||||
ArrayList<TLWTeam> teamsOriginal;
|
||||
ArrayList<TLWMatch> matchesUpdated;
|
||||
ArrayList<TLWTeam> missingTeams;
|
||||
|
||||
public TLWTeamsUpdater(int season, int league, ArrayList<TLWMatch> matchesUpdated) {
|
||||
this.season = season;
|
||||
this.league = league;
|
||||
this.matchesUpdated = matchesUpdated;
|
||||
missingTeams = new ArrayList<>();
|
||||
|
||||
TippligaSQLConnector conn = new TippligaSQLConnector();
|
||||
teamsOriginal = conn.getTeams(String.valueOf(season), String.valueOf(league));
|
||||
|
||||
HashSet<Integer> missingIds = this.initMissingIds();
|
||||
this.initMissingTeams(missingIds);
|
||||
}
|
||||
|
||||
private HashSet<Integer> initMissingIds() {
|
||||
HashSet<Integer> missingIds = new HashSet<>();
|
||||
|
||||
for(TLWMatch match : matchesUpdated) {
|
||||
if(isTeamMissing(match.getTeamIdHome())) {
|
||||
missingIds.add(match.getTeamIdHome());
|
||||
}
|
||||
if(isTeamMissing(match.getTeamIdGuest())) {
|
||||
missingIds.add(match.getTeamIdGuest());
|
||||
}
|
||||
}
|
||||
missingIds.remove(0);
|
||||
return missingIds;
|
||||
}
|
||||
|
||||
private void initMissingTeams(HashSet<Integer> missingIds) {
|
||||
TippligaSQLConnector conn = new TippligaSQLConnector();
|
||||
for (Integer id : missingIds) {
|
||||
ArrayList<TLWTeam> teams = conn.getTeams(String.valueOf(id));
|
||||
missingTeams.add(new TLWTeam(
|
||||
this.season,
|
||||
this.league,
|
||||
id,
|
||||
teams.get(0).getTeamName(),
|
||||
teams.get(0).getTeamNameShort(),
|
||||
teams.get(0).getTeamSymbol(),
|
||||
"",
|
||||
0
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isTeamMissing(int id) {
|
||||
boolean teamMissing = true;
|
||||
for(TLWTeam team : teamsOriginal) {
|
||||
if(team.getTeamId() == id) {
|
||||
teamMissing = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return teamMissing;
|
||||
}
|
||||
|
||||
public String getInsertSQL() {
|
||||
String updateSql = "";
|
||||
|
||||
for(TLWTeam team : missingTeams) {
|
||||
|
||||
updateSql += "INSERT INTO phpbb_footb_teams VALUES (" +
|
||||
team.getSeason() + ", " +
|
||||
team.getLeague() + ", " +
|
||||
team.getTeamId() + ", " +
|
||||
"'" + team.getTeamName() + "', " +
|
||||
"'" + team.getTeamNameShort() + "', " +
|
||||
"'" + team.getTeamSymbol() + "', " +
|
||||
"'" + team.getGroupId() + "', " +
|
||||
team.getMatchday() +
|
||||
");\n";
|
||||
}
|
||||
|
||||
return updateSql;
|
||||
}
|
||||
=======
|
||||
package de.jeyp91.tippliga;public class TLWTeamsUpdater {
|
||||
>>>>>>> origin/master
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user