重构代码,调整 API。

This commit is contained in:
2023-02-18 11:58:06 +08:00
parent 3f4343c996
commit 27183d8e0e
6 changed files with 69 additions and 39 deletions

View File

@@ -2,20 +2,33 @@ package xyz.zhouxy.plusone.util;
import java.util.regex.Pattern;
import cn.hutool.core.util.ReUtil;
public class RegexUtil {
private RegexUtil() {
throw new IllegalStateException("Utility class");
public static boolean matches(CharSequence input, String regex) {
return ReUtil.isMatch(regex, input);
}
public static boolean matches(CharSequence input, String regex) {
return Pattern.matches(regex, input);
public static boolean matches(CharSequence input, Pattern regex) {
return ReUtil.isMatch(regex, input);
}
public static boolean matchesOr(CharSequence input, String... regexs) {
boolean isMatched;
for (String regex : regexs) {
isMatched = Pattern.matches(regex, input);
isMatched = matches(input, regex);
if (isMatched) {
return true;
}
}
return false;
}
public static boolean matchesOr(CharSequence input, Pattern... regexs) {
boolean isMatched;
for (Pattern regex : regexs) {
isMatched = matches(input, regex);
if (isMatched) {
return true;
}
@@ -26,11 +39,26 @@ public class RegexUtil {
public static boolean matchesAnd(CharSequence input, String... regexs) {
boolean isMatched;
for (String regex : regexs) {
isMatched = Pattern.matches(regex, input);
isMatched = matches(input, regex);
if (!isMatched) {
return false;
}
}
return true;
}
public static boolean matchesAnd(CharSequence input, Pattern... regexs) {
boolean isMatched;
for (Pattern regex : regexs) {
isMatched = matches(input, regex);
if (!isMatched) {
return false;
}
}
return true;
}
private RegexUtil() {
throw new IllegalStateException("Utility class");
}
}