Skip to content

Commit a85954b

Browse files
authored
Merge pull request #490 from alex268/feature/equals-hashcode-for-descriptions
Feature/equals hashcode for descriptions
2 parents 93293ff + 3b5ce15 commit a85954b

12 files changed

+284
-0
lines changed

topic/src/main/java/tech/ydb/topic/description/Consumer.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.HashMap;
66
import java.util.List;
77
import java.util.Map;
8+
import java.util.Objects;
89
import java.util.stream.Collectors;
910

1011
import javax.annotation.Nonnull;
@@ -140,4 +141,26 @@ public Consumer build() {
140141
return new Consumer(this);
141142
}
142143
}
144+
145+
@Override
146+
public boolean equals(Object o) {
147+
if (this == o) {
148+
return true;
149+
}
150+
if (o == null || getClass() != o.getClass()) {
151+
return false;
152+
}
153+
Consumer consumer = (Consumer) o;
154+
return important == consumer.important &&
155+
Objects.equals(name, consumer.name) &&
156+
Objects.equals(readFrom, consumer.readFrom) &&
157+
Objects.equals(supportedCodecs, consumer.supportedCodecs) &&
158+
Objects.equals(attributes, consumer.attributes) &&
159+
Objects.equals(stats, consumer.stats);
160+
}
161+
162+
@Override
163+
public int hashCode() {
164+
return Objects.hash(name, important, readFrom, supportedCodecs, attributes, stats);
165+
}
143166
}

topic/src/main/java/tech/ydb/topic/description/ConsumerDescription.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
import java.util.List;
5+
import java.util.Objects;
56
import java.util.stream.Collectors;
67

78
import tech.ydb.proto.topic.YdbTopic;
@@ -28,4 +29,21 @@ public Consumer getConsumer() {
2829
public List<ConsumerPartitionInfo> getPartitions() {
2930
return partitions;
3031
}
32+
33+
@Override
34+
public boolean equals(Object o) {
35+
if (this == o) {
36+
return true;
37+
}
38+
if (o == null || getClass() != o.getClass()) {
39+
return false;
40+
}
41+
ConsumerDescription that = (ConsumerDescription) o;
42+
return Objects.equals(consumer, that.consumer) && Objects.equals(partitions, that.partitions);
43+
}
44+
45+
@Override
46+
public int hashCode() {
47+
return Objects.hash(consumer, partitions);
48+
}
3149
}

topic/src/main/java/tech/ydb/topic/description/ConsumerPartitionInfo.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.time.Duration;
44
import java.time.Instant;
55
import java.util.List;
6+
import java.util.Objects;
67

78
import tech.ydb.core.utils.ProtobufUtils;
89
import tech.ydb.proto.topic.YdbTopic;
@@ -178,4 +179,35 @@ public int getConnectionNodeId() {
178179
return connectionNodeId;
179180
}
180181
}
182+
183+
@Override
184+
public boolean equals(Object o) {
185+
if (this == o) {
186+
return true;
187+
}
188+
if (o == null || getClass() != o.getClass()) {
189+
return false;
190+
}
191+
ConsumerPartitionInfo that = (ConsumerPartitionInfo) o;
192+
return partitionId == that.partitionId &&
193+
active == that.active &&
194+
Objects.equals(childPartitionIds, that.childPartitionIds) &&
195+
Objects.equals(parentPartitionIds, that.parentPartitionIds) &&
196+
Objects.equals(partitionStats, that.partitionStats) &&
197+
Objects.equals(consumerStats, that.consumerStats) &&
198+
Objects.equals(location, that.location);
199+
}
200+
201+
@Override
202+
public int hashCode() {
203+
return Objects.hash(
204+
partitionId,
205+
active,
206+
childPartitionIds,
207+
parentPartitionIds,
208+
partitionStats,
209+
consumerStats,
210+
location
211+
);
212+
}
181213
}

topic/src/main/java/tech/ydb/topic/description/MultipleWindowsStat.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package tech.ydb.topic.description;
22

3+
import java.util.Objects;
4+
35
import tech.ydb.proto.topic.YdbTopic;
46

57
/**
@@ -33,4 +35,21 @@ public long getPerHour() {
3335
public long getPerDay() {
3436
return perDay;
3537
}
38+
39+
@Override
40+
public boolean equals(Object o) {
41+
if (this == o) {
42+
return true;
43+
}
44+
if (o == null || getClass() != o.getClass()) {
45+
return false;
46+
}
47+
MultipleWindowsStat that = (MultipleWindowsStat) o;
48+
return perMinute == that.perMinute && perHour == that.perHour && perDay == that.perDay;
49+
}
50+
51+
@Override
52+
public int hashCode() {
53+
return Objects.hash(perMinute, perHour, perDay);
54+
}
3655
}

topic/src/main/java/tech/ydb/topic/description/PartitionInfo.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.ArrayList;
44
import java.util.List;
5+
import java.util.Objects;
56

67
import com.google.common.collect.ImmutableList;
78

@@ -86,4 +87,25 @@ public PartitionInfo build() {
8687
return new PartitionInfo(this);
8788
}
8889
}
90+
91+
@Override
92+
public boolean equals(Object o) {
93+
if (this == o) {
94+
return true;
95+
}
96+
if (o == null || getClass() != o.getClass()) {
97+
return false;
98+
}
99+
PartitionInfo that = (PartitionInfo) o;
100+
return partitionId == that.partitionId &&
101+
active == that.active &&
102+
Objects.equals(childPartitionIds, that.childPartitionIds) &&
103+
Objects.equals(parentPartitionIds, that.parentPartitionIds) &&
104+
Objects.equals(partitionStats, that.partitionStats);
105+
}
106+
107+
@Override
108+
public int hashCode() {
109+
return Objects.hash(partitionId, active, childPartitionIds, parentPartitionIds, partitionStats);
110+
}
89111
}

topic/src/main/java/tech/ydb/topic/description/PartitionStats.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.time.Duration;
44
import java.time.Instant;
5+
import java.util.Objects;
56

67
import javax.annotation.Nullable;
78

@@ -126,4 +127,33 @@ public PartitionStats build() {
126127
return new PartitionStats(this);
127128
}
128129
}
130+
131+
@Override
132+
public boolean equals(Object o) {
133+
if (this == o) {
134+
return true;
135+
}
136+
if (o == null || getClass() != o.getClass()) {
137+
return false;
138+
}
139+
PartitionStats that = (PartitionStats) o;
140+
return storeSizeBytes == that.storeSizeBytes &&
141+
partitionNodeId == that.partitionNodeId &&
142+
Objects.equals(partitionOffsets, that.partitionOffsets) &&
143+
Objects.equals(lastWriteTime, that.lastWriteTime) &&
144+
Objects.equals(maxWriteTimeLag, that.maxWriteTimeLag) &&
145+
Objects.equals(bytesWritten, that.bytesWritten);
146+
}
147+
148+
@Override
149+
public int hashCode() {
150+
return Objects.hash(
151+
partitionOffsets,
152+
storeSizeBytes,
153+
lastWriteTime,
154+
maxWriteTimeLag,
155+
bytesWritten,
156+
partitionNodeId
157+
);
158+
}
129159
}

topic/src/main/java/tech/ydb/topic/description/SupportedCodecs.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.ArrayList;
44
import java.util.List;
5+
import java.util.Objects;
56

67
import com.google.common.collect.ImmutableList;
78

@@ -47,4 +48,21 @@ public SupportedCodecs build() {
4748
return new SupportedCodecs(this);
4849
}
4950
}
51+
52+
@Override
53+
public boolean equals(Object o) {
54+
if (this == o) {
55+
return true;
56+
}
57+
if (o == null || getClass() != o.getClass()) {
58+
return false;
59+
}
60+
SupportedCodecs that = (SupportedCodecs) o;
61+
return Objects.equals(codecs, that.codecs);
62+
}
63+
64+
@Override
65+
public int hashCode() {
66+
return Objects.hashCode(codecs);
67+
}
5068
}

topic/src/main/java/tech/ydb/topic/description/TopicDescription.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.ArrayList;
55
import java.util.List;
66
import java.util.Map;
7+
import java.util.Objects;
78

89
import javax.annotation.Nonnull;
910
import javax.annotation.Nullable;
@@ -179,4 +180,43 @@ public TopicDescription build() {
179180
return new TopicDescription(this);
180181
}
181182
}
183+
184+
@Override
185+
public boolean equals(Object o) {
186+
if (this == o) {
187+
return true;
188+
}
189+
if (o == null || getClass() != o.getClass()) {
190+
return false;
191+
}
192+
TopicDescription that = (TopicDescription) o;
193+
return retentionStorageMb == that.retentionStorageMb &&
194+
partitionWriteSpeedBytesPerSecond == that.partitionWriteSpeedBytesPerSecond &&
195+
partitionWriteBurstBytes == that.partitionWriteBurstBytes &&
196+
Objects.equals(partitioningSettings, that.partitioningSettings) &&
197+
Objects.equals(partitions, that.partitions) &&
198+
Objects.equals(retentionPeriod, that.retentionPeriod) &&
199+
Objects.equals(supportedCodecs, that.supportedCodecs) &&
200+
Objects.equals(attributes, that.attributes) &&
201+
Objects.equals(consumers, that.consumers) &&
202+
meteringMode == that.meteringMode &&
203+
Objects.equals(topicStats, that.topicStats);
204+
}
205+
206+
@Override
207+
public int hashCode() {
208+
return Objects.hash(
209+
partitioningSettings,
210+
partitions,
211+
retentionPeriod,
212+
retentionStorageMb,
213+
supportedCodecs,
214+
partitionWriteSpeedBytesPerSecond,
215+
partitionWriteBurstBytes,
216+
attributes,
217+
consumers,
218+
meteringMode,
219+
topicStats
220+
);
221+
}
182222
}

topic/src/main/java/tech/ydb/topic/description/TopicStats.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.time.Duration;
44
import java.time.Instant;
5+
import java.util.Objects;
56

67
import javax.annotation.Nullable;
78

@@ -76,4 +77,24 @@ public TopicStats build() {
7677
return new TopicStats(this);
7778
}
7879
}
80+
81+
@Override
82+
public boolean equals(Object o) {
83+
if (this == o) {
84+
return true;
85+
}
86+
if (o == null || getClass() != o.getClass()) {
87+
return false;
88+
}
89+
TopicStats that = (TopicStats) o;
90+
return storeSizeBytes == that.storeSizeBytes &&
91+
Objects.equals(minLastWriteTime, that.minLastWriteTime) &&
92+
Objects.equals(maxWriteTimeLag, that.maxWriteTimeLag) &&
93+
Objects.equals(bytesWritten, that.bytesWritten);
94+
}
95+
96+
@Override
97+
public int hashCode() {
98+
return Objects.hash(storeSizeBytes, minLastWriteTime, maxWriteTimeLag, bytesWritten);
99+
}
79100
}

topic/src/main/java/tech/ydb/topic/read/impl/OffsetsRangeImpl.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package tech.ydb.topic.read.impl;
22

3+
import java.util.Objects;
4+
35
import tech.ydb.topic.description.OffsetsRange;
46

57
/**
@@ -36,4 +38,21 @@ public void setStart(long start) {
3638
public void setEnd(long end) {
3739
this.end = end;
3840
}
41+
42+
@Override
43+
public boolean equals(Object o) {
44+
if (this == o) {
45+
return true;
46+
}
47+
if (o == null || getClass() != o.getClass()) {
48+
return false;
49+
}
50+
OffsetsRangeImpl that = (OffsetsRangeImpl) o;
51+
return start == that.start && end == that.end;
52+
}
53+
54+
@Override
55+
public int hashCode() {
56+
return Objects.hash(start, end);
57+
}
3958
}

0 commit comments

Comments
 (0)