private void updateTurtles(World world, DiffBuffer buf) {
// turtles, on the other hand, can die, so we move each one to a new
// map as we encounter it...
Map<Double, TurtleData> newTurtles = new HashMap<Double, TurtleData>();
for (Agent a : world.turtles().agents()) {
Turtle turtle = (Turtle) a;
TurtleData diffs = updateTurtle(turtle);
if (diffs != null) {
buf.addTurtle(diffs);
}
TurtleData tmp = turtles.remove(Double.valueOf(turtle.id()));
newTurtles.put(Double.valueOf(turtle.id()), tmp);
}
// now, any turtles left in the old map must have died...
for (TurtleData turtle : turtles.values()) {
// so, add a new "dead" TurtleData to the outgoing buffer.
buf.addTurtle(new TurtleData(turtle.id()));
}
// finally, the new map replaces the old one.
turtles = newTurtles;
}