/** Returns a Map of teams that each has it's worms */ public Map<Team, List<Worm>> getByTeams() { Map<Team, List<Worm>> teams = new HashMap<>(); for (Worm worm : getWorms()) { List<Worm> team = teams.get(worm.getTeam()); if (team == null) { team = new ArrayList<>(); teams.put(worm.getTeam(), team); } team.add(worm); } return teams; }
/** Returns the total life for a given team */ public int getTotalLifeFor(Team team) { int life = 0; for (Worm worm : getWorms()) { if (worm.getTeam().equals(team)) { life += worm.getLife(); } } return life; }