调整代码。

feature/net-util
ZhouXY108 2023-04-15 05:09:25 +08:00
parent ef20960480
commit 1b4958f5f6
3 changed files with 9 additions and 11 deletions

View File

@ -94,7 +94,7 @@ public abstract class Enumeration<T extends Enumeration<T>> implements Comparabl
@Nonnull @Nonnull
public Collection<T> getValues() { public Collection<T> getValues() {
return this.values.values(); return Objects.requireNonNull(this.values.values());
} }
} }
} }

View File

@ -26,16 +26,15 @@ public class RegexUtil {
private static final Map<String, Pattern> PATTERN_CACHE = new ConcurrentHashMap<>(); private static final Map<String, Pattern> PATTERN_CACHE = new ConcurrentHashMap<>();
@Nonnull
public static Pattern getPattern(final String regex) { public static Pattern getPattern(final String regex) {
Objects.requireNonNull(regex); Objects.requireNonNull(regex);
Pattern pattern; Pattern pattern = PATTERN_CACHE.get(regex);
if (!PATTERN_CACHE.containsKey(regex)) { if (pattern == null) {
pattern = Pattern.compile(regex); pattern = Pattern.compile(regex);
PATTERN_CACHE.put(regex, pattern); PATTERN_CACHE.put(regex, pattern);
} else {
pattern = PATTERN_CACHE.get(regex);
} }
return pattern; return Objects.requireNonNull(pattern);
} }
public static boolean matches(@Nonnull CharSequence input, @Nonnull String regex) { public static boolean matches(@Nonnull CharSequence input, @Nonnull String regex) {
@ -49,7 +48,7 @@ public class RegexUtil {
public static boolean matchesOr(@Nonnull CharSequence input, String... regexes) { public static boolean matchesOr(@Nonnull CharSequence input, String... regexes) {
boolean isMatched; boolean isMatched;
for (String regex : regexes) { for (String regex : regexes) {
isMatched = matches(input, regex); isMatched = matches(input, Objects.requireNonNull(regex));
if (isMatched) { if (isMatched) {
return true; return true;
} }
@ -60,7 +59,7 @@ public class RegexUtil {
public static boolean matchesOr(@Nonnull CharSequence input, Pattern... patterns) { public static boolean matchesOr(@Nonnull CharSequence input, Pattern... patterns) {
boolean isMatched; boolean isMatched;
for (Pattern pattern : patterns) { for (Pattern pattern : patterns) {
isMatched = matches(input, pattern); isMatched = matches(input, Objects.requireNonNull(pattern));
if (isMatched) { if (isMatched) {
return true; return true;
} }
@ -71,7 +70,7 @@ public class RegexUtil {
public static boolean matchesAnd(@Nonnull CharSequence input, String... regexes) { public static boolean matchesAnd(@Nonnull CharSequence input, String... regexes) {
boolean isMatched; boolean isMatched;
for (String regex : regexes) { for (String regex : regexes) {
isMatched = matches(input, regex); isMatched = matches(input, Objects.requireNonNull(regex));
if (!isMatched) { if (!isMatched) {
return false; return false;
} }
@ -82,7 +81,7 @@ public class RegexUtil {
public static boolean matchesAnd(@Nonnull CharSequence input, Pattern... patterns) { public static boolean matchesAnd(@Nonnull CharSequence input, Pattern... patterns) {
boolean isMatched; boolean isMatched;
for (Pattern pattern : patterns) { for (Pattern pattern : patterns) {
isMatched = matches(input, pattern); isMatched = matches(input, Objects.requireNonNull(pattern));
if (!isMatched) { if (!isMatched) {
return false; return false;
} }

View File

@ -1,6 +1,5 @@
package xyz.zhouxy.plusone.commons; package xyz.zhouxy.plusone.commons;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;