fj.test.Bool Maven / Gradle / Ivy
package fj.test;
import fj.F0;
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 true
if this value is true, false
otherwise.
*
* @return true
if this value is true, false
otherwise.
*/
public boolean is() {
return b;
}
/**
* Returns false
if this value is true, true
otherwise.
*
* @return false
if this value is true, true
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 F0 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() {
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() {
public Property _1() {
return prop(c);
}
});
}
/**
* Construct a Bool
from the given value.
*
* @param b The value to construct a Bool
with.
* @return A Bool
from the given value.
*/
public static Bool bool(final boolean b) {
return b ? t : f;
}
}