From f6e80992cce5ea2ca41d125cb6e2cbf9de5b544c Mon Sep 17 00:00:00 2001 From: Chia-Ping Tsai Date: Fri, 12 May 2023 19:58:14 +0800 Subject: [PATCH] [COMMON] rewrite admin.TopicPartitionReplica by java 17 record --- .../common/admin/TopicPartitionReplica.java | 47 +------------------ 1 file changed, 2 insertions(+), 45 deletions(-) diff --git a/common/src/main/java/org/astraea/common/admin/TopicPartitionReplica.java b/common/src/main/java/org/astraea/common/admin/TopicPartitionReplica.java index e3a056f609..dfc02332e6 100644 --- a/common/src/main/java/org/astraea/common/admin/TopicPartitionReplica.java +++ b/common/src/main/java/org/astraea/common/admin/TopicPartitionReplica.java @@ -16,9 +16,8 @@ */ package org.astraea.common.admin; -import java.util.Objects; - -public class TopicPartitionReplica implements Comparable { +public record TopicPartitionReplica(String topic, int partition, int brokerId) + implements Comparable { public static org.apache.kafka.common.TopicPartitionReplica to(TopicPartitionReplica replica) { return new org.apache.kafka.common.TopicPartitionReplica( @@ -29,16 +28,6 @@ public static TopicPartitionReplica of(String topic, int partition, int brokerId return new TopicPartitionReplica(topic, partition, brokerId); } - private final int brokerId; - private final int partition; - private final String topic; - - private TopicPartitionReplica(String topic, int partition, int brokerId) { - this.partition = partition; - this.topic = topic; - this.brokerId = brokerId; - } - @Override public int compareTo(TopicPartitionReplica o) { var b = Integer.compare(brokerId, o.brokerId); @@ -51,36 +40,4 @@ public int compareTo(TopicPartitionReplica o) { public TopicPartition topicPartition() { return TopicPartition.of(topic, partition); } - - public int brokerId() { - return brokerId; - } - - public int partition() { - return partition; - } - - public String topic() { - return topic; - } - - @Override - public int hashCode() { - return Objects.hash(brokerId, topic, partition); - } - - @Override - public String toString() { - return String.format("%d-%s-%d", brokerId, topic, partition); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - TopicPartitionReplica that = (TopicPartitionReplica) o; - return brokerId == that.brokerId - && partition == that.partition - && Objects.equals(topic, that.topic); - } }