71 lines
1.6 KiB
Java
71 lines
1.6 KiB
Java
package com.ghy.common.utils;
|
|
|
|
import java.lang.reflect.Array;
|
|
import java.util.Collection;
|
|
import java.util.Iterator;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* 对象工具类
|
|
* @since 2022-05-31
|
|
* @author 但星霖
|
|
*/
|
|
public class ObjectUtils {
|
|
|
|
/**
|
|
* 判断object是否为空,集合会校验size
|
|
*/
|
|
public static boolean isNull(Object... objs) {
|
|
for (Object obj : objs) {
|
|
if (isEmpty(obj)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* 判断object是否不为空,集合会校验size
|
|
*/
|
|
public static boolean isNotNull(Object... obj) {
|
|
return !isNull(obj);
|
|
}
|
|
|
|
/**
|
|
* 对象非空判断
|
|
*/
|
|
public static boolean isNotEmpty(Object obj) {
|
|
return !isEmpty(obj);
|
|
}
|
|
|
|
/**
|
|
* 对象空判断
|
|
*/
|
|
public static boolean isEmpty(Object obj) {
|
|
if (obj == null) {
|
|
return true;
|
|
}
|
|
|
|
if (obj.getClass().isArray()) {
|
|
return Array.getLength(obj) == 0;
|
|
}
|
|
if (obj instanceof CharSequence) {
|
|
return ((CharSequence) obj).length() == 0;
|
|
}
|
|
if (obj instanceof Collection) {
|
|
return ((Collection<?>) obj).isEmpty();
|
|
}
|
|
if (obj instanceof Map) {
|
|
return ((Map<?, ?>) obj).isEmpty();
|
|
}
|
|
if (obj instanceof Iterable) {
|
|
return !((Iterable<?>) obj).iterator().hasNext();
|
|
}
|
|
if (obj instanceof Iterator) {
|
|
return !((Iterator<?>) obj).hasNext();
|
|
}
|
|
// else
|
|
return false;
|
|
}
|
|
}
|