Java Reference
In-Depth Information
* statistics (e.g., that there is a {@link Batter} object associated
* with the player.)
* @param batter Player whose batting statistics are to be updated
* @param results a list of the batting results for a particular game
*/
private void updateBatting(Player batter, List<Batter.AtBatResult> results){
Batter batStats = batter.asBatter();
for (Batter.AtBatResult r : results){
batStats.atBat(r);
}
}
What could go wrong if two such updates were happening at the same time? This will depend
on the implementation of the atBat() method. A straightforward approach to the BatterIm-
pl class implements that method as:
public void atBat(AtBatResult what) {
switch (what) {
case strikeOut:
break;
case fieldOut:
break;
case base1:
hits++;
bases++;
break;
case base2:
hits++;
bases += 2;
break;
case base3:
hits++;
bases += 3;
case base4:
hits++;
bases += 4;
case sacrifice:
sacrifices++;
return;
case walk:
baseOnBalls++;
return;
}
Search WWH ::




Custom Search