diff --git a/diboot-core/src/main/java/com/diboot/core/util/V.java b/diboot-core/src/main/java/com/diboot/core/util/V.java index d828adce09a2d2c59e8763ff3d85d205cc8493c5..e93a03ed883bbf72bc9e8672dc7354c1c0beed72 100644 --- a/diboot-core/src/main/java/com/diboot/core/util/V.java +++ b/diboot-core/src/main/java/com/diboot/core/util/V.java @@ -45,6 +45,9 @@ public class V { */ private static Validator VALIDATOR = null; + // region 判空方法 + /* ================================================== 判空方法 =================================================== */ + /** * 对象是否为空 */ @@ -59,6 +62,12 @@ public class V { return isEmpty((Map) obj); } else if (obj.getClass().isArray()) { return Array.getLength(obj) == 0; + } else if (obj instanceof Iterator) { + return isEmpty((Iterator) obj); + } else if (obj instanceof Iterable) { + return isEmpty((Iterable) obj); + } else if (obj instanceof Enumeration) { + return isEmpty((Enumeration) obj); } return false; } @@ -98,6 +107,18 @@ public class V { return obj == null || obj.isEmpty(); } + public static boolean isEmpty(Iterator iterator) { + return iterator == null || !iterator.hasNext(); + } + + public static boolean isEmpty(Iterable iterable) { + return iterable == null || isEmpty(iterable.iterator()); + } + + public static boolean isEmpty(Enumeration enumeration) { + return enumeration == null || !enumeration.hasMoreElements(); + } + public static boolean isEmpty(boolean[] array) { return array == null || array.length == 0; } @@ -134,42 +155,6 @@ public class V { return array == null || array.length == 0; } - public static boolean notEmpty(boolean[] array) { - return array != null && array.length != 0; - } - - public static boolean notEmpty(byte[] array) { - return array != null && array.length != 0; - } - - public static boolean notEmpty(char[] array) { - return array != null && array.length != 0; - } - - public static boolean notEmpty(double[] array) { - return array != null && array.length != 0; - } - - public static boolean notEmpty(float[] array) { - return array != null && array.length != 0; - } - - public static boolean notEmpty(int[] array) { - return array != null && array.length != 0; - } - - public static boolean notEmpty(long[] array) { - return array != null && array.length != 0; - } - - public static boolean notEmpty(short[] array) { - return array != null && array.length != 0; - } - - public static boolean notEmpty(Object[] array) { - return array != null && array.length != 0; - } - /** * 任意元素为空则返回true * @@ -188,14 +173,16 @@ public class V { return false; } - /** - * 全都不为空则返回true - * - * @param objs objs - * @return true/false - */ - public static boolean isNoneEmpty(Object... objs) { - return !isAnyEmpty(objs); + public static boolean isAnyEmpty(Collection collection) { + if (isEmpty(collection)) { + return true; + } + for (T obj : collection) { + if (isEmpty(obj)) { + return true; + } + } + return false; } /** @@ -216,6 +203,23 @@ public class V { return true; } + public static boolean isAllEmpty(Collection collection) { + if (isEmpty(collection)) { + return true; + } + for (T obj : collection) { + if (notEmpty(obj)) { + return false; + } + } + return true; + } + /* ================================================== end ======================================================= */ + // endregion + + // region 非空判断方法 + /* ================================================== 非空判断方法 ================================================ */ + /** * 对象是否为空 */ @@ -230,6 +234,12 @@ public class V { return notEmpty((Map) obj); } else if (obj.getClass().isArray()) { return Array.getLength(obj) != 0; + } else if (obj instanceof Iterator) { + return notEmpty((Iterator) obj); + } else if (obj instanceof Iterable) { + return notEmpty((Iterable) obj); + } else if (obj instanceof Enumeration) { + return notEmpty((Enumeration) obj); } return true; } @@ -269,6 +279,54 @@ public class V { return obj != null && !obj.isEmpty(); } + public static boolean notEmpty(Iterator iterator) { + return iterator != null && iterator.hasNext(); + } + + public static boolean notEmpty(Iterable iterable) { + return iterable != null && notEmpty(iterable.iterator()); + } + + public static boolean notEmpty(Enumeration enumeration) { + return enumeration != null && enumeration.hasMoreElements(); + } + + public static boolean notEmpty(boolean[] array) { + return array != null && array.length != 0; + } + + public static boolean notEmpty(byte[] array) { + return array != null && array.length != 0; + } + + public static boolean notEmpty(char[] array) { + return array != null && array.length != 0; + } + + public static boolean notEmpty(short[] array) { + return array != null && array.length != 0; + } + + public static boolean notEmpty(int[] array) { + return array != null && array.length != 0; + } + + public static boolean notEmpty(long[] array) { + return array != null && array.length != 0; + } + + public static boolean notEmpty(double[] array) { + return array != null && array.length != 0; + } + + public static boolean notEmpty(float[] array) { + return array != null && array.length != 0; + } + + public static boolean notEmpty(Object[] array) { + return array != null && array.length != 0; + } + /** * 对象不为空且不为0 */ @@ -283,6 +341,22 @@ public class V { return intObj != null && intObj != 0; } + /** + * 全都不为空则返回true + * + * @param objs objs + * @return true/false + */ + public static boolean isNoneEmpty(Object... objs) { + return !isAnyEmpty(objs); + } + + public static boolean isNoneEmpty(Collection collection) { + return !isAnyEmpty(collection); + } + /* ================================================== end ======================================================= */ + // endregion + /** * 集合中是否包含指定元素 *