重构。
parent
3a4a9c5166
commit
2c4c9069c6
6
pom.xml
6
pom.xml
|
@ -14,7 +14,6 @@
|
|||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<lombok.version>1.18.24</lombok.version>
|
||||
<jackson.version>2.13.4</jackson.version>
|
||||
<hutool.version>5.8.11</hutool.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
@ -29,10 +28,5 @@
|
|||
<artifactId>jackson-annotations</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-core</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,29 @@
|
|||
package xyz.zhouxy.plusone.commons.constant;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 正则表达式常量
|
||||
*
|
||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||
*/
|
||||
public final class PatternConsts {
|
||||
|
||||
public static final Pattern DATE = Pattern.compile(RegexConsts.DATE);
|
||||
|
||||
public static final Pattern PASSWORD = Pattern.compile(RegexConsts.PASSWORD);
|
||||
|
||||
public static final Pattern CAPTCHA = Pattern.compile(RegexConsts.CAPTCHA);
|
||||
|
||||
public static final Pattern EMAIL = Pattern.compile(RegexConsts.EMAIL);
|
||||
|
||||
public static final Pattern MOBILE_PHONE = Pattern.compile(RegexConsts.MOBILE_PHONE);
|
||||
|
||||
public static final Pattern USERNAME = Pattern.compile(RegexConsts.USERNAME);
|
||||
|
||||
public static final Pattern NICKNAME = Pattern.compile(RegexConsts.NICKNAME);
|
||||
|
||||
private PatternConsts() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package xyz.zhouxy.plusone.constant;
|
||||
package xyz.zhouxy.plusone.commons.constant;
|
||||
|
||||
/**
|
||||
* 正则表达式常量
|
|
@ -1,4 +1,4 @@
|
|||
package xyz.zhouxy.plusone.exception;
|
||||
package xyz.zhouxy.plusone.commons.exception;
|
||||
|
||||
/**
|
||||
* 带错误码的异常。
|
||||
|
@ -11,17 +11,17 @@ public abstract class BaseException extends RuntimeException implements IWithCod
|
|||
|
||||
private final int code;
|
||||
|
||||
public BaseException(int code, String msg) {
|
||||
protected BaseException(int code, String msg) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public BaseException(int code, Throwable cause) {
|
||||
protected BaseException(int code, Throwable cause) {
|
||||
super(cause);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public BaseException(int code, String msg, Throwable cause) {
|
||||
protected BaseException(int code, String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
this.code = code;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package xyz.zhouxy.plusone.exception;
|
||||
package xyz.zhouxy.plusone.commons.exception;
|
||||
|
||||
/**
|
||||
* 规定实现类带有 {@code getCode} 方法。
|
|
@ -1,4 +1,4 @@
|
|||
package xyz.zhouxy.plusone.util;
|
||||
package xyz.zhouxy.plusone.commons.util;
|
||||
|
||||
import java.util.Objects;
|
||||
|
|
@ -1,9 +1,12 @@
|
|||
package xyz.zhouxy.plusone.util;
|
||||
package xyz.zhouxy.plusone.commons.util;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 枚举类
|
||||
*/
|
||||
public abstract class Enumeration<T extends Enumeration<T>> {
|
||||
protected final int value;
|
||||
protected final String name;
|
|
@ -1,4 +1,4 @@
|
|||
package xyz.zhouxy.plusone.util;
|
||||
package xyz.zhouxy.plusone.commons.util;
|
||||
|
||||
/**
|
||||
* NumberUtil
|
|
@ -1,4 +1,4 @@
|
|||
package xyz.zhouxy.plusone.util;
|
||||
package xyz.zhouxy.plusone.commons.util;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package xyz.zhouxy.plusone.util;
|
||||
package xyz.zhouxy.plusone.commons.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
|
@ -0,0 +1,38 @@
|
|||
package xyz.zhouxy.plusone.commons.util;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class RegexUtil {
|
||||
|
||||
public static boolean matches(CharSequence input, Pattern regex) {
|
||||
Matcher m = regex.matcher(input);
|
||||
return m.matches();
|
||||
}
|
||||
|
||||
public static boolean matchesOr(CharSequence input, Pattern... regexs) {
|
||||
boolean isMatched;
|
||||
for (Pattern regex : regexs) {
|
||||
isMatched = matches(input, regex);
|
||||
if (isMatched) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package xyz.zhouxy.plusone.util;
|
||||
package xyz.zhouxy.plusone.commons.util;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
package xyz.zhouxy.plusone.util;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
|
||||
public class RegexUtil {
|
||||
|
||||
public static boolean matches(CharSequence input, String regex) {
|
||||
return ReUtil.isMatch(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 = 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;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean matchesAnd(CharSequence input, String... regexs) {
|
||||
boolean isMatched;
|
||||
for (String regex : regexs) {
|
||||
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");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue