重构。

feature/net-util
ZhouXY108 2023-02-24 11:10:27 +08:00
parent 3a4a9c5166
commit 2c4c9069c6
13 changed files with 82 additions and 82 deletions

View File

@ -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>

View File

@ -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");
}
}

View File

@ -1,4 +1,4 @@
package xyz.zhouxy.plusone.constant;
package xyz.zhouxy.plusone.commons.constant;
/**
*

View File

@ -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;
}

View File

@ -1,4 +1,4 @@
package xyz.zhouxy.plusone.exception;
package xyz.zhouxy.plusone.commons.exception;
/**
* {@code getCode}

View File

@ -1,4 +1,4 @@
package xyz.zhouxy.plusone.util;
package xyz.zhouxy.plusone.commons.util;
import java.util.Objects;

View File

@ -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;

View File

@ -1,4 +1,4 @@
package xyz.zhouxy.plusone.util;
package xyz.zhouxy.plusone.commons.util;
/**
* NumberUtil

View File

@ -1,4 +1,4 @@
package xyz.zhouxy.plusone.util;
package xyz.zhouxy.plusone.commons.util;
import java.util.List;

View File

@ -1,4 +1,4 @@
package xyz.zhouxy.plusone.util;
package xyz.zhouxy.plusone.commons.util;
import java.util.Arrays;
import java.util.Collections;

View File

@ -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");
}
}

View File

@ -1,4 +1,4 @@
package xyz.zhouxy.plusone.util;
package xyz.zhouxy.plusone.commons.util;
import com.fasterxml.jackson.annotation.JsonInclude;

View File

@ -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");
}
}