1. 程式人生 > >常用判空操作工具類

常用判空操作工具類

tis esc mail pre ati bst gradle otn ali

一、項目上校驗空和空集合地方非常多,可以編寫一個工具類統一校驗

package com.moy.custom.utils;

import java.util.Collection;
import java.util.Map;

/**
 * [Project]:moy-gradle-project  <br/>
 * [Email]:[email protected]  <br/>
 * [Date]:2018/1/31  <br/>
 * [Description]: 常用判空操作 <br/>
 *
 * @author YeXiangYang
 */
public
abstract class NullUtils { /** * 對象是空,返回<tt>true<tt/> */ public static boolean objectIsNull(Object obj) { return null == obj; } /** * 對象不是空,返回<tt>true<tt/> */ public static boolean objectIsNotNull(Object obj) { return !objectIsNull(obj); }
/** * 集合是空或者個數小於零,返回<tt>true<tt/> */ public static boolean collectionIsNull(Collection collection) { return null == collection || (collection.size() <= 0); } /** * 集合不是空並且個數大於零,返回<tt>true<tt/> */ public static boolean collectionIsNotNull(Collection collection) {
return !collectionIsNull(collection); } /** * Map是空或者個數小於零,返回<tt>true<tt/> */ public static boolean mapIsEmpty(Map map) { return null == map || (map.size() <= 0); } /** * map不是空並且個數大於零,返回<tt>true<tt/> */ public static boolean mapIsNotEmpty(Map map) { return !mapIsEmpty(map); } /** * CharSequence是空或者長度小於零,返回<tt>true<tt/> */ public static boolean charSequenceIsEmpty(CharSequence charSequence) { return null == charSequence || (charSequence.length() <= 0); } /** * CharSequence不是空並且長度大於零,返回<tt>true<tt/> */ public static boolean charSequenceIsNotEmpty(CharSequence charSequence) { return !charSequenceIsEmpty(charSequence); } }

yexiangyang

[email protected]


常用判空操作工具類