Merge pull request #2816 from 847689421/v5-dev

BooleanUtil增加toString(Boolean bool, String trueString, String falseString, String nullString)方法
This commit is contained in:
Golden Looly 2022-12-27 20:25:27 +08:00 committed by GitHub
commit 0cf4a8d6c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -311,6 +311,28 @@ public class BooleanUtil {
return bool ? trueString : falseString;
}
/**
* 将boolean转换为字符串
*
* <pre>
* BooleanUtil.toString(true, "true", "false", null) = "true"
* BooleanUtil.toString(false, "true", "false", null) = "false"
* BooleanUtil.toString(null, "true", "false", null) = null
* </pre>
*
* @param bool Boolean值
* @param trueString 当值为 {@code true}时返回此字符串, 可能为 {@code null}
* @param falseString 当值为 {@code false}时返回此字符串, 可能为 {@code null}
* @param nullString 当值为 {@code null}时返回此字符串, 可能为 {@code null}
* @return 结果值
*/
public static String toString(Boolean bool, String trueString, String falseString, String nullString) {
if (bool == null) {
return nullString;
}
return bool ? trueString : falseString;
}
/**
* 对Boolean数组取与
*