public static ElectionState withElectedLeader(int epoch, int leaderId, Set<Integer> voters) {
        if (leaderId < 0) {
            throw new IllegalArgumentException("Illegal leader Id " + leaderId + ": must be non-negative");
        }

        return new ElectionState(epoch, OptionalInt.of(leaderId), Optional.empty(), voters);
    }
Return if the replica has voted for the given candidate.

A replica has voted for a candidate if all of the following are true:
1. the node's id and voted id match and
2. if the voted directory id is set, it matches the node's directory id

@param nodeKey the id and directory id of the replica
@return true when the arguments match, otherwise false
raft/src/main/java/org/apache/kafka/raft/ElectionState.java