public static <X> List<X> mostVotedFor(Map<X, Double> votes) {
        // Choose the label with the greatest number of votes
        // If there is a tie, choose the one with the least index
        double maxTalley = Double.NEGATIVE_INFINITY;
        List<X> maxTickets = new ArrayList<X>();
        for(Entry<X,Double> entry : votes.entrySet()) {
            X ticket = entry.getKey();
            double talley = entry.getValue();
            if (talley > maxTalley) {
                maxTickets = new ArrayList<X>();
                maxTickets.add(ticket);
                maxTalley = talley;
            } else if (talley == maxTalley) {
                maxTickets.add(ticket);
            }
        }
        return maxTickets;
    }
public static < X > List < X > mostVotedFor ( Map < X , Double > votes ) { double maxTalley = Double . NEGATIVE_INFINITY ; List < X > maxTickets = new ArrayList < X > ( ) ; for ( Entry < X , Double > entry : votes . entrySet ( ) ) { X ticket = entry . getKey ( ) ; double talley = entry . getValue ( ) ; if ( talley > maxTalley ) { maxTickets = new ArrayList < X > ( ) ; maxTickets . add ( ticket ) ; maxTalley = talley ; } else if ( talley == maxTalley ) { maxTickets . add ( ticket ) ; } } return maxTickets ; }
Choose the <X> with the greatest number of votes.
@param <X> The type of the thing being voted for.
@param votes Maps <X> to a Double representing the number of votes
it received.
@return The <X> that received the most votes.