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 a String returning 'true'
* or 'false'
.
* BooleanUtils.toStringTrueFalse(true) = "true" * BooleanUtils.toStringTrueFalse(false) = "false" ** * @param bool the Boolean to check * @return
'true'
, 'false'
,
* or null
*/
public static String toStringTrueFalse(boolean bool) {
return toString(bool, "true", "false");
}
/**
* Converts a boolean to a String returning one of the input Strings.
* ** BooleanUtils.toString(true, "true", "false") = "true" * BooleanUtils.toString(false, "true", "false") = "false" ** * @param bool the Boolean to check * @param trueString the String to return if
true
,
* may be null
* @param falseString the String to return if false
,
* may be null
* @return one of the two input Strings
*/
public static String toString(boolean bool, String trueString, String falseString) {
return bool ? trueString : falseString;
}
}