コード例 #1
0
  /**
   * Load and return a hockey pool from a text file
   *
   * @param filename the name of the text file to load the hockey pool from
   * @pre The text file is formatted as follows: The first line is the name of the hockey pool. Pool
   *     teams are listed with their name first and then their list of players There is an empty
   *     line to seperate pool teams
   * @post A hockey pool is created and returned
   * @return A hockey pool loaded from the text file. All players have zero stats
   * @throws IOException
   */
  public static HockeyPool loadFromTextFile(String filename) throws IOException {
    HockeyPool hp = new HockeyPool("");

    BufferedReader in = new BufferedReader(new FileReader(filename));
    hp.setName(in.readLine());
    String line;
    PoolTeam currentPoolTeam = new PoolTeam(in.readLine());
    while ((line = in.readLine()) != null) {
      if (line.trim().length() == 0) {
        hp.addPoolTeam(currentPoolTeam);
        currentPoolTeam = new PoolTeam(in.readLine());
      } else {
        currentPoolTeam.addPlayer(new Player(line));
      }
    }
    hp.addPoolTeam(currentPoolTeam);
    in.close();
    return hp;
  }
コード例 #2
0
  /**
   * Resort all of the players and teams in the pool
   *
   * @pre true
   * @post All of the players are teams are sorted
   */
  public void resort() {
    // Resort players
    for (PoolTeam pt : m_poolTeams) {
      Iterator<Player> it = pt.playersIterator();
      List<Player> players = new ArrayList<Player>();
      while (it.hasNext()) players.add(it.next());
      pt.clearPlayers();
      for (Player p : players) {
        pt.addPlayer(p);
      }
    }

    // Resort Pool Teams
    List<PoolTeam> tempTeamList = new ArrayList<PoolTeam>();
    for (PoolTeam pt : m_poolTeams) {
      tempTeamList.add(pt);
    }
    m_poolTeams.clear();
    for (PoolTeam pt : tempTeamList) {
      m_poolTeams.add(pt);
    }
  }