From 9c489c43b1a8ca680590f236bf8772cf7cb323c1 Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Sat, 8 Jul 2023 11:19:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=20FlexAssert=20?= =?UTF-8?q?=E6=96=AD=E8=A8=80=EF=BC=8C=E5=BC=BA=E5=88=B6=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E8=80=85=E5=9C=A8=E6=8A=9B=E5=87=BA=E5=BC=82=E5=B8=B8=E6=97=B6?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E5=BC=82=E5=B8=B8=E4=BF=A1=E6=81=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/exception/FlexAssert.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/FlexAssert.java diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/FlexAssert.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/FlexAssert.java new file mode 100644 index 00000000..5719db75 --- /dev/null +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/FlexAssert.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mybatisflex.core.exception; + +import java.util.Map; + +/** + * 断言。 + * + * @author 王帅 + * @since 2023-07-08 + */ +public final class FlexAssert { + + private FlexAssert() { + } + + /** + * 断言对象不为空,如果为空抛出异常,并指明哪个对象为空。 + * + * @param obj 对象 + * @param msg 错误消息 + * @throws MybatisFlexException 如果对象为空,抛出此异常。 + */ + public static void notNull(Object obj, String msg) { + if (obj == null) { + throw FlexExceptions.wrap(msg); + } + } + + /** + * 断言 Map 集合不为 {@code null} 或者空集合,如果为空则抛出异常,并指明为什么不允许为空集合。 + * + * @param map Map 集合 + * @param msg 错误消息 + * @throws MybatisFlexException 如果集合为空,抛出此异常。 + */ + public static void notEmpty(Map map, String msg) { + if (map == null || map.isEmpty()) { + throw FlexExceptions.wrap(msg); + } + } + +} \ No newline at end of file