package controllers; import java.net.URL; import java.util.List; import java.util.Map; import java.util.ResourceBundle; import com.google.common.collect.Maps; import data.GuiMysql; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.cell.MapValueFactory; import objects.TeamStanding; @SuppressWarnings("rawtypes") public class MatchStatTabController implements Initializable { private static final String GOALS_CONCEDED = "goalsConceded"; private static final String GOALS_SCORED = "goalsScored"; private static final String POINTS_STRING = "points"; private static final String GAMES_PLAYED = "gamesPlayed"; private static MatchStatTabController instance; @FXML TableView> matchStatTable; @FXML TableColumn team = new TableColumn<>("team"); @FXML TableColumn gamesPlayed = new TableColumn<>(GAMES_PLAYED); @FXML TableColumn win = new TableColumn<>("win"); @FXML TableColumn draw = new TableColumn<>("draw"); @FXML TableColumn loss = new TableColumn<>("loss"); @FXML TableColumn points = new TableColumn<>(POINTS_STRING); @FXML TableColumn goalsScored = new TableColumn<>(GOALS_SCORED); @FXML TableColumn goalsConceded = new TableColumn<>(GOALS_CONCEDED); @FXML TableColumn diff = new TableColumn<>("diff"); public static MatchStatTabController getInstance() { if (instance == null) { synchronized (MatchStatTabController.class) { if (instance == null) { instance = new MatchStatTabController(); } } } return instance; } @Override public void initialize(URL arg0, ResourceBundle arg1) { team.setCellValueFactory(new MapValueFactory<>("team")); gamesPlayed.setCellValueFactory(new MapValueFactory<>(GAMES_PLAYED)); win.setCellValueFactory(new MapValueFactory<>("win")); draw.setCellValueFactory(new MapValueFactory<>("draw")); loss.setCellValueFactory(new MapValueFactory<>("loss")); points.setCellValueFactory(new MapValueFactory<>(POINTS_STRING)); goalsScored.setCellValueFactory(new MapValueFactory<>(GOALS_SCORED)); goalsConceded.setCellValueFactory(new MapValueFactory<>(GOALS_CONCEDED)); diff.setCellValueFactory(new MapValueFactory<>("diff")); instance = this; } public void setLeagueStandingsTable(int leagueId, String season, int countryId, String date) { final List res = GuiMysql.getInstance().getLeagueTable(leagueId, season, countryId, date); matchStatTable.getItems().clear(); for (final TeamStanding ts : res) { final Map line = Maps.newHashMap(); final int numGamesPlayed = ts.getWins() + ts.getDraws() + ts.getLosses(); line.put("team", ts.getTeamName()); line.put(GAMES_PLAYED, numGamesPlayed); line.put("win", ts.getWins()); line.put("draw", ts.getDraws()); line.put("loss", ts.getLosses()); line.put(POINTS_STRING, ts.getPoints()); line.put(GOALS_SCORED, ts.getGoalsScored() / numGamesPlayed); line.put(GOALS_CONCEDED, ts.getGoalsConceded() / numGamesPlayed); matchStatTable.getItems().add(line); } } }