コード例 #1
0
 @Override
 public Object getValueAt(int row, int col) {
   if (competitors.isEmpty()) return "N/A";
   Competitor c = competitors.get(row);
   if (col == 0) return row + 1;
   if (col == 1) return c.toString();
   if (col == 2) return competitorWon.get(c);
   if (col == 3) return competitorLost.get(c);
   if (col == 4) return competitorTie.get(c);
   if (col == 5) return competitorPoints.get(c);
   if (col == 6) return competitorSBPoints.get(c);
   return null;
 }
コード例 #2
0
  void updateTables() {
    for (Competitor c : competitors) {
      competitorWon.put(c, 0);
      competitorLost.put(c, 0);
      competitorTie.put(c, 0);
      for (SingleGame sg : competitorGames.get(c)) {
        Competitor c1 = competitorMap.get(sg.getCompetitorW()); // gra białymi
        Competitor c2 = competitorMap.get(sg.getCompetitorB()); // gra czarnymi
        int score = sg.getScore(); // 1 - wygrały białe, 2 - czarne, 3 - remis;
        if (score == 1 && c.equals(c1)) competitorWon.put(c, competitorWon.get(c) + 1);
        if (score == 2 && c.equals(c2)) competitorWon.put(c, competitorWon.get(c) + 1);

        if (score == 1 && c.equals(c2)) competitorLost.put(c, competitorLost.get(c) + 1);
        if (score == 2 && c.equals(c1)) competitorLost.put(c, competitorLost.get(c) + 1);

        if (score == 3) competitorTie.put(c, competitorTie.get(c) + 1);
      }
      float points = 1.0f * competitorWon.get(c) + 0.5f * competitorTie.get(c);
      competitorPoints.put(c, points);
    }
    for (Competitor c : competitors) {
      float SBPoints = 0.0f;
      for (SingleGame sg : competitorGames.get(c)) {
        Competitor c1 = competitorMap.get(sg.getCompetitorW()); // gra białymi
        Competitor c2 = competitorMap.get(sg.getCompetitorB()); // gra czarnymi
        int score = sg.getScore(); // 1 - wygrały białe, 2 - czarne, 3 - remis;
        if (score == 1 && c.equals(c1)) SBPoints += competitorPoints.get(c2);
        if (score == 2 && c.equals(c2)) SBPoints += competitorPoints.get(c1);
        if (score == 3 && c.equals(c1)) SBPoints += 0.5f * competitorPoints.get(c2);
        if (score == 3 && c.equals(c2)) SBPoints += 0.5f * competitorPoints.get(c1);
      }
      competitorSBPoints.put(c, SBPoints);
    }
    competitors.sort(
        (c1, c2) -> (int) (4. * (competitorSBPoints.get(c2) - competitorSBPoints.get(c1))));
    competitors.sort(
        (c1, c2) -> (int) (2. * (competitorPoints.get(c2) - competitorPoints.get(c1))));
    ((AbstractTableModel) table.getModel()).fireTableDataChanged();
  }