Java Reference
In-Depth Information
Note that in this interface, we are identifying teams by their names (since we pass String ob-
jects back and forth) and identifying players by their player IDs, which are UUID objects. We
could just pass the Team and Player objects back and forth over the network, but these are
much larger than the String and UUID objects, and we are trying to keep our communication
overhead minimal. This means that the clients reporting the scores need to find out the play-
er IDs for all of the players on a team. This could be done by having those UUID objects be
well known in some way (published in a newspaper, for example). But a more self-contained
mechanism is to allow the clients to get a roster of the players on a team by talking with the
StatRecorder server , which is the purpose of our second method in the interface.
Implementing the BoxScore interface is reasonably easy, especially if we ignore the details of
how the data would get into this object (which, for the sake of simplicity in this example, we
will). A quick implementation would look something like:
package org.oreilly.javaGoodParts.examples.impl;
import java.io.Serializable;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import org.oreilly.javaGoodParts.examples.statistics.Batter.AtBatResult;
import org.oreilly.javaGoodParts.examples.statistics.BoxScore;
import org.oreilly.javaGoodParts.examples.statistics.DidNotPlayException;
import org.oreilly.javaGoodParts.examples.statistics.Fielder.AttemptResult;
import org.oreilly.javaGoodParts.examples.statistics.Player.Position;
/**
* An implementation of the {@link BoxScore} interface, ignoring
* all of the little details like how the data that populates the private
* fields is actually placed into the object.
*/
public class BoxScoreImpl implements BoxScore, Serializable {
private static final long serialVersionUID = 1L;
private LinkedList<String> teams
= new LinkedList<String>();
private Hashtable<String, List<UUID>> whoPlayed
= new Hashtable<String, List<UUID>>();
private Hashtable<UUID, Position> positions
= new Hashtable<UUID, Position>();
private Hashtable<UUID, List<AtBatResult>> atBats
Search WWH ::




Custom Search