@@ -70,6 +70,77 @@ public static boolean isEmptyString(final CharSequence s) {
7070 return s != null && s .length () == 0 ;
7171 }
7272
73+ /**
74+ * Returns true if the param is null or empty.
75+ *
76+ * @param s the string to check
77+ * @return true if the param is null or empty
78+ */
79+ public static boolean isEmptyOrNull (final CharSequence s ) {
80+ return s == null || s .length () == 0 ;
81+ }
82+
83+ /**
84+ * Returns either the passed in CharSequence, or if the CharSequence is
85+ * empty or {@code null}, the default value.
86+ *
87+ * @param <T> the kind of CharSequence
88+ * @param s the CharSequence to check
89+ * @param defaultString the default to return if the input is empty or null
90+ * @return the passed in CharSequence, or the defaultString
91+ */
92+ public static <T extends CharSequence > T defaultIfEmptyOrNull (final T s , final T defaultString ) {
93+ return isEmptyOrNull (s ) ? defaultString : s ;
94+ }
95+
96+ /**
97+ * Tests if a CharSequence is null, empty, or contains only whitespace.
98+ *
99+ * @param s the CharSequence to check
100+ * @return true if a CharSequence is null, empty, or contains only whitespace
101+ */
102+ public static boolean isBlank (final CharSequence s ) {
103+ if (s == null ) {
104+ return true ;
105+ }
106+
107+ final int length = s .length ();
108+ if (length == 0 ) {
109+ return true ;
110+ }
111+
112+ for (int i = 0 ; i < length ; i ++) {
113+ if (!Character .isWhitespace (s .charAt (i ))) {
114+ return false ;
115+ }
116+ }
117+ return true ;
118+ }
119+
120+ /**
121+ * Tests if a CharSequence is NOT null, empty, or contains only whitespace.
122+ *
123+ * @param s the CharSequence to check
124+ * @return false if a CharSequence is null, empty, or contains only whitespace
125+ */
126+ public static boolean isNotBlank (final CharSequence s ) {
127+ if (s == null ) {
128+ return false ;
129+ }
130+
131+ final int length = s .length ();
132+ if (length == 0 ) {
133+ return false ;
134+ }
135+
136+ for (int i = 0 ; i < length ; i ++) {
137+ if (!Character .isWhitespace (s .charAt (i ))) {
138+ return true ;
139+ }
140+ }
141+ return false ;
142+ }
143+
73144 /**
74145 * @param expected the char that we expect
75146 * @param s the string to check
@@ -687,7 +758,7 @@ public static String[] splitAtComma(final String str) {
687758 * Splits the provided text into an array, using comma or blank as the
688759 * separator.
689760 *
690- * @param str the String to parse, may be null
761+ * @param str the String to parse, may be null
691762 * @return an array of parsed Strings, an empty array if null String input
692763 */
693764 public static String [] splitAtCommaOrBlank (final String str ) {
0 commit comments