淘先锋技术网

首页 1 2 3 4 5 6 7

判断对象或者对象数组是否为空。

package com.kinth.common.util;

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

public class ParamValidator {

    public static boolean isNullOrEmptyObject(Object obj) {
        return obj == null || obj.toString().trim().isEmpty();
    }

    public static boolean isNullOrEmptyArray(Object[] array) {
        if(array == null) {
            return true;
        }

        if(array.length ==) {
            return true;
        }

        boolean eachItemIsNull = true;
        for(Object item:array) {
            if(item != null) {
                eachItemIsNull = false;
            }
        }
        return eachItemIsNull;
    }

    public static boolean isNullOrEmptyList(List<?> list) {
        if(list == null) {
            return true;
        }

        if(list.isEmpty()) {
            return true;
        }

        boolean eachItemIsNull = true;
        for(Object item:list) {
            if(item != null) {
                eachItemIsNull = false;
            }
        }
        return eachItemIsNull;
    }

    public static boolean isNullOrEmptyMap(Map<?,?> map) {
        if(map == null) {
            return true;
        }

        if(map.isEmpty()) {
            return true;
        }

        return false;
    }
}