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

Implement equals and hashcode in Params classes #3728

Merged
merged 2 commits into from
Mar 25, 2024
Merged
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
12 changes: 12 additions & 0 deletions src/main/java/redis/clients/jedis/args/RawableFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ public Raw(byte[] raw) {
public byte[] getRaw() {
return raw;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
return Arrays.equals(raw, ((Raw) o).raw);
}

@Override
public int hashCode() {
return Arrays.hashCode(raw);
}
}

/**
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/redis/clients/jedis/params/BitPosParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import redis.clients.jedis.CommandArguments;
import redis.clients.jedis.args.BitCountOption;

import java.util.Objects;

public class BitPosParams implements IParams {

private Long start;
Expand Down Expand Up @@ -62,4 +64,17 @@ public void addParams(CommandArguments args) {
}
}
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BitPosParams that = (BitPosParams) o;
return Objects.equals(start, that.start) && Objects.equals(end, that.end) && Objects.equals(modifier, that.modifier);
}

@Override
public int hashCode() {
return Objects.hash(start, end, modifier);
}
}
14 changes: 14 additions & 0 deletions src/main/java/redis/clients/jedis/params/ClientKillParams.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package redis.clients.jedis.params;

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

import redis.clients.jedis.CommandArguments;
import redis.clients.jedis.Protocol.Keyword;
Expand Down Expand Up @@ -81,4 +82,17 @@ public ClientKillParams maxAge(long maxAge) {
public void addParams(CommandArguments args) {
params.forEach(kv -> args.add(kv.getKey()).add(kv.getValue()));
}

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

@Override
public int hashCode() {
return Objects.hash(params);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import redis.clients.jedis.CommandArguments;
import redis.clients.jedis.Protocol.Keyword;

import java.util.Objects;

public class CommandListFilterByParams implements IParams {

private String moduleName;
Expand Down Expand Up @@ -46,4 +48,17 @@ public void addParams(CommandArguments args) {
+ getClass().getSimpleName());
}
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CommandListFilterByParams that = (CommandListFilterByParams) o;
return Objects.equals(moduleName, that.moduleName) && Objects.equals(category, that.category) && Objects.equals(pattern, that.pattern);
}

@Override
public int hashCode() {
return Objects.hash(moduleName, category, pattern);
}
}
15 changes: 15 additions & 0 deletions src/main/java/redis/clients/jedis/params/FailoverParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Protocol.Keyword;

import java.util.Objects;

public class FailoverParams implements IParams {

private HostAndPort to;
Expand Down Expand Up @@ -59,4 +61,17 @@ public void addParams(CommandArguments args) {
}

}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FailoverParams that = (FailoverParams) o;
return force == that.force && Objects.equals(to, that.to) && Objects.equals(timeout, that.timeout);
}

@Override
public int hashCode() {
return Objects.hash(to, force, timeout);
}
}
14 changes: 14 additions & 0 deletions src/main/java/redis/clients/jedis/params/GeoAddParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import redis.clients.jedis.CommandArguments;
import redis.clients.jedis.Protocol.Keyword;

import java.util.Objects;

public class GeoAddParams implements IParams {

private boolean nx = false;
Expand Down Expand Up @@ -57,4 +59,16 @@ public void addParams(CommandArguments args) {
}
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
GeoAddParams that = (GeoAddParams) o;
return nx == that.nx && xx == that.xx && ch == that.ch;
}

@Override
public int hashCode() {
return Objects.hash(nx, xx, ch);
}
}
15 changes: 15 additions & 0 deletions src/main/java/redis/clients/jedis/params/GetExParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import redis.clients.jedis.CommandArguments;
import redis.clients.jedis.Protocol.Keyword;

import java.util.Objects;

public class GetExParams implements IParams {

private Keyword expiration;
Expand Down Expand Up @@ -74,4 +76,17 @@ public void addParams(CommandArguments args) {
}
}
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
GetExParams that = (GetExParams) o;
return persist == that.persist && expiration == that.expiration && Objects.equals(expirationValue, that.expirationValue);
}

@Override
public int hashCode() {
return Objects.hash(expiration, expirationValue, persist);
}
}
15 changes: 15 additions & 0 deletions src/main/java/redis/clients/jedis/params/LCSParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import redis.clients.jedis.CommandArguments;
import redis.clients.jedis.Protocol.Keyword;

import java.util.Objects;

public class LCSParams implements IParams {

private boolean len = false;
Expand Down Expand Up @@ -65,4 +67,17 @@ public void addParams(CommandArguments args) {
args.add(Keyword.WITHMATCHLEN);
}
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
LCSParams lcsParams = (LCSParams) o;
return len == lcsParams.len && idx == lcsParams.idx && withMatchLen == lcsParams.withMatchLen && Objects.equals(minMatchLen, lcsParams.minMatchLen);
}

@Override
public int hashCode() {
return Objects.hash(len, idx, minMatchLen, withMatchLen);
}
}
14 changes: 14 additions & 0 deletions src/main/java/redis/clients/jedis/params/LPosParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import redis.clients.jedis.CommandArguments;
import redis.clients.jedis.Protocol.Keyword;

import java.util.Objects;

public class LPosParams implements IParams {

private Integer rank;
Expand Down Expand Up @@ -33,4 +35,16 @@ public void addParams(CommandArguments args) {
}
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
LPosParams that = (LPosParams) o;
return Objects.equals(rank, that.rank) && Objects.equals(maxlen, that.maxlen);
}

@Override
public int hashCode() {
return Objects.hash(rank, maxlen);
}
}
18 changes: 18 additions & 0 deletions src/main/java/redis/clients/jedis/params/LolwutParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import redis.clients.jedis.CommandArguments;
import redis.clients.jedis.Protocol.Keyword;

import java.util.Arrays;
import java.util.Objects;

public class LolwutParams implements IParams {

private Integer version;
Expand Down Expand Up @@ -33,4 +36,19 @@ public void addParams(CommandArguments args) {
}
}
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
LolwutParams that = (LolwutParams) o;
return Objects.equals(version, that.version) && Arrays.equals(opargs, that.opargs);
}

@Override
public int hashCode() {
int result = Objects.hash(version);
result = 31 * result + Arrays.hashCode(opargs);
return result;
}
}
15 changes: 15 additions & 0 deletions src/main/java/redis/clients/jedis/params/MigrateParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import redis.clients.jedis.CommandArguments;
import redis.clients.jedis.Protocol.Keyword;

import java.util.Objects;

public class MigrateParams implements IParams {

private boolean copy = false;
Expand Down Expand Up @@ -52,4 +54,17 @@ public void addParams(CommandArguments args) {
args.add(Keyword.AUTH).add(password);
}
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MigrateParams that = (MigrateParams) o;
return copy == that.copy && replace == that.replace && Objects.equals(username, that.username) && Objects.equals(password, that.password);
}

@Override
public int hashCode() {
return Objects.hash(copy, replace, username, password);
}
}
14 changes: 14 additions & 0 deletions src/main/java/redis/clients/jedis/params/ModuleLoadExParams.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 redis.clients.jedis.CommandArguments;
import redis.clients.jedis.Protocol.Keyword;
Expand Down Expand Up @@ -38,4 +39,17 @@ public void addParams(CommandArguments args) {
args.add(Keyword.ARGS).addObjects(this.args);
}
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ModuleLoadExParams that = (ModuleLoadExParams) o;
return Objects.equals(configs, that.configs) && Objects.equals(args, that.args);
}

@Override
public int hashCode() {
return Objects.hash(configs, args);
}
}
15 changes: 15 additions & 0 deletions src/main/java/redis/clients/jedis/params/RestoreParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import redis.clients.jedis.CommandArguments;
import redis.clients.jedis.Protocol.Keyword;

import java.util.Objects;

public class RestoreParams implements IParams {

private boolean replace;
Expand Down Expand Up @@ -55,4 +57,17 @@ public void addParams(CommandArguments args) {
args.add(Keyword.FREQ).add(frequency);
}
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
RestoreParams that = (RestoreParams) o;
return replace == that.replace && absTtl == that.absTtl && Objects.equals(idleTime, that.idleTime) && Objects.equals(frequency, that.frequency);
}

@Override
public int hashCode() {
return Objects.hash(replace, absTtl, idleTime, frequency);
}
}
14 changes: 14 additions & 0 deletions src/main/java/redis/clients/jedis/params/ScanParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.nio.ByteBuffer;
import java.util.EnumMap;
import java.util.Map;
import java.util.Objects;

import redis.clients.jedis.CommandArguments;
import redis.clients.jedis.Protocol.Keyword;
Expand Down Expand Up @@ -63,4 +64,17 @@ public String match() {
return null;
}
}

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

@Override
public int hashCode() {
return Objects.hash(params);
}
}
16 changes: 16 additions & 0 deletions src/main/java/redis/clients/jedis/params/SetParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import redis.clients.jedis.CommandArguments;
import redis.clients.jedis.Protocol.Keyword;

import java.util.Objects;

public class SetParams implements IParams {

private Keyword existance;
Expand Down Expand Up @@ -106,4 +108,18 @@ public void addParams(CommandArguments args) {
}
}
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SetParams setParams = (SetParams) o;
return Objects.equals(existance, setParams.existance) && Objects.equals(expiration, setParams.expiration)
&& Objects.equals(expirationValue, setParams.expirationValue);
}

@Override
public int hashCode() {
return Objects.hash(existance, expiration, expirationValue);
}
}
Loading
Loading