非空驗證(源代碼Java版)


import java.util.Map;

/**
 *  非空驗證工具類
 */
public class UntilEmpty {

    /**
     * @see: 驗證string類型的是否為空
     */
    public static boolean isNullorEmpty(String str) {
        //為了執行忽略大小寫的比較,可以調用equalsIgnoreCase( )方法。當比較兩個字符串時,它會認為A-Z和a-z是一樣的。
        if ((str == null) || ("".equals(str)) || ("null".equalsIgnoreCase(str)) || ("undefined".equalsIgnoreCase(str))) {
            return true;
        }
        return false;
    }

    /**
     * @see: 驗證實體是否為空
     */
    public static <T> boolean isNullorEmpty(T entity) {
        if (entity == null) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * @see: 驗證StringBuffer類型的是否為空
     */
    public static boolean isNullorEmpty(StringBuffer str) {
        if (str == null ||"".equals(str.toString())  || str.length() == 0) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * @see: 驗證Map類型的是否為空
     */
    public static boolean isNullorEmpty(Map map) {
        if ((map == null) || (map.size() == 0)) {
            return true;
        }
        return false;
    }

 

    /**
     * @see: 驗證Object數組類型的是否為空
     */
    public static boolean isNullorEmpty(Object[] obj) {
        if ((obj == null) || (obj.length == 0)) {
            return true;
        }
        return false;
    }

    /**
     * @see: 驗證Long類型的是否為空
     */
    public static boolean isNullorEmpty(Long longTime) {
        if ((longTime == null) || (longTime.longValue() <= 0L)) {
            return true;
        }
        return false;
    }

    /**
     * @see: 驗證String數組類型的是否為空
     */
    public static boolean isNullorEmpty(String[] str) {
        if ((str == null) || (str.length == 0)) {
            return true;
        }
        return false;
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM