From 1effa7ac89208ea94af65bb5ff493b5d3d5ce38b Mon Sep 17 00:00:00 2001 From: asc at DI <104837209+ascdi@users.noreply.github.com> Date: Sun, 22 Sep 2024 20:42:46 +0200 Subject: [PATCH] Add equals and hashCode to Timeseries Params classes (#3959) --- .../clients/jedis/timeseries/TSAddParams.java | 33 +++++++++++++ .../jedis/timeseries/TSAlterParams.java | 30 ++++++++++++ .../jedis/timeseries/TSArithByParams.java | 33 +++++++++++++ .../jedis/timeseries/TSCreateParams.java | 31 ++++++++++++ .../clients/jedis/timeseries/TSGetParams.java | 18 +++++++ .../jedis/timeseries/TSMGetParams.java | 23 +++++++++ .../jedis/timeseries/TSMRangeParams.java | 48 +++++++++++++++++++ .../jedis/timeseries/TSRangeParams.java | 38 +++++++++++++++ 8 files changed, 254 insertions(+) diff --git a/src/main/java/redis/clients/jedis/timeseries/TSAddParams.java b/src/main/java/redis/clients/jedis/timeseries/TSAddParams.java index 0a9713cefb..487b5301a2 100644 --- a/src/main/java/redis/clients/jedis/timeseries/TSAddParams.java +++ b/src/main/java/redis/clients/jedis/timeseries/TSAddParams.java @@ -5,6 +5,7 @@ import java.util.LinkedHashMap; import java.util.Map; +import java.util.Objects; import redis.clients.jedis.CommandArguments; import redis.clients.jedis.params.IParams; @@ -125,4 +126,36 @@ public void addParams(CommandArguments args) { labels.entrySet().forEach((entry) -> args.add(entry.getKey()).add(entry.getValue())); } } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + TSAddParams that = (TSAddParams) o; + return ignore == that.ignore && ignoreMaxTimediff == that.ignoreMaxTimediff && + Double.compare(ignoreMaxValDiff, that.ignoreMaxValDiff) == 0 && + Objects.equals(retentionPeriod, that.retentionPeriod) && + encoding == that.encoding && Objects.equals(chunkSize, that.chunkSize) && + duplicatePolicy == that.duplicatePolicy && onDuplicate == that.onDuplicate && + Objects.equals(labels, that.labels); + } + + @Override + public int hashCode() { + int result = Objects.hashCode(retentionPeriod); + result = 31 * result + Objects.hashCode(encoding); + result = 31 * result + Objects.hashCode(chunkSize); + result = 31 * result + Objects.hashCode(duplicatePolicy); + result = 31 * result + Objects.hashCode(onDuplicate); + result = 31 * result + Boolean.hashCode(ignore); + result = 31 * result + Long.hashCode(ignoreMaxTimediff); + result = 31 * result + Double.hashCode(ignoreMaxValDiff); + result = 31 * result + Objects.hashCode(labels); + return result; + } } diff --git a/src/main/java/redis/clients/jedis/timeseries/TSAlterParams.java b/src/main/java/redis/clients/jedis/timeseries/TSAlterParams.java index 50ba9723ac..2a65cc74d9 100644 --- a/src/main/java/redis/clients/jedis/timeseries/TSAlterParams.java +++ b/src/main/java/redis/clients/jedis/timeseries/TSAlterParams.java @@ -6,6 +6,7 @@ import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Objects; import redis.clients.jedis.CommandArguments; import redis.clients.jedis.params.IParams; @@ -106,4 +107,33 @@ public void addParams(CommandArguments args) { labels.entrySet().forEach((entry) -> args.add(entry.getKey()).add(entry.getValue())); } } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + TSAlterParams that = (TSAlterParams) o; + return ignore == that.ignore && ignoreMaxTimediff == that.ignoreMaxTimediff && + Double.compare(ignoreMaxValDiff, that.ignoreMaxValDiff) == 0 && + Objects.equals(retentionPeriod, that.retentionPeriod) && + Objects.equals(chunkSize, that.chunkSize) && + duplicatePolicy == that.duplicatePolicy && Objects.equals(labels, that.labels); + } + + @Override + public int hashCode() { + int result = Objects.hashCode(retentionPeriod); + result = 31 * result + Objects.hashCode(chunkSize); + result = 31 * result + Objects.hashCode(duplicatePolicy); + result = 31 * result + Boolean.hashCode(ignore); + result = 31 * result + Long.hashCode(ignoreMaxTimediff); + result = 31 * result + Double.hashCode(ignoreMaxValDiff); + result = 31 * result + Objects.hashCode(labels); + return result; + } } diff --git a/src/main/java/redis/clients/jedis/timeseries/TSArithByParams.java b/src/main/java/redis/clients/jedis/timeseries/TSArithByParams.java index 1bc3df1c55..7703816d25 100644 --- a/src/main/java/redis/clients/jedis/timeseries/TSArithByParams.java +++ b/src/main/java/redis/clients/jedis/timeseries/TSArithByParams.java @@ -5,6 +5,7 @@ import java.util.LinkedHashMap; import java.util.Map; +import java.util.Objects; import redis.clients.jedis.CommandArguments; import redis.clients.jedis.params.IParams; @@ -117,4 +118,36 @@ public void addParams(CommandArguments args) { labels.entrySet().forEach((entry) -> args.add(entry.getKey()).add(entry.getValue())); } } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + TSArithByParams that = (TSArithByParams) o; + return ignore == that.ignore && ignoreMaxTimediff == that.ignoreMaxTimediff && + Double.compare(ignoreMaxValDiff, that.ignoreMaxValDiff) == 0 && + Objects.equals(timestamp, that.timestamp) && + Objects.equals(retentionPeriod, that.retentionPeriod) && + encoding == that.encoding && Objects.equals(chunkSize, that.chunkSize) && + duplicatePolicy == that.duplicatePolicy && Objects.equals(labels, that.labels); + } + + @Override + public int hashCode() { + int result = Objects.hashCode(timestamp); + result = 31 * result + Objects.hashCode(retentionPeriod); + result = 31 * result + Objects.hashCode(encoding); + result = 31 * result + Objects.hashCode(chunkSize); + result = 31 * result + Objects.hashCode(duplicatePolicy); + result = 31 * result + Boolean.hashCode(ignore); + result = 31 * result + Long.hashCode(ignoreMaxTimediff); + result = 31 * result + Double.hashCode(ignoreMaxValDiff); + result = 31 * result + Objects.hashCode(labels); + return result; + } } diff --git a/src/main/java/redis/clients/jedis/timeseries/TSCreateParams.java b/src/main/java/redis/clients/jedis/timeseries/TSCreateParams.java index 0611383d4d..c9c5face72 100644 --- a/src/main/java/redis/clients/jedis/timeseries/TSCreateParams.java +++ b/src/main/java/redis/clients/jedis/timeseries/TSCreateParams.java @@ -5,6 +5,7 @@ import java.util.LinkedHashMap; import java.util.Map; +import java.util.Objects; import redis.clients.jedis.CommandArguments; import redis.clients.jedis.params.IParams; @@ -121,4 +122,34 @@ public void addParams(CommandArguments args) { labels.entrySet().forEach((entry) -> args.add(entry.getKey()).add(entry.getValue())); } } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + TSCreateParams that = (TSCreateParams) o; + return ignore == that.ignore && ignoreMaxTimediff == that.ignoreMaxTimediff && + Double.compare(ignoreMaxValDiff, that.ignoreMaxValDiff) == 0 && + Objects.equals(retentionPeriod, that.retentionPeriod) && + encoding == that.encoding && Objects.equals(chunkSize, that.chunkSize) && + duplicatePolicy == that.duplicatePolicy && Objects.equals(labels, that.labels); + } + + @Override + public int hashCode() { + int result = Objects.hashCode(retentionPeriod); + result = 31 * result + Objects.hashCode(encoding); + result = 31 * result + Objects.hashCode(chunkSize); + result = 31 * result + Objects.hashCode(duplicatePolicy); + result = 31 * result + Boolean.hashCode(ignore); + result = 31 * result + Long.hashCode(ignoreMaxTimediff); + result = 31 * result + Double.hashCode(ignoreMaxValDiff); + result = 31 * result + Objects.hashCode(labels); + return result; + } } diff --git a/src/main/java/redis/clients/jedis/timeseries/TSGetParams.java b/src/main/java/redis/clients/jedis/timeseries/TSGetParams.java index eb35cf1eae..3525b0e18f 100644 --- a/src/main/java/redis/clients/jedis/timeseries/TSGetParams.java +++ b/src/main/java/redis/clients/jedis/timeseries/TSGetParams.java @@ -27,4 +27,22 @@ public void addParams(CommandArguments args) { args.add(LATEST); } } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + TSGetParams that = (TSGetParams) o; + return latest == that.latest; + } + + @Override + public int hashCode() { + return Boolean.hashCode(latest); + } } diff --git a/src/main/java/redis/clients/jedis/timeseries/TSMGetParams.java b/src/main/java/redis/clients/jedis/timeseries/TSMGetParams.java index c7d08ffde2..c4272c04c3 100644 --- a/src/main/java/redis/clients/jedis/timeseries/TSMGetParams.java +++ b/src/main/java/redis/clients/jedis/timeseries/TSMGetParams.java @@ -4,6 +4,7 @@ import static redis.clients.jedis.timeseries.TimeSeriesProtocol.TimeSeriesKeyword.SELECTED_LABELS; import static redis.clients.jedis.timeseries.TimeSeriesProtocol.TimeSeriesKeyword.WITHLABELS; +import java.util.Arrays; import redis.clients.jedis.CommandArguments; import redis.clients.jedis.params.IParams; @@ -55,4 +56,26 @@ public void addParams(CommandArguments args) { } } } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + TSMGetParams that = (TSMGetParams) o; + return latest == that.latest && withLabels == that.withLabels && + Arrays.equals(selectedLabels, that.selectedLabels); + } + + @Override + public int hashCode() { + int result = Boolean.hashCode(latest); + result = 31 * result + Boolean.hashCode(withLabels); + result = 31 * result + Arrays.hashCode(selectedLabels); + return result; + } } diff --git a/src/main/java/redis/clients/jedis/timeseries/TSMRangeParams.java b/src/main/java/redis/clients/jedis/timeseries/TSMRangeParams.java index 182c90814b..cafe091a3a 100644 --- a/src/main/java/redis/clients/jedis/timeseries/TSMRangeParams.java +++ b/src/main/java/redis/clients/jedis/timeseries/TSMRangeParams.java @@ -7,6 +7,8 @@ import static redis.clients.jedis.timeseries.TimeSeriesProtocol.TimeSeriesKeyword.*; import static redis.clients.jedis.util.SafeEncoder.encode; +import java.util.Arrays; +import java.util.Objects; import redis.clients.jedis.CommandArguments; import redis.clients.jedis.params.IParams; @@ -260,4 +262,50 @@ public void addParams(CommandArguments args) { args.add(GROUPBY).add(groupByLabel).add(REDUCE).add(groupByReduce); } } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + TSMRangeParams that = (TSMRangeParams) o; + return latest == that.latest && withLabels == that.withLabels && + bucketDuration == that.bucketDuration && empty == that.empty && + Objects.equals(fromTimestamp, that.fromTimestamp) && + Objects.equals(toTimestamp, that.toTimestamp) && + Arrays.equals(filterByTimestamps, that.filterByTimestamps) && + Arrays.equals(filterByValues, that.filterByValues) && + Arrays.equals(selectedLabels, that.selectedLabels) && + Objects.equals(count, that.count) && Arrays.equals(align, that.align) && + aggregationType == that.aggregationType && + Arrays.equals(bucketTimestamp, that.bucketTimestamp) && + Arrays.equals(filters, that.filters) && + Objects.equals(groupByLabel, that.groupByLabel) && + Objects.equals(groupByReduce, that.groupByReduce); + } + + @Override + public int hashCode() { + int result = Objects.hashCode(fromTimestamp); + result = 31 * result + Objects.hashCode(toTimestamp); + result = 31 * result + Boolean.hashCode(latest); + result = 31 * result + Arrays.hashCode(filterByTimestamps); + result = 31 * result + Arrays.hashCode(filterByValues); + result = 31 * result + Boolean.hashCode(withLabels); + result = 31 * result + Arrays.hashCode(selectedLabels); + result = 31 * result + Objects.hashCode(count); + result = 31 * result + Arrays.hashCode(align); + result = 31 * result + Objects.hashCode(aggregationType); + result = 31 * result + Long.hashCode(bucketDuration); + result = 31 * result + Arrays.hashCode(bucketTimestamp); + result = 31 * result + Boolean.hashCode(empty); + result = 31 * result + Arrays.hashCode(filters); + result = 31 * result + Objects.hashCode(groupByLabel); + result = 31 * result + Objects.hashCode(groupByReduce); + return result; + } } diff --git a/src/main/java/redis/clients/jedis/timeseries/TSRangeParams.java b/src/main/java/redis/clients/jedis/timeseries/TSRangeParams.java index bab70dcbd6..402e2b88e6 100644 --- a/src/main/java/redis/clients/jedis/timeseries/TSRangeParams.java +++ b/src/main/java/redis/clients/jedis/timeseries/TSRangeParams.java @@ -7,6 +7,8 @@ import static redis.clients.jedis.timeseries.TimeSeriesProtocol.TimeSeriesKeyword.*; import static redis.clients.jedis.util.SafeEncoder.encode; +import java.util.Arrays; +import java.util.Objects; import redis.clients.jedis.CommandArguments; import redis.clients.jedis.params.IParams; @@ -205,4 +207,40 @@ public void addParams(CommandArguments args) { } } } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + TSRangeParams that = (TSRangeParams) o; + return latest == that.latest && bucketDuration == that.bucketDuration && empty == that.empty && + Objects.equals(fromTimestamp, that.fromTimestamp) && + Objects.equals(toTimestamp, that.toTimestamp) && + Arrays.equals(filterByTimestamps, that.filterByTimestamps) && + Arrays.equals(filterByValues, that.filterByValues) && + Objects.equals(count, that.count) && Arrays.equals(align, that.align) && + aggregationType == that.aggregationType && + Arrays.equals(bucketTimestamp, that.bucketTimestamp); + } + + @Override + public int hashCode() { + int result = Objects.hashCode(fromTimestamp); + result = 31 * result + Objects.hashCode(toTimestamp); + result = 31 * result + Boolean.hashCode(latest); + result = 31 * result + Arrays.hashCode(filterByTimestamps); + result = 31 * result + Arrays.hashCode(filterByValues); + result = 31 * result + Objects.hashCode(count); + result = 31 * result + Arrays.hashCode(align); + result = 31 * result + Objects.hashCode(aggregationType); + result = 31 * result + Long.hashCode(bucketDuration); + result = 31 * result + Arrays.hashCode(bucketTimestamp); + result = 31 * result + Boolean.hashCode(empty); + return result; + } }