public synchronized void vote(String name, InetAddress ip) throws UserException { if (isClosed()) { throw new UserException("The votes are closed"); } if (ips.contains(ip)) { throw new UserException("IP " + ip + " has already voted"); } ips.add(ip); Candidate theCandidate = null; for (Candidate candidate : this) { if (candidate.getName().equals(name)) { theCandidate = candidate; break; } } if (theCandidate == null) { throw new UserException("Candidate " + name + " doesn't exist"); } theCandidate.vote(); }