public boolean isVotedCandidate(ReplicaKey nodeKey) {
        if (nodeKey.id() < 0) {
            throw new IllegalArgumentException("Invalid node key " + nodeKey);
        } else if (!votedKey.isPresent()) {
            return false;
        } else if (votedKey.get().id() != nodeKey.id()) {
            return false;
        } else if (!votedKey.get().directoryId().isPresent()) {
            // when the persisted voted directory id is not present assume that we voted for this candidate;
            // this happens when the kraft version is 0.
            return true;
        }

        return votedKey.get().directoryId().equals(nodeKey.directoryId());
    }
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