自定义类库:常用判空操作工具类
一、项目上校验空和空集合地方非常多,可以编写一个工具类统一校验
package com.moy.custom.utils; import java.util.Collection; import java.util.Map; /** * [Project]:moy-gradle-project <br/> * [Email]:moy25@foxmail.com <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 objectnIsNotNull(Object obj) { return !objectIsNull(obj); } /** * 集合是空或者个数小于零,返回<tt>true<tt/> */ public static boolean collectionIsEmpty(Collection collection) { return null == collection || (collection.size() <= 0); } /** * 集合不是空并且个数大于零,返回<tt>true<tt/> */ public static boolean collectionIsNotEmpty(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
moyyexy@gmail.com