private void Defaults(Role currentRole, ReadableRaftState ctx) { _nextRole = currentRole; _term = ctx.Term(); _leader = ctx.Leader(); _leaderCommit = ctx.LeaderCommit(); _votedFor = ctx.VotedFor(); _renewElectionTimeout = false; _needsFreshSnapshot = false; _isPreElection = (currentRole == Role.FOLLOWER) && ctx.PreElection; _steppingDownInTerm = long?.empty(); _preVotesForMe = _isPreElection ? new HashSet <MemberId>(ctx.PreVotesForMe()) : emptySet(); _votesForMe = (currentRole == Role.CANDIDATE) ? new HashSet <MemberId>(ctx.VotesForMe()) : emptySet(); _heartbeatResponses = (currentRole == Role.LEADER) ? new HashSet <MemberId>(ctx.HeartbeatResponses()) : emptySet(); _lastLogIndexBeforeWeBecameLeader = (currentRole == Role.LEADER) ? ctx.LastLogIndexBeforeWeBecameLeader() : -1; _followerStates = (currentRole == Role.LEADER) ? ctx.FollowerStates() : new FollowerStates <MemberId>(); _commitIndex = ctx.CommitIndex(); }