From d236b05eb274b68a277e401e369943cafbfdcf3a Mon Sep 17 00:00:00 2001 From: zhangchuanxi Date: Mon, 4 Nov 2019 10:17:29 +0800 Subject: [PATCH] feat #添加判断空字符串 --- pom.xml | 2 +- src/main/java/com/irrigation/icl/utils/ObjectUtils.java | 56 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index ddf6114..348a035 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.irrigation common-lib - 2.0.3 + 2.0.4 UTF-8 diff --git a/src/main/java/com/irrigation/icl/utils/ObjectUtils.java b/src/main/java/com/irrigation/icl/utils/ObjectUtils.java index 03e6eee..12c790f 100644 --- a/src/main/java/com/irrigation/icl/utils/ObjectUtils.java +++ b/src/main/java/com/irrigation/icl/utils/ObjectUtils.java @@ -3,6 +3,7 @@ package com.irrigation.icl.utils; import com.google.common.collect.Lists; import com.irrigation.icl.exception.ContextRuntimeException; import org.springframework.beans.BeanUtils; +import org.springframework.util.StringUtils; import java.util.*; @@ -52,6 +53,17 @@ public class ObjectUtils { } /** + * 判断两个对象是否不相等 + * + * @param a + * @param b + * @return + */ + public static boolean unequal(Object a, Object b) { + return (a != null && !a.equals(b)) || (b != null && !b.equals(a)); + } + + /** * 判断集合是否是空 * * @param collection @@ -96,22 +108,51 @@ public class ObjectUtils { /** * 判断字符串 是否是 null 或 length=0 * - * @param str + * @param cs * @return */ - public static boolean stringIsEmpty(String str) { - return str == null || str.length() == 0; + public static boolean stringIsEmpty(CharSequence cs) { + return cs == null || cs.length() == 0; } /** * 判断字符串 是否不是 null 并且 length!=0 * - * @param str + * @param cs + * @return + */ + public static boolean stringNonEmpty(CharSequence cs) { + return !stringIsEmpty(cs); + } + + /** + * 判断字符是否是空字符 + * + * @param cs * @return */ - public static boolean stringNontEmpty(String str) { - return !stringIsEmpty(str); + public static boolean stringIsBlank(CharSequence cs) { + int strLen; + if (cs == null || (strLen = cs.length()) == 0) { + return true; + } + for (int i = 0; i < strLen; i++) { + if (!Character.isWhitespace(cs.charAt(i))) { + return false; + } + } + return true; + } + + /** + * 判断字符是否是空字符 + * + * @param cs + * @return + */ + public static boolean stringNonBlankB(CharSequence cs) { + return !stringIsBlank(cs); } @@ -121,11 +162,10 @@ public class ObjectUtils { * @param str * @return */ - public static String stringTrim(String str) { + public static String stringTrim(final String str) { return str == null ? null : str.trim(); } - /** * 单个对象复制 * -- libgit2 0.21.4