0
|
1 package fj.test;
|
|
2
|
|
3 import fj.P1;
|
|
4 import static fj.test.Property.prop;
|
|
5
|
|
6 /**
|
|
7 * A boolean wrapper that works well with properties.
|
|
8 *
|
|
9 * @version %build.number%
|
|
10 */
|
|
11 public final class Bool {
|
|
12 private final boolean b;
|
|
13
|
|
14 private static final Bool t = new Bool(true);
|
|
15 private static final Bool f = new Bool(false);
|
|
16
|
|
17 private Bool(final boolean b) {
|
|
18 this.b = b;
|
|
19 }
|
|
20
|
|
21 /**
|
|
22 * Returns <code>true</code> if this value is true, <code>false</code> otherwise.
|
|
23 *
|
|
24 * @return <code>true</code> if this value is true, <code>false</code> otherwise.
|
|
25 */
|
|
26 public boolean is() {
|
|
27 return b;
|
|
28 }
|
|
29
|
|
30 /**
|
|
31 * Returns <code>false</code> if this value is true, <code>true</code> otherwise.
|
|
32 *
|
|
33 * @return <code>false</code> if this value is true, <code>true</code> otherwise.
|
|
34 */
|
|
35 public boolean isNot() {
|
|
36 return !b;
|
|
37 }
|
|
38
|
|
39 /**
|
|
40 * Returns a property that produces a result only if this value is true. The result will be taken
|
|
41 * from the given property.
|
|
42 *
|
|
43 * @param p The property to return if this value is true.
|
|
44 * @return a property that produces a result only if this value is true.
|
|
45 */
|
|
46 public Property implies(final P1<Property> p) {
|
|
47 return Property.implies(b, p);
|
|
48 }
|
|
49
|
|
50 /**
|
|
51 * Returns a property that produces a result only if this value is true. The result will be taken
|
|
52 * from the given property.
|
|
53 *
|
|
54 * @param p The property to return if this value is true.
|
|
55 * @return a property that produces a result only if this value is true.
|
|
56 */
|
|
57 public Property implies(final Property p) {
|
|
58 return Property.implies(b, new P1<Property>() {
|
|
59 public Property _1() {
|
|
60 return p;
|
|
61 }
|
|
62 });
|
|
63 }
|
|
64
|
|
65 /**
|
|
66 * Returns a property that produces a result only if this value is true.
|
|
67 *
|
|
68 * @param c The value to construct a property with to return if this value is true.
|
|
69 * @return a property that produces a result only if this value is true.
|
|
70 */
|
|
71 public Property implies(final Bool c) {
|
|
72 return implies(prop(c.b));
|
|
73 }
|
|
74
|
|
75 /**
|
|
76 * Returns a property that produces a result only if this value is true.
|
|
77 *
|
|
78 * @param c The value to construct a property with to return if this value is true.
|
|
79 * @return a property that produces a result only if this value is true.
|
|
80 */
|
|
81 public Property implies(final boolean c) {
|
|
82 return Property.implies(b, new P1<Property>() {
|
|
83 public Property _1() {
|
|
84 return prop(c);
|
|
85 }
|
|
86 });
|
|
87 }
|
|
88
|
|
89 /**
|
|
90 * Construct a <code>Bool</code> from the given value.
|
|
91 *
|
|
92 * @param b The value to construct a <code>Bool</code> with.
|
|
93 * @return A <code>Bool</code> from the given value.
|
|
94 */
|
|
95 public static Bool bool(final boolean b) {
|
|
96 return b ? t : f;
|
|
97 }
|
|
98 }
|