diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/Assert.java b/src/main/java/xyz/zhouxy/plusone/commons/util/Assert.java index ee35e8c..3bc0191 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/Assert.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/Assert.java @@ -166,7 +166,7 @@ public class Assert { Assert.isFalse((arr == null || arr.length() == 0), errorMessageTemplate, args); } - // private consrtuctor + // private constructor private Assert() { throw new IllegalStateException("Utility class"); } 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 90edf0a..a43a38e 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/Enumeration.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/Enumeration.java @@ -21,8 +21,6 @@ import java.util.Map; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; -import javax.annotation.Nonnull; - /** * 枚举类 */ @@ -71,7 +69,7 @@ public abstract class Enumeration> implements Comparabl } protected static final class ValueSet> { - private final Map values = new ConcurrentHashMap<>(); + private final Map values = new ConcurrentHashMap<>(); @SafeVarargs public ValueSet(T... values) { @@ -89,7 +87,7 @@ public abstract class Enumeration> implements Comparabl return this.values.get(id); } - public Collection<@Nonnull T> getValues() { + public Collection getValues() { return 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 66446fd..5af00c3 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/RegexUtil.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/RegexUtil.java @@ -16,7 +16,6 @@ package xyz.zhouxy.plusone.commons.util; -import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.Map; @@ -26,7 +25,7 @@ import java.util.regex.Pattern; public class RegexUtil { - private static final Map PATTERN_CACHE = new ConcurrentHashMap<>(); + private static final Map PATTERN_CACHE = new ConcurrentHashMap<>(); public static Pattern getPattern(final String regex) { Objects.requireNonNull(regex); @@ -34,9 +33,6 @@ public class RegexUtil { return PATTERN_CACHE.get(regex); } Pattern pattern = Pattern.compile(regex); - if (pattern == null) { - throw new IllegalArgumentException("Regex must not be null."); - } PATTERN_CACHE.put(regex, pattern); return pattern; } @@ -47,14 +43,12 @@ public class RegexUtil { public static boolean matches(@Nullable CharSequence input, Pattern pattern) { Assert.notNull(pattern, "Pattern must not be null."); - return pattern.matcher(input).matches(); + return input != null && pattern.matcher(input).matches(); } public static boolean matchesOr(@Nullable CharSequence input, String... regexes) { - boolean isMatched; for (String regex : regexes) { - isMatched = matches(input, regex); - if (isMatched) { + if (matches(input, regex)) { return true; } } @@ -62,10 +56,8 @@ public class RegexUtil { } public static boolean matchesOr(@Nullable CharSequence input, Pattern... patterns) { - boolean isMatched; for (Pattern pattern : patterns) { - isMatched = matches(input, pattern); - if (isMatched) { + if (matches(input, pattern)) { return true; } } @@ -73,10 +65,8 @@ public class RegexUtil { } public static boolean matchesAnd(@Nullable CharSequence input, String... regexes) { - boolean isMatched; for (String regex : regexes) { - isMatched = matches(input, regex); - if (!isMatched) { + if (!matches(input, regex)) { return false; } } @@ -84,10 +74,8 @@ public class RegexUtil { } public static boolean matchesAnd(@Nullable CharSequence input, Pattern... patterns) { - boolean isMatched; for (Pattern pattern : patterns) { - isMatched = matches(input, pattern); - if (!isMatched) { + if (!matches(input, pattern)) { 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 619c4d8..983906c 100644 --- a/src/test/java/xyz/zhouxy/plusone/commons/EnumerationTests.java +++ b/src/test/java/xyz/zhouxy/plusone/commons/EnumerationTests.java @@ -1,6 +1,6 @@ package xyz.zhouxy.plusone.commons; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertSame; import com.google.common.collect.Lists; import org.junit.jupiter.api.Test; @@ -17,8 +17,8 @@ class EnumerationTests { @Test void testEnumeration() { - assertTrue(EntityStatus.AVAILABLE == EntityStatus.of(0)); - assertTrue(Result.SUCCESSFUL == Result.of(1)); + assertSame(EntityStatus.AVAILABLE, EntityStatus.of(0)); + assertSame(Result.SUCCESSFUL, Result.of(1)); Collection>> enums = Lists.newArrayList(); enums.addAll(EntityStatus.constants()); enums.addAll(Result.constants());