forked from functionaljava/functionaljava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrings.java
More file actions
65 lines (57 loc) · 1.65 KB
/
Strings.java
File metadata and controls
65 lines (57 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package fj.function;
import fj.F;
import fj.F2;
import static fj.Function.curry;
/**
* Curried string functions.
*
* @version %build.number%
*/
public final class Strings {
private Strings() {
throw new UnsupportedOperationException();
}
/**
* This function checks if a given String is neither <code>null</code> nor empty.
*/
public static final F<String, Boolean> isNotNullOrEmpty = new F<String, Boolean>() {
@Override
public Boolean f(final String a) {
return a != null && a.length() > 0;
}
};
/**
* A curried version of {@link String#isEmpty()}.
*/
public static final F<String, Boolean> isEmpty = new F<String, Boolean>() {
public Boolean f(final String s) {
return s.length() == 0;
}
};
/**
* A curried version of {@link String#length()}.
*/
public static final F<String, Integer> length = new F<String, Integer>() {
public Integer f(final String s) {
return s.length();
}
};
/**
* A curried version of {@link String#contains(CharSequence)}.
* The function returns true if the second argument contains the first.
*/
public static final F<String, F<String, Boolean>> contains = curry(new F2<String, String, Boolean>() {
public Boolean f(final String s1, final String s2) {
return s2.contains(s1);
}
});
/**
* A curried version of {@link String#matches(String)}.
* The function returns true if the second argument matches the first.
*/
public static final F<String, F<String, Boolean>> matches = curry(new F2<String, String, Boolean>() {
public Boolean f(final String s1, final String s2) {
return s2.matches(s1);
}
});
}