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 bca9392..8c255a2 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/Enumeration.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/Enumeration.java @@ -74,12 +74,12 @@ public abstract class Enumeration> implements Comparabl @SafeVarargs public ValueSet(T... values) { - Map valueMap = new HashMap<>(values.length); + Map temp = new HashMap<>(values.length); for (T value : values) { Assert.notNull(value, "Value must not be null."); - valueMap.put(value.getId(), value); + temp.put(value.getId(), value); } - this.valueMap = Collections.unmodifiableMap(valueMap); + this.valueMap = Collections.unmodifiableMap(temp); } public T get(int id) { 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; } }