mirror of
https://gitee.com/jzsw-it/yexuejc-base.git
synced 2025-06-06 13:54:03 +08:00
[update] 判断空优化
Signed-off-by: 夜雪剑辰 <1107047387@qq.com>
This commit is contained in:
parent
007d8d2f16
commit
127c6902bf
@ -1,8 +1,7 @@
|
||||
package com.yexuejc.base.util;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.lang.reflect.Array;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
@ -11,9 +10,9 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -33,36 +32,25 @@ public final class StrUtil {
|
||||
private static char[] HEX_CHAR = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
|
||||
/**
|
||||
* 判断字符串,数组,集合 是否为空
|
||||
* 判断字符串,数组,集合 是否为空(null,"",[],{})
|
||||
*
|
||||
* @param obj
|
||||
* @param obj 対象
|
||||
* @return true:空;false:非空
|
||||
* @return
|
||||
*/
|
||||
public static boolean isEmpty(Object obj) {
|
||||
if (obj instanceof String) {
|
||||
if (obj == null || "".equals((String) obj)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else if (obj instanceof Object[]) {
|
||||
if (obj == null || ((Object[]) obj).length == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else if (obj instanceof Collection<?>) {
|
||||
if (obj == null || ((Collection<?>) obj).size() == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (obj == null) {
|
||||
return true;
|
||||
} else if (obj instanceof Optional) {
|
||||
return ((Optional<?>) obj).isEmpty();
|
||||
} else if (obj instanceof CharSequence) {
|
||||
return ((CharSequence) obj).length() == 0;
|
||||
} else if (obj.getClass().isArray()) {
|
||||
return Array.getLength(obj) == 0;
|
||||
} else if (obj instanceof Collection) {
|
||||
return ((Collection<?>) obj).isEmpty();
|
||||
} else {
|
||||
if (obj == null) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return obj instanceof Map && ((Map<?, ?>) obj).isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user