001/**
002 * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
003 * <p>
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * <p>
008 * http://www.apache.org/licenses/LICENSE-2.0
009 * <p>
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package com.mybatisflex.core.query;
017
018import com.mybatisflex.core.util.ClassUtil;
019import com.mybatisflex.core.util.StringUtil;
020
021import java.lang.reflect.Array;
022import java.util.Collection;
023import java.util.Map;
024
025public class If {
026
027
028    /**
029     * 判断对象是否为空
030     */
031   public static boolean isNull(Object object) {
032        return object == null;
033    }
034
035    /**
036     * 判断对象是否非空
037     */
038    public static boolean notNull(Object object) {
039        return !isNull(object);
040    }
041
042    /**
043     * 查看某个对象是否为空,支持数组、集合、map 等
044     * @param object
045     */
046    public static boolean notEmpty(Object object){
047        if (object == null){
048            return false;
049        }
050
051        if (object instanceof Collection){
052            return !((Collection<?>) object).isEmpty();
053        }
054
055        if (ClassUtil.isArray(object.getClass())){
056            return Array.getLength(object) >0;
057        }
058
059        if (object instanceof Map){
060            return !((Map<?, ?>) object).isEmpty();
061        }
062
063        if (object instanceof String){
064            return StringUtil.isNotBlank((String) object);
065        }
066        return true;
067    }
068
069
070    /**
071     * 查看某个对象是否为空数据 或者 null
072     * @param object
073     */
074    public static boolean isEmpty(Object object){
075        return !notEmpty(object);
076    }
077
078
079    /**
080     * 查看某个 string 对象是否有文本内容
081     * @param object
082     */
083    public static boolean hasText(Object object){
084        return object != null && StringUtil.isNotBlank((String) object);
085    }
086
087}