From 0a4ad3a5bac48418f17fee26eedb272af3049803 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Tue, 4 Apr 2023 00:20:02 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8C=96=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zhouxy/plusone/validator/BoolValidator.java | 8 +++++--- .../plusone/validator/CollectionValidator.java | 16 ++++------------ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/main/java/xyz/zhouxy/plusone/validator/BoolValidator.java b/src/main/java/xyz/zhouxy/plusone/validator/BoolValidator.java index 9912c37..fa408f6 100644 --- a/src/main/java/xyz/zhouxy/plusone/validator/BoolValidator.java +++ b/src/main/java/xyz/zhouxy/plusone/validator/BoolValidator.java @@ -3,6 +3,8 @@ package xyz.zhouxy.plusone.validator; import java.util.function.Function; import java.util.function.Supplier; +import org.apache.commons.lang3.BooleanUtils; + public class BoolValidator extends PropertyValidator> { BoolValidator(Function getter) { @@ -25,7 +27,7 @@ public class BoolValidator extends PropertyValidator BoolValidator isTrue( Function exceptionCreator) { - withRule(Boolean.TRUE::equals, exceptionCreator); + withRule(BooleanUtils::isTrue, exceptionCreator); return this; } @@ -45,10 +47,10 @@ public class BoolValidator extends PropertyValidator BoolValidator isFalse( Function exceptionCreator) { - withRule(Boolean.FALSE::equals, exceptionCreator); + withRule(BooleanUtils::isFalse, exceptionCreator); return this; } - + @Override protected BoolValidator thisObject() { return this; diff --git a/src/main/java/xyz/zhouxy/plusone/validator/CollectionValidator.java b/src/main/java/xyz/zhouxy/plusone/validator/CollectionValidator.java index d4ab7ba..4526988 100644 --- a/src/main/java/xyz/zhouxy/plusone/validator/CollectionValidator.java +++ b/src/main/java/xyz/zhouxy/plusone/validator/CollectionValidator.java @@ -4,6 +4,8 @@ import java.util.Collection; import java.util.function.Function; import java.util.function.Supplier; +import org.apache.commons.collections4.CollectionUtils; + public class CollectionValidator extends PropertyValidator, CollectionValidator> { CollectionValidator(Function> getter) { @@ -22,12 +24,7 @@ public class CollectionValidator extends PropertyValidator CollectionValidator notEmpty( Function, E> exceptionCreator) { - withRule(value -> { - if (value == null) { - return false; - } - return !((Collection) value).isEmpty(); - }, exceptionCreator); + withRule(CollectionUtils::isNotEmpty, exceptionCreator); return this; } @@ -43,12 +40,7 @@ public class CollectionValidator extends PropertyValidator CollectionValidator isEmpty( Function, E> exceptionCreator) { - withRule(value -> { - if (value == null) { - return true; - } - return ((Collection) value).isEmpty(); - }, exceptionCreator); + withRule(CollectionUtils::isEmpty, exceptionCreator); return this; }