一、项目上校验空和空集合地方非常多,可以编写一个工具类统一校验
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]
原文地址:https://www.cnblogs.com/moy25/p/8455263.html
时间: 2024-10-10 20:18:13