From 0ea68678562f4e950bf8271e11914878329ca703 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Sat, 9 Sep 2023 18:45:02 +0800 Subject: [PATCH] =?UTF-8?q?plusone-commons=20=E4=BF=AE=E6=94=B9=E4=BA=86?= =?UTF-8?q?=20BaseException?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plusone/validator/BaseValidator.java | 2 +- .../validator/InvalidInputException.java | 20 +++++++++---------- .../plusone/validator/PropertyValidator.java | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/xyz/zhouxy/plusone/validator/BaseValidator.java b/src/main/java/xyz/zhouxy/plusone/validator/BaseValidator.java index ae00ac2..847a01d 100644 --- a/src/main/java/xyz/zhouxy/plusone/validator/BaseValidator.java +++ b/src/main/java/xyz/zhouxy/plusone/validator/BaseValidator.java @@ -13,7 +13,7 @@ public class BaseValidator { private final List> propertyValidators = new ArrayList<>(); protected void withRule(final Predicate rule, final String errorMessage) { - withRule(rule, () -> new InvalidInputException(errorMessage)); + withRule(rule, () -> InvalidInputException.of(errorMessage)); } protected void withRule(Predicate rule, Supplier exceptionBuilder) { diff --git a/src/main/java/xyz/zhouxy/plusone/validator/InvalidInputException.java b/src/main/java/xyz/zhouxy/plusone/validator/InvalidInputException.java index b8066cf..90310ce 100644 --- a/src/main/java/xyz/zhouxy/plusone/validator/InvalidInputException.java +++ b/src/main/java/xyz/zhouxy/plusone/validator/InvalidInputException.java @@ -11,29 +11,29 @@ public class InvalidInputException extends BaseException { private static final long serialVersionUID = 7956661913360059670L; - public static final int ERROR_CODE = 4040200; + public static final String ERROR_CODE = "4040200"; - private InvalidInputException(int code, String msg) { + private InvalidInputException(String code, String msg) { super(code, msg); } - private InvalidInputException(int code, Throwable cause) { + private InvalidInputException(String code, Throwable cause) { super(code, cause); } - private InvalidInputException(int code, String msg, Throwable cause) { + private InvalidInputException(String code, String msg, Throwable cause) { super(code, msg, cause); } - public InvalidInputException(String msg) { - this(ERROR_CODE, msg); + public static InvalidInputException of(String msg) { + return new InvalidInputException(ERROR_CODE, msg); } - public InvalidInputException(Throwable cause) { - this(ERROR_CODE, cause); + public static InvalidInputException of(Throwable cause) { + return new InvalidInputException(ERROR_CODE, cause); } - public InvalidInputException(String msg, Throwable cause) { - this(ERROR_CODE, msg, cause); + public static InvalidInputException of(String msg, Throwable cause) { + return new InvalidInputException(ERROR_CODE, msg, cause); } } diff --git a/src/main/java/xyz/zhouxy/plusone/validator/PropertyValidator.java b/src/main/java/xyz/zhouxy/plusone/validator/PropertyValidator.java index a0298d2..2dafff3 100644 --- a/src/main/java/xyz/zhouxy/plusone/validator/PropertyValidator.java +++ b/src/main/java/xyz/zhouxy/plusone/validator/PropertyValidator.java @@ -69,7 +69,7 @@ abstract class PropertyValidator { // ===== equals ===== public THIS equalsThat(Object that) { - return equalsThat(that, value -> new InvalidInputException(String.format("(%s) 必须与 (%s) 相等", value, that))); + return equalsThat(that, value -> InvalidInputException.of(String.format("(%s) 必须与 (%s) 相等", value, that))); } public THIS equalsThat(Object that, String errMsg) { @@ -143,7 +143,7 @@ abstract class PropertyValidator { } static Function convertExceptionCreator(String errMsg) { - return value -> new InvalidInputException(errMsg); + return value -> InvalidInputException.of(errMsg); } static Function convertExceptionCreator(