jsancio commented on code in PR #15859:
URL: https://github.com/apache/kafka/pull/15859#discussion_r1595585037


##########
raft/src/main/java/org/apache/kafka/raft/ElectionState.java:
##########
@@ -115,15 +166,51 @@ public boolean equals(Object o) {
         ElectionState that = (ElectionState) o;
 
         if (epoch != that.epoch) return false;
-        if (!leaderIdOpt.equals(that.leaderIdOpt)) return false;
-        return votedIdOpt.equals(that.votedIdOpt);
+        if (!leaderId.equals(that.leaderId)) return false;
+        if (!votedKey.equals(that.votedKey)) return false;
+
+        return voters.equals(that.voters);
     }
 
     @Override
     public int hashCode() {
-        int result = epoch;
-        result = 31 * result + leaderIdOpt.hashCode();
-        result = 31 * result + votedIdOpt.hashCode();
-        return result;
+        return Objects.hash(epoch, leaderId, votedKey, voters);
+    }
+
+    public static ElectionState withVotedCandidate(int epoch, ReplicaKey 
votedKey, Set<Integer> voters) {
+        if (votedKey.id() < 0) {
+            throw new IllegalArgumentException("Illegal voted Id " + 
votedKey.id() + ": must be non-negative");
+        }
+
+        return new ElectionState(epoch, OptionalInt.empty(), 
Optional.of(votedKey), voters);
+    }
+
+    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);
+    }
+
+    public static ElectionState withUnknownLeader(int epoch, Set<Integer> 
voters) {
+        return new ElectionState(epoch, OptionalInt.empty(), Optional.empty(), 
voters);
+    }
+
+    public static ElectionState fromQuorumStateData(QuorumStateData data) {
+        Optional<Uuid> votedDirectoryId = 
data.votedDirectoryId().equals(noVotedDirectoryId) ?
+            Optional.empty() :
+            Optional.of(data.votedDirectoryId());
+
+        Optional<ReplicaKey> voterKey = data.votedId() == notVoted ?

Review Comment:
   Fixed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to