package utils ; import org . apache . commons . lang . StringUtils ; import java . util . * ; /** * 〈判空工具类〉 * 非空加!关键字即可 * * @author Barrett * @version 1.0.0 * @time 2020/1/6 */ public class ValidateUtil { /**
import org.apache.commons.lang.StringUtils;
import java.util.*;
/**
* 〈判空工具类〉
* 非空加!关键字即可
*
* @author Barrett
* @version 1.0.0
* @time 2020/1/6
*/
public class ValidateUtil {
/**
* @Author Barrett
* @Date 10:46 2020/1/6
* @Description 对字符串进行判空
* StringUtils.isBlank()可判断某个字段为null,""," ",三种类型
*/
public static boolean isBlankToStr(String s) {
return StringUtils.isBlank(s);
}
/**
* @Author Barrett
* @Date 10:46 2020/1/6
* @Description 对日期进行判空
*/
public static boolean isBlankToDate(Date date) {
if (null == date) return true;
return false;
}
/**
* @Author Barrett
* @Date 10:46 2020/1/6
* @Description 对集合进行判空
*/
public static <T> boolean isBlankToCollection(Collection<T> collection) {
if (null == collection || collection.isEmpty()) return true;
return false;
}
/**
* @Author Barrett
* @Date 10:46 2020/1/6
* @Description 对map集合进行判空
*/
public static <T> boolean isBlankToMap(Map<T, T> map) {
if (null == map || map.isEmpty()) return true;
return false;
}
/**
* @Author Barrett
* @Date 10:46 2020/1/6
* @Description 对对象进行判空
*/
public static boolean isBlankToObject(Object object) {
if (object == null) return true;
if (object instanceof String) {
return isBlankToStr(String.valueOf(object));
} else if (object instanceof Date) {
return isBlankToDate((Date) object);
} else if (object instanceof Collection) {
return isBlankToCollection((Collection) object);
} else if (object instanceof Map) {
return isBlankToMap((Map) object);
}
return false;
}
}