Example #1
0
 /**
  * Remove a pool team with a given name from the pool
  *
  * @param name The name of the pool team to remove
  * @pre true
  * @post If the pool contains a pool team with the given name, the team is removed
  * @return true if the team was successfully removed from the pool, false otherwise
  */
 public boolean removePoolTeam(String name) {
   for (PoolTeam pt : m_poolTeams) {
     if (pt.getName().equals(name)) {
       return m_poolTeams.remove(pt);
     }
   }
   return false;
 }
Example #2
0
 /**
  * Get a List of all of the players in the pool
  *
  * @pre true
  * @post nothing changes
  * @return A collection of all of the players in the hockey pool
  */
 public List<Player> getAllPlayers() {
   List<Player> players = new ArrayList<Player>();
   for (PoolTeam pt : m_poolTeams) {
     Iterator<Player> it = pt.playersIterator();
     while (it.hasNext()) {
       players.add(it.next());
     }
   }
   return players;
 }
Example #3
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;
  }
Example #4
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);
    }
  }
Example #5
0
 /**
  * Returns the pool team with the given name, or null if the pool doesn't contain a pool team with
  * that name
  *
  * @param name The name of the pool team to search for
  * @pre true
  * @post nothing changes
  * @return The pool team with the given name, or null if the pool doesn't contain a pool team with
  *     that name
  */
 public PoolTeam getPoolTeam(String name) {
   for (PoolTeam pt : m_poolTeams) {
     if (pt.getName().equals(name)) return pt;
   }
   return null;
 }