From c52ec11a4bb8ee8fe31bca892cfcef5c061f531d Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Thu, 21 Jul 2022 00:43:58 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=83=D1=82=D0=B8=D0=BB=D0=B8=D1=82=D0=B0=D1=80=D0=BD?= =?UTF-8?q?=D1=8B=D0=B9=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- haiti-bom/pom.xml | 4 +- haiti-context/pom.xml | 2 +- haiti-core/pom.xml | 2 +- .../SimpleManagerRepositoryMap.java | 16 ++-- .../service/AbstractSimpleManagerService.java | 1 - haiti-exception/pom.xml | 2 +- haiti-filter/pom.xml | 2 +- haiti-utils/pom.xml | 2 +- .../dev/struchkov/haiti/utils/Checker.java | 88 ++++++++++++++++++ .../dev/struchkov/haiti/utils/Inspector.java | 91 ++++--------------- pom.xml | 4 +- 11 files changed, 122 insertions(+), 92 deletions(-) create mode 100644 haiti-utils/src/main/java/dev/struchkov/haiti/utils/Checker.java diff --git a/haiti-bom/pom.xml b/haiti-bom/pom.xml index 8c6f7f0..da7c7eb 100644 --- a/haiti-bom/pom.xml +++ b/haiti-bom/pom.xml @@ -6,7 +6,7 @@ dev.struchkov.haiti haiti-bom - 1.0.2 + 1.0.3 pom Haiti BOM @@ -30,7 +30,7 @@ UTF-8 UTF-8 - 1.0.2 + 1.0.3 ${haiti.ver} ${haiti.ver} diff --git a/haiti-context/pom.xml b/haiti-context/pom.xml index 6747f8c..09b08bf 100644 --- a/haiti-context/pom.xml +++ b/haiti-context/pom.xml @@ -6,7 +6,7 @@ dev.struchkov.haiti haiti - 1.0.2 + 1.0.3 haiti-context diff --git a/haiti-core/pom.xml b/haiti-core/pom.xml index 7d46b64..1e2256a 100644 --- a/haiti-core/pom.xml +++ b/haiti-core/pom.xml @@ -6,7 +6,7 @@ dev.struchkov.haiti haiti - 1.0.2 + 1.0.3 haiti-core diff --git a/haiti-core/src/main/java/dev/struchkov/haiti/core/repository/SimpleManagerRepositoryMap.java b/haiti-core/src/main/java/dev/struchkov/haiti/core/repository/SimpleManagerRepositoryMap.java index f69fa1b..02b203b 100644 --- a/haiti-core/src/main/java/dev/struchkov/haiti/core/repository/SimpleManagerRepositoryMap.java +++ b/haiti-core/src/main/java/dev/struchkov/haiti/core/repository/SimpleManagerRepositoryMap.java @@ -4,7 +4,6 @@ import dev.struchkov.haiti.context.domain.BasicEntity; import dev.struchkov.haiti.context.page.Pagination; import dev.struchkov.haiti.context.page.Sheet; import dev.struchkov.haiti.context.repository.SimpleManagerRepository; -import dev.struchkov.haiti.utils.Inspector; import java.util.Collection; import java.util.HashMap; @@ -13,6 +12,7 @@ import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; +import static dev.struchkov.haiti.utils.Inspector.isNotNull; import static dev.struchkov.haiti.utils.Strings.ERR_OPERATION_NOT_SUPPORTED; public class SimpleManagerRepositoryMap> implements SimpleManagerRepository { @@ -22,7 +22,7 @@ public class SimpleManagerRepositoryMap> implements @Override public T save(T accessTarget) { - Inspector.isNotNull(accessTarget); + isNotNull(accessTarget); accessTarget.setId(key); map.put(key, accessTarget); key++; @@ -31,25 +31,25 @@ public class SimpleManagerRepositoryMap> implements @Override public Optional findById(Long id) { - Inspector.isNotNull(id); + isNotNull(id); return Optional.ofNullable(map.get(id)); } @Override public boolean existsById(Long id) { - Inspector.isNotNull(id); + isNotNull(id); return map.containsKey(id); } @Override public void deleteById(Long id) { - Inspector.isNotNull(id); + isNotNull(id); map.remove(id); } @Override public List saveAll(Collection accessTargets) { - Inspector.isNotNull(accessTargets); + isNotNull(accessTargets); return accessTargets.stream() .map(this::save) .collect(Collectors.toList()); @@ -57,13 +57,13 @@ public class SimpleManagerRepositoryMap> implements @Override public void deleteAllById(Collection accessTargets) { - Inspector.isNotNull(accessTargets); + isNotNull(accessTargets); accessTargets.forEach(map::remove); } @Override public List findAllById(Collection ids) { - Inspector.isNotNull(ids); + isNotNull(ids); return ids.stream() .map(map::get) .collect(Collectors.toList()); diff --git a/haiti-core/src/main/java/dev/struchkov/haiti/core/service/AbstractSimpleManagerService.java b/haiti-core/src/main/java/dev/struchkov/haiti/core/service/AbstractSimpleManagerService.java index 34d73fb..5c2a384 100644 --- a/haiti-core/src/main/java/dev/struchkov/haiti/core/service/AbstractSimpleManagerService.java +++ b/haiti-core/src/main/java/dev/struchkov/haiti/core/service/AbstractSimpleManagerService.java @@ -2,7 +2,6 @@ package dev.struchkov.haiti.core.service; import dev.struchkov.haiti.context.domain.BasicEntity; import dev.struchkov.haiti.context.domain.ExistsContainer; -import dev.struchkov.haiti.context.exception.NotFoundException; import dev.struchkov.haiti.context.page.Pagination; import dev.struchkov.haiti.context.page.Sheet; import dev.struchkov.haiti.context.repository.SimpleManagerRepository; diff --git a/haiti-exception/pom.xml b/haiti-exception/pom.xml index cb37d31..82aba79 100644 --- a/haiti-exception/pom.xml +++ b/haiti-exception/pom.xml @@ -6,7 +6,7 @@ dev.struchkov.haiti haiti - 1.0.2 + 1.0.3 haiti-exception diff --git a/haiti-filter/pom.xml b/haiti-filter/pom.xml index e52c941..312922d 100644 --- a/haiti-filter/pom.xml +++ b/haiti-filter/pom.xml @@ -6,7 +6,7 @@ dev.struchkov.haiti haiti - 1.0.2 + 1.0.3 haiti-filter diff --git a/haiti-utils/pom.xml b/haiti-utils/pom.xml index 883b3d8..19b671c 100644 --- a/haiti-utils/pom.xml +++ b/haiti-utils/pom.xml @@ -6,7 +6,7 @@ dev.struchkov.haiti haiti - 1.0.2 + 1.0.3 Haiti Utils 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 new file mode 100644 index 0000000..a2a188c --- /dev/null +++ b/haiti-utils/src/main/java/dev/struchkov/haiti/utils/Checker.java @@ -0,0 +1,88 @@ +package dev.struchkov.haiti.utils; + +import java.util.Collection; + +import static dev.struchkov.haiti.utils.Exceptions.utilityClass; + +public final class Checker { + + private Checker() { + utilityClass(); + } + + public static boolean checkNull(Object o) { + return o == null; + } + + public static boolean checkNotNull(Object o) { + return o != null; + } + + /** + * Проверка коллекции на пустоту. + * + * @return false - если коллекция null или пустая, true в противном случае. + */ + public static boolean checkNotEmpty(Collection collection) { + return collection != null && !collection.isEmpty(); + } + + /** + * Проверка массива на пустоту + * + * @return false - если массив null или пустой, true в противном случае. + */ + public static boolean checkNotEmpty(Object... args) { + if (args == null) { + return false; + } else { + return args.length > 0; + } + } + + /** + * Проверка коллекции на пустоту. + * + * @return true - если коллекция null или пустая, false в противном случае + */ + public static boolean checkEmpty(Collection collection) { + return collection == null || collection.isEmpty(); + } + + /** + * Проверка массива на пустоту. + * + * @return true - если массив null или пустой, false в противном случае + */ + public static boolean checkEmpty(Object... args) { + return args == null || args.length == 0; + } + + public static boolean checkLong(String s) { + try { + Long.parseLong(s); + return true; + } catch (NumberFormatException e) { + return false; + } + } + + public static boolean checkDouble(String s) { + try { + Double.parseDouble(s); + return true; + } catch (NumberFormatException e) { + return false; + } + } + + public static boolean checkInteger(String s) { + try { + Integer.parseInt(s); + return true; + } catch (NumberFormatException e) { + return false; + } + } + +} 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 3bd7b73..1ddd5eb 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,6 +3,10 @@ package dev.struchkov.haiti.utils; import java.util.Collection; import java.util.function.Supplier; +import static dev.struchkov.haiti.utils.Checker.checkEmpty; +import static dev.struchkov.haiti.utils.Checker.checkNotEmpty; +import static dev.struchkov.haiti.utils.Checker.checkNotNull; +import static dev.struchkov.haiti.utils.Checker.checkNull; import static dev.struchkov.haiti.utils.Exceptions.utilityClass; /** @@ -19,44 +23,24 @@ public final class Inspector { /** * Проверка на null значение с возвращением исключения, если объект не null. * - * @param object Проверяемый объект - * @param exception Возвращаемое исключение + * @param o Проверяемый объект + * @param e Возвращаемое исключение * @throws RuntimeException */ - public static void isNull(Object object, Supplier exception) { - if (object != null) throw exception.get(); + public static void isNull(Object o, Supplier e) { + if (checkNotNull(o)) throw e.get(); } /** * Проверяет множество объектов на null. Если хотябы один объект null, то будет выброшено исключение * - * @param exception исключение, которое необходимо выбросить + * @param e исключение, которое необходимо выбросить * @param objects проверяемое множество объектов * @throws RuntimeException */ - public static void isAnyNotNull(Supplier exception, Object... objects) { - for (Object object : objects) - if (object == null) throw exception.get(); - } - - /** - * Проверка на null значение с возвращением исключения, если объект null. - * - * @param object Проверяемый объект - * @param exception Возвращаемое исключение - */ - public static void isNotNull(Object object, Supplier exception) { - if (object == null) throw exception.get(); - } - - /** - * Проверка на null значение с возвращением исключения, если объект null. - * - * @param object Проверяемый объект - * @throws NullPointerException - */ - public static void isNotNull(Object object) { - if (object == null) throw new NullPointerException("Object cannot be null"); + public static void isAnyNotNull(Supplier e, Object... objects) { + for (Object o : objects) + if (checkNull(o)) throw e.get(); } /** @@ -67,7 +51,7 @@ public final class Inspector { */ public static void isNotNull(Object... objects) { for (Object o : objects) - if (o == null) throw new NullPointerException("Object cannot be null"); + if (checkNull(o)) throw new NullPointerException("Object cannot be null"); } /** @@ -90,46 +74,6 @@ public final class Inspector { if (flag) throw exception.get(); } - /** - * Проверка коллекции на пустоту. - * - * @return false - если коллекция null или пустая, true в противном случае. - */ - public static boolean isNotEmpty(Collection collection) { - return collection != null && !collection.isEmpty(); - } - - /** - * Проверка массива на пустоту - * - * @return false - если массив null или пустой, true в противном случае. - */ - public static boolean isNotEmpty(Object... args) { - if (args == null) { - return false; - } else { - return args.length > 0; - } - } - - /** - * Проверка коллекции на пустоту. - * - * @return true - если коллекция null или пустая, false в противном случае - */ - public static boolean isEmpty(Collection collection) { - return collection == null || collection.isEmpty(); - } - - /** - * Проверка массива на пустоту. - * - * @return true - если массив null или пустой, false в противном случае - */ - public static boolean isEmpty(Object... args) { - return args == null || args.length == 0; - } - /** * Проверка коллекции на пустоту. Если коллекция пустая или null, то будет выбрашено исключение. * @@ -137,7 +81,7 @@ public final class Inspector { * @throws RuntimeException */ public static void isNotEmpty(Collection collection, Supplier exception) { - if (isEmpty(collection)) { + if (checkEmpty(collection)) { throw exception.get(); } } @@ -149,7 +93,7 @@ public final class Inspector { * @throws RuntimeException */ public static void isNotEmpty(Supplier exception, Object... args) { - if (isEmpty(args)) { + if (checkEmpty(args)) { throw exception.get(); } } @@ -161,7 +105,7 @@ public final class Inspector { * @throws RuntimeException */ public static void isEmpty(Collection collection, Supplier exception) { - if (isNotEmpty(collection)) throw exception.get(); + if (checkNotEmpty(collection)) throw exception.get(); } /** @@ -171,14 +115,13 @@ public final class Inspector { * @throws RuntimeException */ public static void isEmpty(Supplier exception, Object... args) { - if (isNotEmpty(args)) throw exception.get(); + if (checkNotEmpty(args)) throw exception.get(); } /** * Утилитарный класс. */ public static final class Utils { - private Utils() { utilityClass(); } diff --git a/pom.xml b/pom.xml index 8466ddc..8cb7177 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ dev.struchkov.haiti haiti - 1.0.2 + 1.0.3 pom Haiti Framework @@ -39,7 +39,7 @@ UTF-8 UTF-8 - 1.0.2 + 1.0.3 ${haiti.ver} ${haiti.ver}