/**
*<html>
*<body>
* <P> Copyright ● JasonInternational </p>
* <p> All rights reserved.</p>
* <p> Created by Jason see https://github.com/Jasonandy/springboot-wx </p>
*</body>
*</html>
*/
package cn.ucaner.skeleton.common.utils.base;
import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Date;
import java.util.Map;
/**
* @Package:cn.ucaner.wx.app.core.utils.base
* @ClassName:ValidateHelper
* @Description: <p> 判断对象、字符串、集合是否为空、不为空 </p>
* @Author: - Jason
* @CreatTime:2018年10月23日 下午7:46:52
* @Modify By:
* @ModifyTime: 2018年10月23日
* @Modify marker:
* @version V1.0
*/
public final class ValidateHelper {
/**
* 判断数组是否为空
* @param array
* @return
*/
@SuppressWarnings("unused")
private static <T> boolean isEmptyArray(T[] array){
if (array == null || array.length == 0){
return true;
}
else{
return false;
}
}
/**
* 判断数组是否不为空
* @param array
* @return
*/
public static <T> boolean isNotEmptyArray(T[] array){
if (array != null && array.length > 0){
return true;
}
else{
return false;
}
}
/**
* 判断字符串是否为空
* @param string
* @return
*/
public static boolean isEmptyString(String string){
if (string == null || string.length() == 0){
return true;
}
else{
return false;
}
}
/**
* 判断字符串是否不为空
* @param string
* @return
*/
public static boolean isNotEmptyString(String string){
if (string != null && string.length() > 0){
return true;
}
else{
return false;
}
}
/**
* 判断集合是否为空
* @param collection
* @return
*/
public static boolean isEmptyCollection(Collection<?> collection){
if (collection == null || collection.isEmpty()){
return true;
}
else{
return false;
}
}
/**
* 判断集合是否不为空
* @param collection
* @return
*/
public static boolean isNotEmptyCollection(Collection<?> collection){
if (collection != null && !collection.isEmpty()){
return true;
}
else{
return false;
}
}
/**
* 判断map集合是否不为空
* @param map
* @return
*/
@SuppressWarnings("rawtypes")
public static boolean isNotEmptyMap(Map map){
if (map != null && !map.isEmpty()){
return true;
}
else{
return false;
}
}
/**
* 判断map集合是否为空
* @param map
* @return
*/
@SuppressWarnings("rawtypes")
public static boolean isEmptyMap(Map map){
if (map == null || map.isEmpty()){
return true;
}
else{
return false;
}
}
/**
* 检验对象是否为空,String 中只有空格在对象中也算空.
* @param object
* @return
*/
@SuppressWarnings("rawtypes")
public static boolean isEmpty(Object object) {
if (null == object)
return true;
else if (object instanceof String)
return "".equals(object.toString().trim());
else if (object instanceof Iterable)
return !((Iterable) object).iterator().hasNext();
else if (object.getClass().isArray())
return Array.getLength(object) == 0;
else if (object instanceof Map)
return ((Map) object).size() == 0;
else if (Number.class.isAssignableFrom(object.getClass()))
return false;
else if (Date.class.isAssignableFrom(object.getClass()))
return false;
else
return false;
}
/**
* @Description: Just for test
* @Autor: Jason
*/
public static void main(String[] args) {
}
}
08Java为空判断工具
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 如何优雅的判断对象的字段属性值呢? 直接上代码(工具类,拿去就能用) ... ... 参数 1.source:需要...
- 1./**判断输入框输入的内容是否为空 yes 表示为空 no 表示有内容**/ + (BOOL) isBlank...
- Django的ORM中如何判断查询结果是否为空,判断django中的orm为空 result= Booking.o...
- if (array != nil && ![array isKindOfClass:[NSNull class]]...