Skip to content

Add equals() and hashCode() methods to topic description classes #480

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

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions topic/src/main/java/tech/ydb/topic/description/Consumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -140,4 +141,23 @@ public Consumer build() {
return new Consumer(this);
}
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
Consumer consumer = (Consumer) o;
return important == consumer.important &&
Objects.equals(name, consumer.name) &&
Objects.equals(readFrom, consumer.readFrom) &&
Objects.equals(supportedCodecs, consumer.supportedCodecs) &&
Objects.equals(attributes, consumer.attributes) &&
Objects.equals(stats, consumer.stats);
}

@Override
public int hashCode() {
return Objects.hash(name, important, readFrom, supportedCodecs, attributes, stats);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import tech.ydb.proto.topic.YdbTopic;
Expand Down Expand Up @@ -29,4 +30,17 @@ public List<ConsumerPartitionInfo> getPartitions() {
return partitions;
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
ConsumerDescription that = (ConsumerDescription) o;
return Objects.equals(consumer, that.consumer) && Objects.equals(partitions, that.partitions);
}

@Override
public int hashCode() {
return Objects.hash(consumer, partitions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.time.Duration;
import java.time.Instant;
import java.util.List;
import java.util.Objects;

import tech.ydb.core.utils.ProtobufUtils;
import tech.ydb.proto.topic.YdbTopic;
Expand Down Expand Up @@ -178,4 +179,32 @@ public int getConnectionNodeId() {
return connectionNodeId;
}
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
ConsumerPartitionInfo that = (ConsumerPartitionInfo) o;
return partitionId == that.partitionId &&
active == that.active &&
Objects.equals(childPartitionIds, that.childPartitionIds) &&
Objects.equals(parentPartitionIds, that.parentPartitionIds) &&
Objects.equals(partitionStats, that.partitionStats) &&
Objects.equals(consumerStats, that.consumerStats) &&
Objects.equals(location, that.location);
}

@Override
public int hashCode() {
return Objects.hash(
partitionId,
active,
childPartitionIds,
parentPartitionIds,
partitionStats,
consumerStats,
location
);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package tech.ydb.topic.description;

import java.util.Objects;

import tech.ydb.proto.topic.YdbTopic;

/**
Expand Down Expand Up @@ -33,4 +35,18 @@ public long getPerHour() {
public long getPerDay() {
return perDay;
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
MultipleWindowsStat that = (MultipleWindowsStat) o;
return perMinute == that.perMinute && perHour == that.perHour && perDay == that.perDay;
}

@Override
public int hashCode() {
return Objects.hash(perMinute, perHour, perDay);
}
}
19 changes: 19 additions & 0 deletions topic/src/main/java/tech/ydb/topic/description/PartitionInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import com.google.common.collect.ImmutableList;

Expand Down Expand Up @@ -86,4 +87,22 @@ public PartitionInfo build() {
return new PartitionInfo(this);
}
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
PartitionInfo that = (PartitionInfo) o;
return partitionId == that.partitionId &&
active == that.active &&
Objects.equals(childPartitionIds, that.childPartitionIds) &&
Objects.equals(parentPartitionIds, that.parentPartitionIds) &&
Objects.equals(partitionStats, that.partitionStats);
}

@Override
public int hashCode() {
return Objects.hash(partitionId, active, childPartitionIds, parentPartitionIds, partitionStats);
}
}
27 changes: 27 additions & 0 deletions topic/src/main/java/tech/ydb/topic/description/PartitionStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.time.Duration;
import java.time.Instant;
import java.util.Objects;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -126,4 +127,30 @@ public PartitionStats build() {
return new PartitionStats(this);
}
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
PartitionStats that = (PartitionStats) o;
return storeSizeBytes == that.storeSizeBytes &&
partitionNodeId == that.partitionNodeId &&
Objects.equals(partitionOffsets, that.partitionOffsets) &&
Objects.equals(lastWriteTime, that.lastWriteTime) &&
Objects.equals(maxWriteTimeLag, that.maxWriteTimeLag) &&
Objects.equals(bytesWritten, that.bytesWritten);
}

@Override
public int hashCode() {
return Objects.hash(
partitionOffsets,
storeSizeBytes,
lastWriteTime,
maxWriteTimeLag,
bytesWritten,
partitionNodeId
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import com.google.common.collect.ImmutableList;

Expand Down Expand Up @@ -47,4 +48,18 @@ public SupportedCodecs build() {
return new SupportedCodecs(this);
}
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
SupportedCodecs that = (SupportedCodecs) o;
return Objects.equals(codecs, that.codecs);
}

@Override
public int hashCode() {
return Objects.hashCode(codecs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -180,4 +181,39 @@ public TopicDescription build() {
}
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
TopicDescription that = (TopicDescription) o;
return retentionStorageMb == that.retentionStorageMb &&
partitionWriteSpeedBytesPerSecond == that.partitionWriteSpeedBytesPerSecond &&
partitionWriteBurstBytes == that.partitionWriteBurstBytes &&
Objects.equals(partitioningSettings, that.partitioningSettings) &&
Objects.equals(partitions, that.partitions) &&
Objects.equals(retentionPeriod, that.retentionPeriod) &&
Objects.equals(supportedCodecs, that.supportedCodecs) &&
Objects.equals(attributes, that.attributes) &&
Objects.equals(consumers, that.consumers) &&
meteringMode == that.meteringMode &&
Objects.equals(topicStats, that.topicStats);
}

@Override
public int hashCode() {
return Objects.hash(
partitioningSettings,
partitions,
retentionPeriod,
retentionStorageMb,
supportedCodecs,
partitionWriteSpeedBytesPerSecond,
partitionWriteBurstBytes,
attributes,
consumers,
meteringMode,
topicStats
);
}
}
18 changes: 18 additions & 0 deletions topic/src/main/java/tech/ydb/topic/description/TopicStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.time.Duration;
import java.time.Instant;
import java.util.Objects;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -76,4 +77,21 @@ public TopicStats build() {
return new TopicStats(this);
}
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
TopicStats that = (TopicStats) o;
return storeSizeBytes == that.storeSizeBytes &&
Objects.equals(minLastWriteTime, that.minLastWriteTime) &&
Objects.equals(maxWriteTimeLag, that.maxWriteTimeLag) &&
Objects.equals(bytesWritten, that.bytesWritten);
}

@Override
public int hashCode() {
return Objects.hash(storeSizeBytes, minLastWriteTime, maxWriteTimeLag, bytesWritten);
}
}
Loading