Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Remove unnecessary usages of Optional.
Signed-off-by: facewise <dydguskim@gripcorp.co>
  • Loading branch information
facewise committed Aug 18, 2025
commit 36b0ebe31a6b86ecb581a19c55c6f6f56fe3e661
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
package org.springframework.data.redis.cache;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.Set;

import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisKeyCommands;
Expand All @@ -34,6 +33,7 @@
* @author Mark Paluch
* @author Christoph Strobl
* @author John Blum
* @author Yong-Hyun Kim
* @since 2.6
*/
public abstract class BatchStrategies {
Expand Down Expand Up @@ -82,14 +82,15 @@ public long cleanCache(RedisConnection connection, String name, byte[] pattern)

RedisKeyCommands commands = connection.keyCommands();

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

if (keys.length > 0) {
commands.del(keys);
}
if (keys == null || keys.isEmpty()) {
return 0;
}

commands.del(keys.toArray(new byte[0][]));

return keys.length;
return keys.size();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
*
* @author Mark Paluch
* @author Christoph Strobl
* @author Yong-Hyun Kim
* @since 2.0
*/
public class RedisPassword {
Expand All @@ -55,10 +56,11 @@ private RedisPassword(char[] thePassword) {
*/
public static RedisPassword of(@Nullable String passwordAsString) {

return Optional.ofNullable(passwordAsString) //
.filter(StringUtils::hasText) //
.map(it -> new RedisPassword(it.toCharArray())) //
.orElseGet(RedisPassword::none);
if (!StringUtils.hasText(passwordAsString)) {
return none();
}

return new RedisPassword(passwordAsString.toCharArray());
}

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

return Optional.ofNullable(passwordAsChars) //
.filter(it -> !ObjectUtils.isEmpty(passwordAsChars)) //
.map(it -> new RedisPassword(Arrays.copyOf(it, it.length))) //
.orElseGet(RedisPassword::none);
if (ObjectUtils.isEmpty(passwordAsChars)) {
return none();
}

return new RedisPassword(Arrays.copyOf(passwordAsChars, passwordAsChars.length));
}

/**
Expand Down