Skip to content

Commit

Permalink
Make use of pattern variable in equals(:Object) method.
Browse files Browse the repository at this point in the history
  • Loading branch information
jxblum committed Jun 26, 2023
1 parent c863f9b commit 5e21ed6
Showing 1 changed file with 27 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.springframework.data.redis.connection;

import static org.springframework.util.StringUtils.*;
import static org.springframework.util.StringUtils.commaDelimitedListToSet;

import java.util.Collection;
import java.util.Collections;
Expand All @@ -27,6 +27,7 @@
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.data.redis.connection.RedisConfiguration.ClusterConfiguration;
import org.springframework.data.redis.util.RedisAssertions;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.NumberUtils;
Expand All @@ -47,11 +48,14 @@ public class RedisClusterConfiguration implements RedisConfiguration, ClusterCon
private static final String REDIS_CLUSTER_NODES_CONFIG_PROPERTY = "spring.redis.cluster.nodes";
private static final String REDIS_CLUSTER_MAX_REDIRECTS_CONFIG_PROPERTY = "spring.redis.cluster.max-redirects";

private Set<RedisNode> clusterNodes;
private @Nullable Integer maxRedirects;
private @Nullable String username = null;

private RedisPassword password = RedisPassword.none();

private final Set<RedisNode> clusterNodes;

private @Nullable String username = null;

/**
* Creates new {@link RedisClusterConfiguration}.
*/
Expand Down Expand Up @@ -94,12 +98,12 @@ public RedisClusterConfiguration(PropertySource<?> propertySource) {
this.clusterNodes = new LinkedHashSet<>();

if (propertySource.containsProperty(REDIS_CLUSTER_NODES_CONFIG_PROPERTY)) {
appendClusterNodes(
commaDelimitedListToSet(propertySource.getProperty(REDIS_CLUSTER_NODES_CONFIG_PROPERTY).toString()));
Object redisClusterNodes = propertySource.getProperty(REDIS_CLUSTER_NODES_CONFIG_PROPERTY);
appendClusterNodes(commaDelimitedListToSet(String.valueOf(redisClusterNodes)));
}
if (propertySource.containsProperty(REDIS_CLUSTER_MAX_REDIRECTS_CONFIG_PROPERTY)) {
this.maxRedirects = NumberUtils.parseNumber(
propertySource.getProperty(REDIS_CLUSTER_MAX_REDIRECTS_CONFIG_PROPERTY).toString(), Integer.class);
Object clusterMaxRedirects = propertySource.getProperty(REDIS_CLUSTER_MAX_REDIRECTS_CONFIG_PROPERTY);
this.maxRedirects = NumberUtils.parseNumber(String.valueOf(clusterMaxRedirects), Integer.class);
}
}

Expand All @@ -110,7 +114,7 @@ public RedisClusterConfiguration(PropertySource<?> propertySource) {
*/
public void setClusterNodes(Iterable<RedisNode> nodes) {

Assert.notNull(nodes, "Cannot set cluster nodes to 'null'");
Assert.notNull(nodes, "Cannot set cluster nodes to null");

this.clusterNodes.clear();

Expand All @@ -130,9 +134,7 @@ public Set<RedisNode> getClusterNodes() {
* @param node must not be {@literal null}.
*/
public void addClusterNode(RedisNode node) {

Assert.notNull(node, "ClusterNode must not be 'null'");
this.clusterNodes.add(node);
this.clusterNodes.add(RedisAssertions.requireNonNull(node, "ClusterNode must not be null"));
}

/**
Expand All @@ -141,6 +143,7 @@ public void addClusterNode(RedisNode node) {
public RedisClusterConfiguration clusterNode(RedisNode node) {

this.clusterNodes.add(node);

return this;
}

Expand All @@ -155,6 +158,7 @@ public Integer getMaxRedirects() {
public void setMaxRedirects(int maxRedirects) {

Assert.isTrue(maxRedirects >= 0, "MaxRedirects must be greater or equal to 0");

this.maxRedirects = maxRedirects;
}

Expand Down Expand Up @@ -192,31 +196,24 @@ public RedisPassword getPassword() {

@Override
public void setPassword(RedisPassword password) {

Assert.notNull(password, "RedisPassword must not be null");

this.password = password;
this.password = RedisAssertions.requireNonNull(password, "RedisPassword must not be null");
}

@Override
public boolean equals(@Nullable Object o) {
if (this == o) {
public boolean equals(@Nullable Object obj) {

if (this == obj) {
return true;
}
if (!(o instanceof RedisClusterConfiguration)) {
return false;
}
RedisClusterConfiguration that = (RedisClusterConfiguration) o;
if (!ObjectUtils.nullSafeEquals(clusterNodes, that.clusterNodes)) {
return false;
}
if (!ObjectUtils.nullSafeEquals(maxRedirects, that.maxRedirects)) {
return false;
}
if (!ObjectUtils.nullSafeEquals(username, that.username)) {

if (!(obj instanceof RedisClusterConfiguration that)) {
return false;
}
return ObjectUtils.nullSafeEquals(password, that.password);

return ObjectUtils.nullSafeEquals(this.clusterNodes, that.clusterNodes)
&& ObjectUtils.nullSafeEquals(this.maxRedirects, that.maxRedirects)
&& ObjectUtils.nullSafeEquals(this.username, that.username)
&& ObjectUtils.nullSafeEquals(this.password, that.password);
}

@Override
Expand All @@ -239,6 +236,7 @@ private static Map<String, Object> asMap(Collection<String> clusterHostAndPorts,
Assert.noNullElements(clusterHostAndPorts, "ClusterHostAndPorts must not contain null elements");

Map<String, Object> map = new HashMap<>();

map.put(REDIS_CLUSTER_NODES_CONFIG_PROPERTY, StringUtils.collectionToCommaDelimitedString(clusterHostAndPorts));

if (redirects >= 0) {
Expand All @@ -247,5 +245,4 @@ private static Map<String, Object> asMap(Collection<String> clusterHostAndPorts,

return map;
}

}

0 comments on commit 5e21ed6

Please sign in to comment.