@@ -32,6 +32,7 @@ private GwtNullSafe() {
32
32
33
33
/**
34
34
* Allows you to safely compare a child property of val1 to other.
35
+ *
35
36
* @return False if val1 is null else whether the child property of val1 is equal to other
36
37
*/
37
38
public static <T1 , T2 > boolean equals (final T1 val1 ,
@@ -47,6 +48,7 @@ public static <T1, T2> boolean equals(final T1 val1,
47
48
48
49
/**
49
50
* Allows you to safely compare a grandchild property of val1 to other.
51
+ *
50
52
* @return False if val1 is null or if val1's child property is null,
51
53
* else whether the grandchild property of val1 is equal to other
52
54
*/
@@ -161,6 +163,34 @@ public static boolean isBlankString(final String str) {
161
163
return true ;
162
164
}
163
165
166
+ /**
167
+ * @return str if it is not null/empty/blank, else other.
168
+ */
169
+ public static String nonBlankStringElse (final String str , final String other ) {
170
+ return isBlankString (str )
171
+ ? Objects .requireNonNull (other )
172
+ : str ;
173
+ }
174
+
175
+ /**
176
+ * @return str if it is not null/empty/blank, else result of calling otherSupplier.
177
+ */
178
+ public static String nonBlankStringElseGet (final String str , final Supplier <String > otherSupplier ) {
179
+ return isBlankString (str )
180
+ ? Objects .requireNonNull (Objects .requireNonNull (otherSupplier ).get ())
181
+ : str ;
182
+ }
183
+
184
+ /**
185
+ * If str is not null/empty/blank then pass it to consumer (if that is not null).
186
+ */
187
+ public static void consumeNonBlankString (final String str , final Consumer <String > consumer ) {
188
+ // GWT doesn't emulate String::isBlank
189
+ if (!isBlankString (str ) && consumer != null ) {
190
+ consumer .accept (str );
191
+ }
192
+ }
193
+
164
194
/**
165
195
* @return True if str is null or empty
166
196
*/
@@ -228,7 +258,7 @@ public static <T> boolean isEmptyString(final T value,
228
258
}
229
259
230
260
/**
231
- * @return True if value is null or the string property is null or empty
261
+ * @return True if value is null or the string property is null/ empty/blank
232
262
*/
233
263
public static <T > boolean isBlankString (final T value ,
234
264
final Function <T , String > stringGetter ) {
@@ -240,6 +270,22 @@ public static <T> boolean isBlankString(final T value,
240
270
}
241
271
}
242
272
273
+ /**
274
+ * If str is not null/empty/blank then pass it to consumer (if that is not null).
275
+ */
276
+ public static <T > void consumeNonBlankString (final T value ,
277
+ final Function <T , String > stringGetter ,
278
+ final Consumer <String > consumer ) {
279
+ // GWT doesn't emulate String::isBlank
280
+ if (value != null && stringGetter != null && consumer != null ) {
281
+ final String str = stringGetter .apply (value );
282
+
283
+ if (!isBlankString (str )) {
284
+ Objects .requireNonNull (consumer ).accept (str );
285
+ }
286
+ }
287
+ }
288
+
243
289
/**
244
290
* @return True if value is null or the collection is null or empty
245
291
*/
@@ -373,6 +419,7 @@ public static <T> Stream<T> stream(final T... items) {
373
419
/**
374
420
* Returns the passed array of items or varargs items as a non-null list.
375
421
* Does not support null items in the list.
422
+ *
376
423
* @return A non-null list of items. List should be assumed to be immutable.
377
424
*/
378
425
public static <T > List <T > asList (final T ... items ) {
@@ -384,6 +431,7 @@ public static <T> List<T> asList(final T... items) {
384
431
/**
385
432
* Returns the passed array of items or varargs items as a non-null set.
386
433
* Does not support null items in the array.
434
+ *
387
435
* @return A non-null unmodifiable set of items.
388
436
*/
389
437
public static <T > Set <T > asSet (final T ... items ) {
@@ -971,7 +1019,9 @@ private static String convertToString(final Object value, final String other) {
971
1019
* GWT currently doesn't emulate requireNonNullElse
972
1020
*/
973
1021
public static <T > T requireNonNullElse (T obj , T other ) {
974
- return (obj != null ) ? obj : Objects .requireNonNull (other , "other" );
1022
+ return (obj != null )
1023
+ ? obj
1024
+ : Objects .requireNonNull (other , "other" );
975
1025
}
976
1026
977
1027
/**
0 commit comments