smjn commented on code in PR #18929:
URL: https://github.com/apache/kafka/pull/18929#discussion_r2077328972


##########
clients/src/main/java/org/apache/kafka/common/requests/AlterShareGroupOffsetsResponse.java:
##########
@@ -63,4 +66,44 @@ public static AlterShareGroupOffsetsResponse parse(Readable 
readable, short vers
             new AlterShareGroupOffsetsResponseData(readable, version)
         );
     }
+
+    public static class Builder {
+        AlterShareGroupOffsetsResponseData data = new 
AlterShareGroupOffsetsResponseData();
+        HashMap<String, AlterShareGroupOffsetsResponseTopic> topics = new 
HashMap<>();
+
+        private AlterShareGroupOffsetsResponseTopic getOrCreateTopic(String 
topic) {
+            
AlterShareGroupOffsetsResponseData.AlterShareGroupOffsetsResponseTopic 
topicData = topics.get(topic);
+            if (topicData == null) {
+                topicData = new 
AlterShareGroupOffsetsResponseData.AlterShareGroupOffsetsResponseTopic()
+                    .setTopicName(topic);
+                topics.put(topic, topicData);
+            }
+            return topicData;
+        }
+
+        public Builder addPartition(String topic, int partition, Errors error) 
{
+            AlterShareGroupOffsetsResponseTopic topicData = 
getOrCreateTopic(topic);
+            topicData.partitions().add(new 
AlterShareGroupOffsetsResponseData.AlterShareGroupOffsetsResponsePartition()
+                .setPartitionIndex(partition)
+                .setErrorCode(error.code()));
+            return this;
+        }
+
+        public AlterShareGroupOffsetsResponse build() {
+            data.setResponses(new ArrayList<>(topics.values()));
+            return new AlterShareGroupOffsetsResponse(data);
+        }
+
+        public Builder merge(AlterShareGroupOffsetsResponseData data) {
+            data.responses().forEach(topic -> {
+                AlterShareGroupOffsetsResponseTopic newTopic = 
getOrCreateTopic(topic.topicName());
+                topic.partitions().forEach(partition -> 
newTopic.partitions().add(
+                    new 
AlterShareGroupOffsetsResponseData.AlterShareGroupOffsetsResponsePartition()
+                        .setPartitionIndex(partition.partitionIndex())
+                        .setErrorCode(partition.errorCode())));

Review Comment:
   error message too



##########
clients/src/main/java/org/apache/kafka/common/requests/AlterShareGroupOffsetsResponse.java:
##########
@@ -63,4 +66,44 @@ public static AlterShareGroupOffsetsResponse parse(Readable 
readable, short vers
             new AlterShareGroupOffsetsResponseData(readable, version)
         );
     }
+
+    public static class Builder {
+        AlterShareGroupOffsetsResponseData data = new 
AlterShareGroupOffsetsResponseData();
+        HashMap<String, AlterShareGroupOffsetsResponseTopic> topics = new 
HashMap<>();
+
+        private AlterShareGroupOffsetsResponseTopic getOrCreateTopic(String 
topic) {
+            
AlterShareGroupOffsetsResponseData.AlterShareGroupOffsetsResponseTopic 
topicData = topics.get(topic);
+            if (topicData == null) {
+                topicData = new 
AlterShareGroupOffsetsResponseData.AlterShareGroupOffsetsResponseTopic()
+                    .setTopicName(topic);
+                topics.put(topic, topicData);
+            }
+            return topicData;
+        }
+
+        public Builder addPartition(String topic, int partition, Errors error) 
{
+            AlterShareGroupOffsetsResponseTopic topicData = 
getOrCreateTopic(topic);
+            topicData.partitions().add(new 
AlterShareGroupOffsetsResponseData.AlterShareGroupOffsetsResponsePartition()
+                .setPartitionIndex(partition)
+                .setErrorCode(error.code()));

Review Comment:
   err message too



-- 
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