1
2
3
4
5
6
7
8
9
10
11 package org.csveed.bean.conversion;
12
13
14
15
16 public final class ConversionUtil {
17
18
19
20
21 private ConversionUtil() {
22
23 }
24
25
26
27
28
29
30
31
32
33 public static boolean hasLength(CharSequence str) {
34 return str != null && str.length() > 0;
35 }
36
37
38
39
40
41
42
43
44
45 public static boolean hasText(String str) {
46 return hasText((CharSequence) str);
47 }
48
49
50
51
52
53
54
55
56
57 public static boolean hasText(CharSequence str) {
58 if (!hasLength(str)) {
59 return false;
60 }
61 int strLen = str.length();
62 for (int i = 0; i < strLen; i++) {
63 if (!Character.isWhitespace(str.charAt(i))) {
64 return true;
65 }
66 }
67 return false;
68 }
69
70
71
72
73
74
75
76
77
78 public static String trimAllWhitespace(String str) {
79 if (!hasLength(str)) {
80 return str;
81 }
82 StringBuilder sb = new StringBuilder(str);
83 int index = 0;
84 while (sb.length() > index) {
85 if (Character.isWhitespace(sb.charAt(index))) {
86 sb.deleteCharAt(index);
87 } else {
88 index++;
89 }
90 }
91 return sb.toString();
92 }
93
94 }