Skip to content

Commit 394ff5c

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 15bc22c commit 394ff5c

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: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
import java.util.Set;
2323

2424
import org.springframework.data.redis.connection.RedisConnection;
25+
import org.springframework.data.redis.connection.RedisKeyCommands;
2526
import org.springframework.data.redis.core.Cursor;
2627
import org.springframework.data.redis.core.ScanOptions;
2728
import org.springframework.util.Assert;
29+
import org.springframework.util.CollectionUtils;
2830

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

8284
RedisKeyCommands commands = connection.keyCommands();
8385

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

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

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

9294
return keys.size();
9395
}

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

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

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

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

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
import org.springframework.data.redis.connection.RedisConfiguration.ClusterConfiguration;
6565
import org.springframework.data.redis.connection.RedisConfiguration.WithDatabaseIndex;
6666
import org.springframework.data.redis.connection.RedisConfiguration.WithPassword;
67-
import org.springframework.data.util.Optionals;
6867
import org.springframework.lang.Nullable;
6968
import org.springframework.util.Assert;
7069
import org.springframework.util.ClassUtils;
@@ -1190,8 +1189,13 @@ public void resetConnection() {
11901189

11911190
doInLock(() -> {
11921191

1193-
Optionals.toStream(Optional.ofNullable(this.connection), Optional.ofNullable(this.reactiveConnection))
1194-
.forEach(SharedConnection::resetConnection);
1192+
if (this.connection != null) {
1193+
this.connection.resetConnection();
1194+
}
1195+
1196+
if (this.reactiveConnection != null) {
1197+
this.reactiveConnection.resetConnection();
1198+
}
11951199

11961200
this.connection = null;
11971201
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)