Skip to content

Commit 7cf0dcd

Browse files
committed
Polishing.
Replace other occurences of Optional being used as conditional substitute. Reformat code to use tab indents instead of spaces. See #3203
1 parent f356947 commit 7cf0dcd

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

src/main/java/org/springframework/data/redis/cache/BatchStrategies.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.springframework.data.redis.core.Cursor;
2727
import org.springframework.data.redis.core.ScanOptions;
2828
import org.springframework.util.Assert;
29+
import org.springframework.util.CollectionUtils;
2930

3031
/**
3132
* Collection of predefined {@link BatchStrategy} implementations using the Redis {@code KEYS} or {@code SCAN} command.
@@ -82,13 +83,13 @@ public long cleanCache(RedisConnection connection, String name, byte[] pattern)
8283

8384
RedisKeyCommands commands = connection.keyCommands();
8485

85-
Set<byte[]> keys = commands.keys(pattern);
86+
Set<byte[]> keys = commands.keys(pattern);
8687

87-
if (keys == null || keys.isEmpty()) {
88-
return 0;
89-
}
88+
if (CollectionUtils.isEmpty(keys)) {
89+
return 0;
90+
}
9091

91-
commands.del(keys.toArray(new byte[0][]));
92+
commands.del(keys.toArray(new byte[0][]));
9293

9394
return keys.size();
9495
}

src/main/java/org/springframework/data/redis/connection/RedisPassword.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,6 @@ public Optional<char[]> toOptional() {
142142
return Optional.empty();
143143
}
144144

145-
@Override
146-
public String toString() {
147-
return "%s[%s]".formatted(getClass().getSimpleName(), isPresent() ? "*****" : "<none>");
148-
}
149-
150145
@Override
151146
public boolean equals(@Nullable Object o) {
152147

@@ -164,4 +159,10 @@ public boolean equals(@Nullable Object o) {
164159
public int hashCode() {
165160
return Objects.hashCode(thePassword);
166161
}
162+
163+
@Override
164+
public String toString() {
165+
return "%s[%s]".formatted(getClass().getSimpleName(), isPresent() ? "*****" : "<none>");
166+
}
167+
167168
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.apache.commons.logging.Log;
5252
import org.apache.commons.logging.LogFactory;
5353
import org.jspecify.annotations.Nullable;
54+
5455
import org.springframework.beans.factory.DisposableBean;
5556
import org.springframework.beans.factory.InitializingBean;
5657
import org.springframework.context.SmartLifecycle;
@@ -64,7 +65,6 @@
6465
import org.springframework.data.redis.connection.RedisConfiguration.ClusterConfiguration;
6566
import org.springframework.data.redis.connection.RedisConfiguration.WithDatabaseIndex;
6667
import org.springframework.data.redis.connection.RedisConfiguration.WithPassword;
67-
import org.springframework.data.util.Optionals;
6868
import org.springframework.util.Assert;
6969
import org.springframework.util.ClassUtils;
7070
import org.springframework.util.ObjectUtils;
@@ -1194,8 +1194,13 @@ public void resetConnection() {
11941194

11951195
doInLock(() -> {
11961196

1197-
Optionals.toStream(Optional.ofNullable(this.connection), Optional.ofNullable(this.reactiveConnection))
1198-
.forEach(SharedConnection::resetConnection);
1197+
if (this.connection != null) {
1198+
this.connection.resetConnection();
1199+
}
1200+
1201+
if (this.reactiveConnection != null) {
1202+
this.reactiveConnection.resetConnection();
1203+
}
11991204

12001205
this.connection = null;
12011206
this.reactiveConnection = null;

src/main/java/org/springframework/data/redis/repository/support/QueryByExampleRedisExecutor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ public void setBeanClassLoader(ClassLoader classLoader) {
118118

119119
@Override
120120
public <S extends T> Optional<S> findOne(Example<S> example) {
121-
122121
return Optional.ofNullable(doFindOne(example));
123122
}
124123

0 commit comments

Comments
 (0)