forked from functionaljava/functionaljava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBool.java
More file actions
98 lines (87 loc) · 2.61 KB
/
Bool.java
File metadata and controls
98 lines (87 loc) · 2.61 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package fj.test;
import fj.P1;
import static fj.test.Property.prop;
/**
* A boolean wrapper that works well with properties.
*
* @version %build.number%
*/
public final class Bool {
private final boolean b;
private static final Bool t = new Bool(true);
private static final Bool f = new Bool(false);
private Bool(final boolean b) {
this.b = b;
}
/**
* Returns <code>true</code> if this value is true, <code>false</code> otherwise.
*
* @return <code>true</code> if this value is true, <code>false</code> otherwise.
*/
public boolean is() {
return b;
}
/**
* Returns <code>false</code> if this value is true, <code>true</code> otherwise.
*
* @return <code>false</code> if this value is true, <code>true</code> otherwise.
*/
public boolean isNot() {
return !b;
}
/**
* Returns a property that produces a result only if this value is true. The result will be taken
* from the given property.
*
* @param p The property to return if this value is true.
* @return a property that produces a result only if this value is true.
*/
public Property implies(final P1<Property> p) {
return Property.implies(b, p);
}
/**
* Returns a property that produces a result only if this value is true. The result will be taken
* from the given property.
*
* @param p The property to return if this value is true.
* @return a property that produces a result only if this value is true.
*/
public Property implies(final Property p) {
return Property.implies(b, new P1<Property>() {
public Property _1() {
return p;
}
});
}
/**
* Returns a property that produces a result only if this value is true.
*
* @param c The value to construct a property with to return if this value is true.
* @return a property that produces a result only if this value is true.
*/
public Property implies(final Bool c) {
return implies(prop(c.b));
}
/**
* Returns a property that produces a result only if this value is true.
*
* @param c The value to construct a property with to return if this value is true.
* @return a property that produces a result only if this value is true.
*/
public Property implies(final boolean c) {
return Property.implies(b, new P1<Property>() {
public Property _1() {
return prop(c);
}
});
}
/**
* Construct a <code>Bool</code> from the given value.
*
* @param b The value to construct a <code>Bool</code> with.
* @return A <code>Bool</code> from the given value.
*/
public static Bool bool(final boolean b) {
return b ? t : f;
}
}