Operations on boolean primitives and Boolean objects.
* *This class tries to handle null
input gracefully.
* An exception will not be thrown for a null
input.
* Each method documents its behaviour in more detail.
Converts a Boolean to an Integer specifying the conversion values.
* ** BooleanUtils.toIntegerObject(Boolean.TRUE, new Integer(1), new Integer(0), new Integer(2)) = new Integer(1) * BooleanUtils.toIntegerObject(Boolean.FALSE, new Integer(1), new Integer(0), new Integer(2)) = new Integer(0) * BooleanUtils.toIntegerObject(null, new Integer(1), new Integer(0), new Integer(2)) = new Integer(2) ** * @param bool the Boolean to convert * @param trueValue the value to return if
true
,
* may be null
* @param falseValue the value to return if false
,
* may be null
* @param nullValue the value to return if null
,
* may be null
* @return the appropriate value
*/
public static Integer toIntegerObject(Boolean bool, Integer trueValue, Integer falseValue, Integer nullValue) {
if (bool == null) {
return nullValue;
}
return bool.booleanValue() ? trueValue : falseValue;
}
}