Java Reference
In-Depth Information
* implementation will go through the players (by their
* id), and call {@link updatePlayer} for each player
* that was in the game.
* @param forTeam the team whose players are being
* updated
* @param game the {@link BoxScore} object that
* contains the record of the game
private void processScore(Team forTeam, BoxScore game) {
List<UUID> players = game.getPlayers(forTeam.getName());
for (UUID id : players) {
Player toUpdate = forTeam.getPlayer(id);
updatePlayer(toUpdate, game);
The question we need to ask ourselves is what could go wrong during such an update. There
are two cases we need to consider. The first is what could go wrong if such an update is called
on two different threads, which could happen if two games played by the same team were be-
ing reported at the same time. The second is what could go wrong if one thread is responding
to a call to getRoster() while we were in the middle of a processScore() .
The answer to both of these will depend on what is done in updatePlayer() , which we left
as an exercise to the reader in Chapter 9 . Let's flesh this out a bit now. A reasonable approach
to such an update method might look like:
* Update the statistics of a particular player, given
* the boxscore of the game. The complete implementation
* of this method is an exercise left to the reader...
* @param toUpdate
* @param game
private void updatePlayer(Player toUpdate, BoxScore game) {
List<Batter.AtBatResult> batting = game.getBatting(toUpdate.getId());
if (!batting.isEmpty()){
updateBatting(toUpdate, batting);
/* Need to add further clauses to update other statistics*/
* Update the batting statistics for a player for a particular game.
* This method assumes that the player is associated with some batting
Search WWH ::

Custom Search