Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f9dd9bc

Browse files
committed
Polishing.
Simplify code to use well-known Spring patterns. Original pull request: #2752 See #2751
1 parent c7ab023 commit f9dd9bc

File tree

9 files changed

+58
-167
lines changed

9 files changed

+58
-167
lines changed

‎src/main/java/org/springframework/data/redis/cache/RedisCache.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.springframework.data.redis.serializer.RedisSerializationContext;
4040
import org.springframework.data.redis.serializer.RedisSerializer;
4141
import org.springframework.data.redis.util.ByteUtils;
42-
import org.springframework.data.redis.util.RedisAssertions;
4342
import org.springframework.lang.Nullable;
4443
import org.springframework.util.Assert;
4544
import org.springframework.util.ObjectUtils;
@@ -86,8 +85,7 @@ public class RedisCache extends AbstractValueAdaptingCache {
8685
*/
8786
protected RedisCache(String name, RedisCacheWriter cacheWriter, RedisCacheConfiguration cacheConfiguration) {
8887

89-
super(RedisAssertions.requireNonNull(cacheConfiguration, "CacheConfiguration must not be null")
90-
.getAllowCacheNullValues());
88+
super(cacheConfiguration.getAllowCacheNullValues());
9189

9290
Assert.notNull(name, "Name must not be null");
9391
Assert.notNull(cacheWriter, "CacheWriter must not be null");

‎src/main/java/org/springframework/data/redis/cache/RedisCacheManager.java‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.springframework.cache.CacheManager;
2828
import org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager;
2929
import org.springframework.data.redis.connection.RedisConnectionFactory;
30-
import org.springframework.data.redis.util.RedisAssertions;
3130
import org.springframework.lang.Nullable;
3231
import org.springframework.util.Assert;
3332

@@ -103,10 +102,11 @@ public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration d
103102
private RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration,
104103
boolean allowRuntimeCacheCreation) {
105104

106-
this.defaultCacheConfiguration = RedisAssertions.requireNonNull(defaultCacheConfiguration,
107-
"DefaultCacheConfiguration must not be null");
105+
Assert.notNull(defaultCacheConfiguration,"DefaultCacheConfiguration must not be null");
106+
Assert.notNull(cacheWriter, "CacheWriter must not be null");
108107

109-
this.cacheWriter = RedisAssertions.requireNonNull(cacheWriter, "CacheWriter must not be null");
108+
this.defaultCacheConfiguration = defaultCacheConfiguration;
109+
this.cacheWriter = cacheWriter;
110110
this.initialCacheConfiguration = new LinkedHashMap<>();
111111
this.allowRuntimeCacheCreation = allowRuntimeCacheCreation;
112112
}
@@ -423,7 +423,10 @@ public static class RedisCacheManagerBuilder {
423423
* @see org.springframework.data.redis.cache.RedisCacheWriter
424424
*/
425425
public static RedisCacheManagerBuilder fromCacheWriter(RedisCacheWriter cacheWriter) {
426-
return new RedisCacheManagerBuilder(RedisAssertions.requireNonNull(cacheWriter, "CacheWriter must not be null"));
426+
427+
Assert.notNull(cacheWriter, "CacheWriter must not be null");
428+
429+
return new RedisCacheManagerBuilder(cacheWriter);
427430
}
428431

429432
/**
@@ -534,7 +537,10 @@ public RedisCacheManagerBuilder cacheDefaults(RedisCacheConfiguration defaultCac
534537
* @since 2.3
535538
*/
536539
public RedisCacheManagerBuilder cacheWriter(RedisCacheWriter cacheWriter) {
537-
this.cacheWriter = RedisAssertions.requireNonNull(cacheWriter, "CacheWriter must not be null");
540+
541+
Assert.notNull(cacheWriter, "CacheWriter must not be null");
542+
543+
this.cacheWriter = cacheWriter;
538544
return this;
539545
}
540546

@@ -558,8 +564,10 @@ public RedisCacheManagerBuilder enableStatistics() {
558564
*/
559565
public RedisCacheManagerBuilder initialCacheNames(Set<String> cacheNames) {
560566

561-
RedisAssertions.requireNonNull(cacheNames, "CacheNames must not be null")
562-
.forEach(it -> withCacheConfiguration(it, defaultCacheConfiguration));
567+
Assert.notNull(cacheNames, "CacheNames must not be null");
568+
Assert.noNullElements(cacheNames, "CacheNames must not be null");
569+
570+
cacheNames.forEach(it -> withCacheConfiguration(it, defaultCacheConfiguration));
563571

564572
return this;
565573
}
@@ -603,9 +611,9 @@ public RedisCacheManagerBuilder withCacheConfiguration(String cacheName,
603611
public RedisCacheManagerBuilder withInitialCacheConfigurations(
604612
Map<String, RedisCacheConfiguration> cacheConfigurations) {
605613

606-
RedisAssertions.requireNonNull(cacheConfigurations, "CacheConfigurations must not be null")
607-
.forEach((cacheName, cacheConfiguration) -> RedisAssertions.requireNonNull(cacheConfiguration,
608-
"RedisCacheConfiguration for cache [%s] must not be null", cacheName));
614+
Assert.notNull(cacheConfigurations, "CacheConfigurations must not be null!");
615+
cacheConfigurations.forEach((cacheName, configuration) -> Assert.notNull(configuration,
616+
String.format("RedisCacheConfiguration for cache %s must not be null!", cacheName)));
609617

610618
this.initialCaches.putAll(cacheConfigurations);
611619

‎src/main/java/org/springframework/data/redis/connection/RedisClusterConfiguration.java‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.springframework.core.env.MapPropertySource;
2626
import org.springframework.core.env.PropertySource;
2727
import org.springframework.data.redis.connection.RedisConfiguration.ClusterConfiguration;
28-
import org.springframework.data.redis.util.RedisAssertions;
2928
import org.springframework.lang.Nullable;
3029
import org.springframework.util.Assert;
3130
import org.springframework.util.NumberUtils;
@@ -161,7 +160,10 @@ public Set<RedisNode> getClusterNodes() {
161160
* @param node must not be {@literal null}.
162161
*/
163162
public void addClusterNode(RedisNode node) {
164-
this.clusterNodes.add(RedisAssertions.requireNonNull(node, "ClusterNode must not be null"));
163+
164+
Assert.notNull(node, "ClusterNode must not be null");
165+
166+
this.clusterNodes.add(node);
165167
}
166168

167169
/**
@@ -211,7 +213,10 @@ public String getUsername() {
211213

212214
@Override
213215
public void setPassword(RedisPassword password) {
214-
this.password = RedisAssertions.requireNonNull(password, "RedisPassword must not be null");
216+
217+
Assert.notNull(password, "RedisPassword must not be null");
218+
219+
this.password = password;
215220
}
216221

217222
@Override

‎src/main/java/org/springframework/data/redis/connection/RedisClusterNode.java‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.LinkedHashSet;
2323
import java.util.Set;
2424

25-
import org.springframework.data.redis.util.RedisAssertions;
2625
import org.springframework.lang.Nullable;
2726
import org.springframework.util.Assert;
2827
import org.springframework.util.CollectionUtils;
@@ -76,7 +75,9 @@ public RedisClusterNode(String id) {
7675

7776
this(SlotRange.empty());
7877

79-
this.id = RedisAssertions.requireNonNull(id, "Id must not be null");
78+
Assert.notNull(id, "Id must not be null");
79+
80+
this.id = id;
8081
}
8182

8283
/**
@@ -86,8 +87,10 @@ public RedisClusterNode(String id) {
8687
*/
8788
public RedisClusterNode(SlotRange slotRange) {
8889

90+
Assert.notNull(slotRange, "SlotRange must not be null");
91+
8992
this.flags = Collections.emptySet();
90-
this.slotRange = RedisAssertions.requireNonNull(slotRange,"SlotRange must not be null");
93+
this.slotRange = slotRange;
9194
}
9295

9396
/**
@@ -101,8 +104,10 @@ public RedisClusterNode(String host, int port, SlotRange slotRange) {
101104

102105
super(host, port);
103106

107+
Assert.notNull(slotRange, "SlotRange must not be null");
108+
104109
this.flags = Collections.emptySet();
105-
this.slotRange = RedisAssertions.requireNonNull(slotRange,"SlotRange must not be null");
110+
this.slotRange = slotRange;
106111
}
107112

108113
/**

‎src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
import org.springframework.data.redis.connection.RedisConfiguration.ClusterConfiguration;
6464
import org.springframework.data.redis.connection.RedisConfiguration.WithDatabaseIndex;
6565
import org.springframework.data.redis.connection.RedisConfiguration.WithPassword;
66-
import org.springframework.data.redis.util.RedisAssertions;
6766
import org.springframework.data.util.Optionals;
6867
import org.springframework.lang.Nullable;
6968
import org.springframework.util.Assert;
@@ -666,8 +665,11 @@ public AbstractRedisClient getNativeClient() {
666665
*/
667666
public AbstractRedisClient getRequiredNativeClient() {
668667

669-
return RedisAssertions.requireState(getNativeClient(),
670-
"Client not yet initialized; Did you forget to call initialize the bean");
668+
AbstractRedisClient client = getNativeClient();
669+
670+
Assert.state(client != null, "Client not yet initialized; Did you forget to call initialize the bean");
671+
672+
return client;
671673
}
672674

673675
@Nullable

‎src/main/java/org/springframework/data/redis/core/DefaultReactiveZSetOperations.java‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.function.Function;
2828

2929
import org.reactivestreams.Publisher;
30+
3031
import org.springframework.dao.InvalidDataAccessApiUsageException;
3132
import org.springframework.data.domain.Range;
3233
import org.springframework.data.redis.connection.Limit;
@@ -38,7 +39,6 @@
3839
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
3940
import org.springframework.data.redis.serializer.RedisSerializationContext;
4041
import org.springframework.data.redis.util.ByteUtils;
41-
import org.springframework.data.redis.util.RedisAssertions;
4242
import org.springframework.lang.Nullable;
4343
import org.springframework.util.Assert;
4444

@@ -745,8 +745,13 @@ private V readValue(ByteBuffer buffer) {
745745

746746
private V readRequiredValue(ByteBuffer buffer) {
747747

748-
return RedisAssertions.requireNonNull(readValue(buffer),
749-
() -> new InvalidDataAccessApiUsageException("Deserialized sorted set value is null"));
748+
V value = readValue(buffer);
749+
750+
if (value == null) {
751+
throw new InvalidDataAccessApiUsageException("Deserialized sorted set value is null");
752+
}
753+
754+
return value;
750755
}
751756

752757
private TypedTuple<V> readTypedTuple(Tuple raw) {

‎src/main/java/org/springframework/data/redis/serializer/JdkSerializationRedisSerializer.java‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import org.springframework.core.serializer.DefaultSerializer;
2121
import org.springframework.core.serializer.support.DeserializingConverter;
2222
import org.springframework.core.serializer.support.SerializingConverter;
23-
import org.springframework.data.redis.util.RedisAssertions;
2423
import org.springframework.lang.Nullable;
24+
import org.springframework.util.Assert;
2525

2626
/**
2727
* Java Serialization {@link RedisSerializer}.
@@ -77,8 +77,11 @@ public JdkSerializationRedisSerializer(@Nullable ClassLoader classLoader) {
7777
public JdkSerializationRedisSerializer(Converter<Object, byte[]> serializer,
7878
Converter<byte[], Object> deserializer) {
7979

80-
this.serializer = RedisAssertions.requireNonNull(serializer, "Serializer must not be null");
81-
this.deserializer = RedisAssertions.requireNonNull(deserializer, "Deserializer must not be null");
80+
Assert.notNull(serializer, "Serializer must not be null");
81+
Assert.notNull(deserializer, "Deserializer must not be null");
82+
83+
this.serializer = serializer;
84+
this.deserializer = deserializer;
8285
}
8386

8487
@Override

‎src/main/java/org/springframework/data/redis/util/RedisAssertions.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
*
2626
* @author John Blum
2727
* @since 3.1.0
28+
* @deprecated since 3.3, will be removed in a future revision in favor of Spring's {@link Assert} utility.
2829
*/
30+
@Deprecated(since = "3.3", forRemoval = true)
2931
public abstract class RedisAssertions {
3032

3133
/**

‎src/test/java/org/springframework/data/redis/util/RedisAssertionsUnitTests.java‎

Lines changed: 0 additions & 137 deletions
This file was deleted.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /