From 2c4c9069c6bc2417349122c0fd46ce5b95a0cd87 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Fri, 24 Feb 2023 11:10:27 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 -- .../commons/constant/PatternConsts.java | 29 +++++++++ .../{ => commons}/constant/RegexConsts.java | 2 +- .../exception/BaseException.java | 8 +-- .../{ => commons}/exception/IWithCode.java | 2 +- .../plusone/{ => commons}/util/EnumUtil.java | 2 +- .../{ => commons}/util/Enumeration.java | 5 +- .../{ => commons}/util/NumberUtil.java | 2 +- .../plusone/{ => commons}/util/PageDTO.java | 2 +- .../util/PagingAndSortingQueryParams.java | 2 +- .../plusone/commons/util/RegexUtil.java | 38 +++++++++++ .../{ => commons}/util/RestfulResult.java | 2 +- .../xyz/zhouxy/plusone/util/RegexUtil.java | 64 ------------------- 13 files changed, 82 insertions(+), 82 deletions(-) create mode 100644 src/main/java/xyz/zhouxy/plusone/commons/constant/PatternConsts.java rename src/main/java/xyz/zhouxy/plusone/{ => commons}/constant/RegexConsts.java (95%) rename src/main/java/xyz/zhouxy/plusone/{ => commons}/exception/BaseException.java (70%) rename src/main/java/xyz/zhouxy/plusone/{ => commons}/exception/IWithCode.java (89%) rename src/main/java/xyz/zhouxy/plusone/{ => commons}/util/EnumUtil.java (98%) rename src/main/java/xyz/zhouxy/plusone/{ => commons}/util/Enumeration.java (96%) rename src/main/java/xyz/zhouxy/plusone/{ => commons}/util/NumberUtil.java (93%) rename src/main/java/xyz/zhouxy/plusone/{ => commons}/util/PageDTO.java (94%) rename src/main/java/xyz/zhouxy/plusone/{ => commons}/util/PagingAndSortingQueryParams.java (96%) create mode 100644 src/main/java/xyz/zhouxy/plusone/commons/util/RegexUtil.java rename src/main/java/xyz/zhouxy/plusone/{ => commons}/util/RestfulResult.java (97%) delete mode 100644 src/main/java/xyz/zhouxy/plusone/util/RegexUtil.java diff --git a/pom.xml b/pom.xml index aa68b1a..994ed99 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,6 @@ 1.8 1.18.24 2.13.4 - 5.8.11 @@ -29,10 +28,5 @@ jackson-annotations ${jackson.version} - - cn.hutool - hutool-core - ${hutool.version} - \ No newline at end of file diff --git a/src/main/java/xyz/zhouxy/plusone/commons/constant/PatternConsts.java b/src/main/java/xyz/zhouxy/plusone/commons/constant/PatternConsts.java new file mode 100644 index 0000000..9efcf24 --- /dev/null +++ b/src/main/java/xyz/zhouxy/plusone/commons/constant/PatternConsts.java @@ -0,0 +1,29 @@ +package xyz.zhouxy.plusone.commons.constant; + +import java.util.regex.Pattern; + +/** + * 正则表达式常量 + * + * @author ZhouXY + */ +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"); + } +} diff --git a/src/main/java/xyz/zhouxy/plusone/constant/RegexConsts.java b/src/main/java/xyz/zhouxy/plusone/commons/constant/RegexConsts.java similarity index 95% rename from src/main/java/xyz/zhouxy/plusone/constant/RegexConsts.java rename to src/main/java/xyz/zhouxy/plusone/commons/constant/RegexConsts.java index a34c436..2daf331 100644 --- a/src/main/java/xyz/zhouxy/plusone/constant/RegexConsts.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/constant/RegexConsts.java @@ -1,4 +1,4 @@ -package xyz.zhouxy.plusone.constant; +package xyz.zhouxy.plusone.commons.constant; /** * 正则表达式常量 diff --git a/src/main/java/xyz/zhouxy/plusone/exception/BaseException.java b/src/main/java/xyz/zhouxy/plusone/commons/exception/BaseException.java similarity index 70% rename from src/main/java/xyz/zhouxy/plusone/exception/BaseException.java rename to src/main/java/xyz/zhouxy/plusone/commons/exception/BaseException.java index ac6cb7e..87cf1d7 100644 --- a/src/main/java/xyz/zhouxy/plusone/exception/BaseException.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/exception/BaseException.java @@ -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; } diff --git a/src/main/java/xyz/zhouxy/plusone/exception/IWithCode.java b/src/main/java/xyz/zhouxy/plusone/commons/exception/IWithCode.java similarity index 89% rename from src/main/java/xyz/zhouxy/plusone/exception/IWithCode.java rename to src/main/java/xyz/zhouxy/plusone/commons/exception/IWithCode.java index c559573..8671f54 100644 --- a/src/main/java/xyz/zhouxy/plusone/exception/IWithCode.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/exception/IWithCode.java @@ -1,4 +1,4 @@ -package xyz.zhouxy.plusone.exception; +package xyz.zhouxy.plusone.commons.exception; /** * 规定实现类带有 {@code getCode} 方法。 diff --git a/src/main/java/xyz/zhouxy/plusone/util/EnumUtil.java b/src/main/java/xyz/zhouxy/plusone/commons/util/EnumUtil.java similarity index 98% rename from src/main/java/xyz/zhouxy/plusone/util/EnumUtil.java rename to src/main/java/xyz/zhouxy/plusone/commons/util/EnumUtil.java index 522ed87..832d270 100644 --- a/src/main/java/xyz/zhouxy/plusone/util/EnumUtil.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/EnumUtil.java @@ -1,4 +1,4 @@ -package xyz.zhouxy.plusone.util; +package xyz.zhouxy.plusone.commons.util; import java.util.Objects; diff --git a/src/main/java/xyz/zhouxy/plusone/util/Enumeration.java b/src/main/java/xyz/zhouxy/plusone/commons/util/Enumeration.java similarity index 96% rename from src/main/java/xyz/zhouxy/plusone/util/Enumeration.java rename to src/main/java/xyz/zhouxy/plusone/commons/util/Enumeration.java index 4ad6e6e..f94a4a8 100644 --- a/src/main/java/xyz/zhouxy/plusone/util/Enumeration.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/Enumeration.java @@ -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> { protected final int value; protected final String name; diff --git a/src/main/java/xyz/zhouxy/plusone/util/NumberUtil.java b/src/main/java/xyz/zhouxy/plusone/commons/util/NumberUtil.java similarity index 93% rename from src/main/java/xyz/zhouxy/plusone/util/NumberUtil.java rename to src/main/java/xyz/zhouxy/plusone/commons/util/NumberUtil.java index b5bac8b..7078ba3 100644 --- a/src/main/java/xyz/zhouxy/plusone/util/NumberUtil.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/NumberUtil.java @@ -1,4 +1,4 @@ -package xyz.zhouxy.plusone.util; +package xyz.zhouxy.plusone.commons.util; /** * NumberUtil diff --git a/src/main/java/xyz/zhouxy/plusone/util/PageDTO.java b/src/main/java/xyz/zhouxy/plusone/commons/util/PageDTO.java similarity index 94% rename from src/main/java/xyz/zhouxy/plusone/util/PageDTO.java rename to src/main/java/xyz/zhouxy/plusone/commons/util/PageDTO.java index dce9bc8..9fa076a 100644 --- a/src/main/java/xyz/zhouxy/plusone/util/PageDTO.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/PageDTO.java @@ -1,4 +1,4 @@ -package xyz.zhouxy.plusone.util; +package xyz.zhouxy.plusone.commons.util; import java.util.List; diff --git a/src/main/java/xyz/zhouxy/plusone/util/PagingAndSortingQueryParams.java b/src/main/java/xyz/zhouxy/plusone/commons/util/PagingAndSortingQueryParams.java similarity index 96% rename from src/main/java/xyz/zhouxy/plusone/util/PagingAndSortingQueryParams.java rename to src/main/java/xyz/zhouxy/plusone/commons/util/PagingAndSortingQueryParams.java index 78b2ddf..9dadeca 100644 --- a/src/main/java/xyz/zhouxy/plusone/util/PagingAndSortingQueryParams.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/PagingAndSortingQueryParams.java @@ -1,4 +1,4 @@ -package xyz.zhouxy.plusone.util; +package xyz.zhouxy.plusone.commons.util; import java.util.Arrays; import java.util.Collections; diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/RegexUtil.java b/src/main/java/xyz/zhouxy/plusone/commons/util/RegexUtil.java new file mode 100644 index 0000000..7550721 --- /dev/null +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/RegexUtil.java @@ -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"); + } +} diff --git a/src/main/java/xyz/zhouxy/plusone/util/RestfulResult.java b/src/main/java/xyz/zhouxy/plusone/commons/util/RestfulResult.java similarity index 97% rename from src/main/java/xyz/zhouxy/plusone/util/RestfulResult.java rename to src/main/java/xyz/zhouxy/plusone/commons/util/RestfulResult.java index 7a596c5..674d77f 100644 --- a/src/main/java/xyz/zhouxy/plusone/util/RestfulResult.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/RestfulResult.java @@ -1,4 +1,4 @@ -package xyz.zhouxy.plusone.util; +package xyz.zhouxy.plusone.commons.util; import com.fasterxml.jackson.annotation.JsonInclude; diff --git a/src/main/java/xyz/zhouxy/plusone/util/RegexUtil.java b/src/main/java/xyz/zhouxy/plusone/util/RegexUtil.java deleted file mode 100644 index 9f88a04..0000000 --- a/src/main/java/xyz/zhouxy/plusone/util/RegexUtil.java +++ /dev/null @@ -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"); - } -}