View Javadoc
1   package org.csveed.bean.conversion;
2   
3   public class ConversionUtil {
4   
5       public static boolean hasLength(CharSequence str) {
6           return str != null && str.length() > 0;
7       }
8   
9       public static boolean hasText(String str) {
10          return hasText((CharSequence) str);
11      }
12  
13      public static boolean hasText(CharSequence str) {
14          if (!hasLength(str)) {
15              return false;
16          }
17          int strLen = str.length();
18          for (int i = 0; i < strLen; i++) {
19              if (!Character.isWhitespace(str.charAt(i))) {
20                  return true;
21              }
22          }
23          return false;
24      }
25  
26      public static String trimAllWhitespace(String str) {
27          if (!hasLength(str)) {
28              return str;
29          }
30          StringBuilder sb = new StringBuilder(str);
31          int index = 0;
32          while (sb.length() > index) {
33              if (Character.isWhitespace(sb.charAt(index))) {
34                  sb.deleteCharAt(index);
35              } else {
36                  index++;
37              }
38          }
39          return sb.toString();
40      }
41  
42  }