Commit d236b05eb274b68a277e401e369943cafbfdcf3a

Authored by zhangchuanxi
1 parent 113e6180

feat #添加判断空字符串

... ... @@ -6,7 +6,7 @@
6 6  
7 7 <groupId>com.irrigation</groupId>
8 8 <artifactId>common-lib</artifactId>
9   - <version>2.0.3</version>
  9 + <version>2.0.4</version>
10 10  
11 11 <properties>
12 12 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
... ...
src/main/java/com/irrigation/icl/utils/ObjectUtils.java
... ... @@ -3,6 +3,7 @@ package com.irrigation.icl.utils;
3 3 import com.google.common.collect.Lists;
4 4 import com.irrigation.icl.exception.ContextRuntimeException;
5 5 import org.springframework.beans.BeanUtils;
  6 +import org.springframework.util.StringUtils;
6 7  
7 8 import java.util.*;
8 9  
... ... @@ -52,6 +53,17 @@ public class ObjectUtils {
52 53 }
53 54  
54 55 /**
  56 + * 判断两个对象是否不相等
  57 + *
  58 + * @param a
  59 + * @param b
  60 + * @return
  61 + */
  62 + public static boolean unequal(Object a, Object b) {
  63 + return (a != null && !a.equals(b)) || (b != null && !b.equals(a));
  64 + }
  65 +
  66 + /**
55 67 * 判断集合是否是空
56 68 *
57 69 * @param collection
... ... @@ -96,22 +108,51 @@ public class ObjectUtils {
96 108 /**
97 109 * 判断字符串 是否是 null 或 length=0
98 110 *
99   - * @param str
  111 + * @param cs
100 112 * @return
101 113 */
102   - public static boolean stringIsEmpty(String str) {
103   - return str == null || str.length() == 0;
  114 + public static boolean stringIsEmpty(CharSequence cs) {
  115 + return cs == null || cs.length() == 0;
104 116 }
105 117  
106 118  
107 119 /**
108 120 * 判断字符串 是否不是 null 并且 length!=0
109 121 *
110   - * @param str
  122 + * @param cs
  123 + * @return
  124 + */
  125 + public static boolean stringNonEmpty(CharSequence cs) {
  126 + return !stringIsEmpty(cs);
  127 + }
  128 +
  129 + /**
  130 + * 判断字符是否是空字符
  131 + *
  132 + * @param cs
111 133 * @return
112 134 */
113   - public static boolean stringNontEmpty(String str) {
114   - return !stringIsEmpty(str);
  135 + public static boolean stringIsBlank(CharSequence cs) {
  136 + int strLen;
  137 + if (cs == null || (strLen = cs.length()) == 0) {
  138 + return true;
  139 + }
  140 + for (int i = 0; i < strLen; i++) {
  141 + if (!Character.isWhitespace(cs.charAt(i))) {
  142 + return false;
  143 + }
  144 + }
  145 + return true;
  146 + }
  147 +
  148 + /**
  149 + * 判断字符是否是空字符
  150 + *
  151 + * @param cs
  152 + * @return
  153 + */
  154 + public static boolean stringNonBlankB(CharSequence cs) {
  155 + return !stringIsBlank(cs);
115 156 }
116 157  
117 158  
... ... @@ -121,11 +162,10 @@ public class ObjectUtils {
121 162 * @param str
122 163 * @return
123 164 */
124   - public static String stringTrim(String str) {
  165 + public static String stringTrim(final String str) {
125 166 return str == null ? null : str.trim();
126 167 }
127 168  
128   -
129 169 /**
130 170 * 单个对象复制
131 171 *
... ...