Skip to content

Commit 15bc22c

Browse files
facewisemp911de
authored andcommitted
Remove unnecessary usages of Optional.
Signed-off-by: facewise <dydguskim@gripcorp.co> Closes #3203
1 parent c178fa1 commit 15bc22c

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
package org.springframework.data.redis.cache;
1717

1818
import java.util.ArrayList;
19-
import java.util.Collections;
2019
import java.util.Iterator;
2120
import java.util.List;
2221
import java.util.NoSuchElementException;
23-
import java.util.Optional;
22+
import java.util.Set;
2423

2524
import org.springframework.data.redis.connection.RedisConnection;
2625
import org.springframework.data.redis.core.Cursor;
@@ -33,6 +32,7 @@
3332
* @author Mark Paluch
3433
* @author Christoph Strobl
3534
* @author John Blum
35+
* @author Yong-Hyun Kim
3636
* @since 2.6
3737
*/
3838
public abstract class BatchStrategies {
@@ -79,14 +79,17 @@ static class Keys implements BatchStrategy {
7979
@Override
8080
public long cleanCache(RedisConnection connection, String name, byte[] pattern) {
8181

82-
byte[][] keys = Optional.ofNullable(connection.keys(pattern)).orElse(Collections.emptySet())
83-
.toArray(new byte[0][]);
82+
RedisKeyCommands commands = connection.keyCommands();
8483

85-
if (keys.length > 0) {
86-
connection.del(keys);
87-
}
84+
Set<byte[]> keys = commands.keys(pattern);
85+
86+
if (keys == null || keys.isEmpty()) {
87+
return 0;
88+
}
89+
90+
commands.del(keys.toArray(new byte[0][]));
8891

89-
return keys.length;
92+
return keys.size();
9093
}
9194
}
9295

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
*
3535
* @author Mark Paluch
3636
* @author Christoph Strobl
37+
* @author Yong-Hyun Kim
3738
* @since 2.0
3839
*/
3940
public class RedisPassword {
@@ -54,10 +55,11 @@ private RedisPassword(char[] thePassword) {
5455
*/
5556
public static RedisPassword of(@Nullable String passwordAsString) {
5657

57-
return Optional.ofNullable(passwordAsString) //
58-
.filter(StringUtils::hasText) //
59-
.map(it -> new RedisPassword(it.toCharArray())) //
60-
.orElseGet(RedisPassword::none);
58+
if (!StringUtils.hasText(passwordAsString)) {
59+
return none();
60+
}
61+
62+
return new RedisPassword(passwordAsString.toCharArray());
6163
}
6264

6365
/**
@@ -68,10 +70,11 @@ public static RedisPassword of(@Nullable String passwordAsString) {
6870
*/
6971
public static RedisPassword of(@Nullable char[] passwordAsChars) {
7072

71-
return Optional.ofNullable(passwordAsChars) //
72-
.filter(it -> !ObjectUtils.isEmpty(passwordAsChars)) //
73-
.map(it -> new RedisPassword(Arrays.copyOf(it, it.length))) //
74-
.orElseGet(RedisPassword::none);
73+
if (ObjectUtils.isEmpty(passwordAsChars)) {
74+
return none();
75+
}
76+
77+
return new RedisPassword(Arrays.copyOf(passwordAsChars, passwordAsChars.length));
7578
}
7679

7780
/**

0 commit comments

Comments
 (0)