2
2
3
3
import fj .F ;
4
4
import fj .F2 ;
5
+ import fj .data .Stream ;
5
6
import static fj .Function .curry ;
7
+ import static fj .function .Booleans .not ;
8
+ import static fj .function .Characters .isWhitespace ;
6
9
7
10
/**
8
11
* Curried string functions.
@@ -14,8 +17,41 @@ private Strings() {
14
17
throw new UnsupportedOperationException ();
15
18
}
16
19
20
+ /**
21
+ * This function checks if a given String contains any non-whitespace character
22
+ * (according to {@link Character#isWhitespace(char)}) and if it's also not
23
+ * <code>null</code> and not empty ("").
24
+ *
25
+ * @see #isNullOrBlank
26
+ * @see Character#isWhitespace(char)
27
+ * @see Characters#isWhitespace
28
+ */
29
+ public static final F <String , Boolean > isNotNullOrBlank = new F <String , Boolean >() {
30
+ @ Override
31
+ public Boolean f (final String a ) {
32
+ return isNotNullOrEmpty .f (a ) && Stream .fromString (a ).find (not (isWhitespace )).isSome ();
33
+ }
34
+ };
35
+
36
+ /**
37
+ * This function checks if a given String is whitespace (according to {@link Character#isWhitespace(char)}),
38
+ * empty ("") or <code>null</code>.
39
+ *
40
+ * @see #isNotNullOrBlank
41
+ * @see Character#isWhitespace(char)
42
+ * @see Characters#isWhitespace
43
+ */
44
+ public static final F <String , Boolean > isNullOrBlank = new F <String , Boolean >() {
45
+ @ Override
46
+ public Boolean f (final String a ) {
47
+ return isNullOrEmpty .f (a ) || Stream .fromString (a ).find (not (isWhitespace )).isNone ();
48
+ }
49
+ };
50
+
17
51
/**
18
52
* This function checks if a given String is neither <code>null</code> nor empty.
53
+ *
54
+ * @see #isNullOrEmpty
19
55
*/
20
56
public static final F <String , Boolean > isNotNullOrEmpty = new F <String , Boolean >() {
21
57
@ Override
@@ -24,6 +60,18 @@ public Boolean f(final String a) {
24
60
}
25
61
};
26
62
63
+ /**
64
+ * This function checks if a given String is <code>null</code> or empty ({@link String#isEmpty()}).
65
+ *
66
+ * @see #isNotNullOrEmpty
67
+ */
68
+ public static final F <String , Boolean > isNullOrEmpty = new F <String , Boolean >() {
69
+ @ Override
70
+ public Boolean f (final String a ) {
71
+ return a == null || a .length () == 0 ;
72
+ }
73
+ };
74
+
27
75
/**
28
76
* A curried version of {@link String#isEmpty()}.
29
77
*/
0 commit comments