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 f356947

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

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

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

Lines changed: 9 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.connection.RedisKeyCommands;
@@ -34,6 +33,7 @@
3433
* @author Mark Paluch
3534
* @author Christoph Strobl
3635
* @author John Blum
36+
* @author Yong-Hyun Kim
3737
* @since 2.6
3838
*/
3939
public abstract class BatchStrategies {
@@ -82,14 +82,15 @@ public long cleanCache(RedisConnection connection, String name, byte[] pattern)
8282

8383
RedisKeyCommands commands = connection.keyCommands();
8484

85-
byte[][] keys = Optional.ofNullable(commands.keys(pattern)).orElse(Collections.emptySet())
86-
.toArray(new byte[0][]);
85+
Set<byte[]> keys = commands.keys(pattern);
8786

88-
if (keys.length > 0) {
89-
commands.del(keys);
90-
}
87+
if (keys == null || keys.isEmpty()) {
88+
return 0;
89+
}
90+
91+
commands.del(keys.toArray(new byte[0][]));
9192

92-
return keys.length;
93+
return keys.size();
9394
}
9495
}
9596

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

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

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

6466
/**
@@ -69,10 +71,11 @@ public static RedisPassword of(@Nullable String passwordAsString) {
6971
*/
7072
public static RedisPassword of(char @Nullable[] passwordAsChars) {
7173

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

7881
/**

0 commit comments

Comments
(0)

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