Java Reference
In-Depth Information
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.oreilly.javaGoodParts.examples.statistics.Player;
import org.oreilly.javaGoodParts.examples.statistics.Team;
/**
* A fourth implementation of the Team interface, using a HashSet as the backing
* store for the Players on the team, after the interface has been changed to
* return a Set from the getPlayers() method. This iteration adds methods that
* allow getting player records in a random access fashion. One method allows
* getting a {@link List} of {@link Player} objects for a player from the name,
* and the other allows getting a {@link Player} object from the player id. To
* do this, we add two {@link HashMap} objects to the private fields.
*/
public class TeamImpl implements Team {
private String name;
private HashSet<Player> players = new HashSet<Player>();
private HashMap<String, Set<Player>> byName =
new HashMap<String, Set<Player>>();
private HashMap<UUID, Player> byIds = new HashMap<UUID, Player>();
/**
* Create a TeamImpl object, with the name supplied.
*/
public TeamImpl(String teamName) {
name = teamName;
}
/**
* Return a <code>String</code> that is the name of this team.
*/
public String getName() {
return name;
}
/**
* Return a set of the players that are on this team.
*/
public Set<Player> getRoster() {
return new HashSet<Player>(players);
}
/**
* Add a player to the team.
Search WWH ::




Custom Search