Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[COMMON] rewrite admin.TopicPartitionReplica by java 17 record #1734

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
*/
package org.astraea.common.admin;

import java.util.Objects;

public class TopicPartitionReplica implements Comparable<TopicPartitionReplica> {
public record TopicPartitionReplica(String topic, int partition, int brokerId)
implements Comparable<TopicPartitionReplica> {

public static org.apache.kafka.common.TopicPartitionReplica to(TopicPartitionReplica replica) {
return new org.apache.kafka.common.TopicPartitionReplica(
Expand All @@ -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);
Expand All @@ -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);
}
}