package cn.hanghui.outapi.platform.common.utils;

import java.util.List;
import java.util.Map;

/**
 * @author shisl
 * @package com.yx.face.boot.uitls
 * @class Preconditions
 * @date 2022/9/22 上午11:23
 * @description
 */
public class Preconditions {
    /**
     * check if object is null for List Map String
     *
     * @param t
     * @param <T>
     * @return
     */
    public static <T> boolean isBlank(T t) {

        boolean result = false;

        if (t == null) {
            return true;
        }

        if (t instanceof List) {
            if (((List) t).size() == 0) {
                return true;
            }
        } else if (t instanceof Map) {
            if (((Map) t).size() == 0) {
                return true;
            }
        } else if (t instanceof Object[]) {
            if (((Object[]) t).length == 0) {
                return true;
            }
        } else if (t instanceof String) {
            int strLen;

            strLen = ((String) t).length();
            if (strLen == 0) {
                return true;
            }

            for (int i = 0; i < strLen; i++) {
                if ((!Character.isWhitespace(((String) t).charAt(i)))) {
                    return false;
                }
            }

            return true;
        }

        return result;
    }

    public static <T> boolean isNotBlank(T t) {
        return !isBlank(t);
    }

}
