From 1b4958f5f6f2de4ff9b1184f3c46cbc2c1efec02 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Sat, 15 Apr 2023 05:09:25 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plusone/commons/util/Enumeration.java | 2 +- .../zhouxy/plusone/commons/util/RegexUtil.java | 17 ++++++++--------- .../plusone/commons/EnumerationTests.java | 1 - 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/Enumeration.java b/src/main/java/xyz/zhouxy/plusone/commons/util/Enumeration.java index 4845d55..3be8c8b 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/Enumeration.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/Enumeration.java @@ -94,7 +94,7 @@ public abstract class Enumeration> implements Comparabl @Nonnull public Collection getValues() { - return this.values.values(); + return Objects.requireNonNull(this.values.values()); } } } diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/RegexUtil.java b/src/main/java/xyz/zhouxy/plusone/commons/util/RegexUtil.java index de0959a..88cc8a9 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/RegexUtil.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/RegexUtil.java @@ -26,16 +26,15 @@ public class RegexUtil { private static final Map PATTERN_CACHE = new ConcurrentHashMap<>(); + @Nonnull public static Pattern getPattern(final String regex) { Objects.requireNonNull(regex); - Pattern pattern; - if (!PATTERN_CACHE.containsKey(regex)) { + Pattern pattern = PATTERN_CACHE.get(regex); + if (pattern == null) { pattern = Pattern.compile(regex); 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) { @@ -49,7 +48,7 @@ public class RegexUtil { public static boolean matchesOr(@Nonnull CharSequence input, String... regexes) { boolean isMatched; for (String regex : regexes) { - isMatched = matches(input, regex); + isMatched = matches(input, Objects.requireNonNull(regex)); if (isMatched) { return true; } @@ -60,7 +59,7 @@ public class RegexUtil { public static boolean matchesOr(@Nonnull CharSequence input, Pattern... patterns) { boolean isMatched; for (Pattern pattern : patterns) { - isMatched = matches(input, pattern); + isMatched = matches(input, Objects.requireNonNull(pattern)); if (isMatched) { return true; } @@ -71,7 +70,7 @@ public class RegexUtil { public static boolean matchesAnd(@Nonnull CharSequence input, String... regexes) { boolean isMatched; for (String regex : regexes) { - isMatched = matches(input, regex); + isMatched = matches(input, Objects.requireNonNull(regex)); if (!isMatched) { return false; } @@ -82,7 +81,7 @@ public class RegexUtil { public static boolean matchesAnd(@Nonnull CharSequence input, Pattern... patterns) { boolean isMatched; for (Pattern pattern : patterns) { - isMatched = matches(input, pattern); + isMatched = matches(input, Objects.requireNonNull(pattern)); if (!isMatched) { return false; } diff --git a/src/test/java/xyz/zhouxy/plusone/commons/EnumerationTests.java b/src/test/java/xyz/zhouxy/plusone/commons/EnumerationTests.java index eb73a9e..79ba044 100644 --- a/src/test/java/xyz/zhouxy/plusone/commons/EnumerationTests.java +++ b/src/test/java/xyz/zhouxy/plusone/commons/EnumerationTests.java @@ -1,6 +1,5 @@ package xyz.zhouxy.plusone.commons; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.common.collect.Lists;