public Optional<VoterSet> addVoter(VoterNode voter) {
        if (voters.containsKey(voter.voterKey().id())) {
            return Optional.empty();
        }

        HashMap<Integer, VoterNode> newVoters = new HashMap<>(voters);
        newVoters.put(voter.voterKey().id(), voter);

        return Optional.of(new VoterSet(newVoters));
    }
Adds a voter to the voter set.

This object is immutable. A new voter set is returned if the voter was added.

A new voter can be added to a voter set if its id doesn't already exist in the voter set.

@param voter the new voter to add
@return a new voter set if the voter was added, otherwise {@code Optional.empty()}
raft/src/main/java/org/apache/kafka/raft/internals/VoterSet.java