Class OpenBoolean
java.lang.Object
cloud.opencode.base.core.OpenBoolean
Boolean Utility Class - Conversion, logical operations and validation for boolean values
布尔值工具类 - 布尔值的转换、逻辑运算和验证
Provides comprehensive boolean operations including conversion, logical operations and validation.
提供全面的布尔值操作,包括转换、逻辑运算、验证。
Features | 主要功能:
- Convert to boolean (toBoolean from String/Integer/Boolean) - 转换为 boolean
- Convert to Boolean (toBooleanObject) - 转换为 Boolean
- Convert to String (toString, toStringYesNo, toStringOnOff) - 转换为字符串
- Convert to Integer (toInteger) - 转换为整数
- Validation (isTrue, isFalse, isNotTrue, isNotFalse) - 验证
- Logical operations (negate, and, or, xor) - 逻辑运算
Usage Examples | 使用示例:
// String to boolean - 字符串转 boolean
boolean b1 = OpenBoolean.toBoolean("yes"); // true
boolean b2 = OpenBoolean.toBoolean("1"); // true
boolean b3 = OpenBoolean.toBoolean("on"); // true
// Boolean to string - Boolean 转字符串
String s = OpenBoolean.toStringYesNo(true); // "yes"
// Logical operations - 逻辑运算
boolean result = OpenBoolean.and(true, true, false); // false
Security | 安全性:
- Thread-safe: Yes (stateless) - 线程安全: 是 (无状态)
- Null-safe: Yes - 空值安全: 是
- Since:
- JDK 25, opencode-base-core V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanand(boolean... values) Logical AND operation 逻辑与操作static intcompare(boolean x, boolean y) Compares 比较两个 Booleanstatic booleanChecks 判断是否为 falsestatic booleanisNotFalse(Boolean value) Checks 判断是否不为 false(null 或 true)static booleanChecks 判断是否不为 true(null 或 false)static booleanChecks 判断是否为 truestatic booleannegate(boolean value) Negation operation 取反操作static BooleanNegation operation (Boolean, null returns null) 取反操作(Boolean,null 返回 null)static booleanor(boolean... values) Logical OR operation 逻辑或操作static booleantoBoolean(int value) Converts an integer to boolean (0 is false, others are true) 整数转 boolean(0 为 false,其他为 true)static booleanBoolean 转 boolean(null 安全)static booleanConverts a string to boolean 字符串转 booleanstatic BooleantoBooleanObject(boolean value) boolean 转 Booleanstatic BooleantoBooleanObject(String str) Converts a string to Boolean (null-safe) 字符串转 Boolean(null 安全)static inttoInteger(boolean value) boolean 转整数(true=1, false=0)static intBoolean 转整数(null=0)static StringBoolean 转字符串static StringtoStringOnOff(Boolean value) Converts to 转为 on/off 字符串static StringtoStringYesNo(Boolean value) Converts to 转为 yes/no 字符串static StringtoStringYN(Boolean value) Converts to 转为 Y/N 字符串static booleanxor(boolean... values) Logical XOR operation 逻辑异或操作
-
Method Details
-
toBoolean
Boolean 转 boolean(null 安全) -
toBoolean
Converts a string to boolean 字符串转 boolean以下值视为 true(忽略大小写):true, yes, y, on, 1
-
toBoolean
public static boolean toBoolean(int value) Converts an integer to boolean (0 is false, others are true) 整数转 boolean(0 为 false,其他为 true) -
toBooleanObject
boolean 转 Boolean -
toBooleanObject
-
toString
-
toStringYesNo
-
toStringOnOff
-
toStringYN
-
toInteger
public static int toInteger(boolean value) boolean 转整数(true=1, false=0) -
toInteger
Boolean 转整数(null=0) -
isTrue
Checks 判断是否为 true -
isFalse
Checks 判断是否为 false -
isNotTrue
Checks 判断是否不为 true(null 或 false) -
isNotFalse
Checks 判断是否不为 false(null 或 true) -
negate
public static boolean negate(boolean value) Negation operation 取反操作 -
negate
-
and
public static boolean and(boolean... values) Logical AND operation 逻辑与操作 -
or
public static boolean or(boolean... values) Logical OR operation 逻辑或操作 -
xor
public static boolean xor(boolean... values) Logical XOR operation 逻辑异或操作 -
compare
public static int compare(boolean x, boolean y) Compares 比较两个 Boolean
-