From e5152c059d3a69869661e5082633a048c9beecdc Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Mon, 13 Feb 2023 22:36:52 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D1=8B=D0=B5=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4?= =?UTF-8?q?=D1=8B=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=B2=20Checker=20=D0=B8=20Inspector?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/struchkov/haiti/utils/Checker.java | 8 +++++++ .../dev/struchkov/haiti/utils/Inspector.java | 23 ++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/haiti-utils/src/main/java/dev/struchkov/haiti/utils/Checker.java b/haiti-utils/src/main/java/dev/struchkov/haiti/utils/Checker.java index 093b2c8..7173a59 100644 --- a/haiti-utils/src/main/java/dev/struchkov/haiti/utils/Checker.java +++ b/haiti-utils/src/main/java/dev/struchkov/haiti/utils/Checker.java @@ -92,6 +92,14 @@ public final class Checker { return EMPTY.equals(s); } + public static boolean checkNotBlank(String s) { + return checkNotNull(s) && !s.isBlank(); + } + + public static boolean checkBlank(String s) { + return checkNull(s) || s.isBlank(); + } + public static boolean checkFalse(Boolean b) { return b != null && !b; } diff --git a/haiti-utils/src/main/java/dev/struchkov/haiti/utils/Inspector.java b/haiti-utils/src/main/java/dev/struchkov/haiti/utils/Inspector.java index ba8a159..cf09e41 100644 --- a/haiti-utils/src/main/java/dev/struchkov/haiti/utils/Inspector.java +++ b/haiti-utils/src/main/java/dev/struchkov/haiti/utils/Inspector.java @@ -3,7 +3,9 @@ package dev.struchkov.haiti.utils; import java.util.Collection; import java.util.function.Supplier; +import static dev.struchkov.haiti.utils.Checker.checkBlank; import static dev.struchkov.haiti.utils.Checker.checkEmpty; +import static dev.struchkov.haiti.utils.Checker.checkNotBlank; import static dev.struchkov.haiti.utils.Checker.checkNotEmpty; import static dev.struchkov.haiti.utils.Checker.checkNotNull; import static dev.struchkov.haiti.utils.Checker.checkNull; @@ -106,9 +108,11 @@ public final class Inspector { * @throws RuntimeException */ public static void isNotEmpty(Supplier exception, Object... args) { - if (checkEmpty(args)) { - throw exception.get(); - } + if (checkEmpty(args)) throw exception.get(); + } + + public static void isNotEmpty(String s, Supplier exception) { + if (checkEmpty(s)) throw exception.get(); } /** @@ -121,6 +125,10 @@ public final class Inspector { if (checkNotEmpty(collection)) throw exception.get(); } + public static void isEmpty(String s, Supplier exception) { + if (checkNotEmpty(s)) throw exception.get(); + } + /** * Проверка массива на пустоту. Если массив не пустой и не null, то будет выбрашено исключение. * @@ -131,10 +139,19 @@ public final class Inspector { if (checkNotEmpty(args)) throw exception.get(); } + public static void isNotBlank(String s, Supplier exception) { + if (checkBlank(s)) throw exception.get(); + } + + public static void isBlank(String s, Supplier exception) { + if (checkNotBlank(s)) throw exception.get(); + } + /** * Утилитарный класс. */ public static final class Utils { + private Utils() { utilityClass(); }