Class OpenBoolean

java.lang.Object
cloud.opencode.base.core.OpenBoolean

public final class OpenBoolean extends Object
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 Type
    Method
    Description
    static boolean
    and(boolean... values)
    Logical AND operation 逻辑与操作
    static int
    compare(boolean x, boolean y)
    Compares 比较两个 Boolean
    static boolean
    Checks 判断是否为 false
    static boolean
    Checks 判断是否不为 false(null 或 true)
    static boolean
    Checks 判断是否不为 true(null 或 false)
    static boolean
    isTrue(Boolean value)
    Checks 判断是否为 true
    static boolean
    negate(boolean value)
    Negation operation 取反操作
    static Boolean
    negate(Boolean value)
    Negation operation (Boolean, null returns null) 取反操作(Boolean,null 返回 null)
    static boolean
    or(boolean... values)
    Logical OR operation 逻辑或操作
    static boolean
    toBoolean(int value)
    Converts an integer to boolean (0 is false, others are true) 整数转 boolean(0 为 false,其他为 true)
    static boolean
    Boolean 转 boolean(null 安全)
    static boolean
    Converts a string to boolean 字符串转 boolean
    static Boolean
    toBooleanObject(boolean value)
    boolean 转 Boolean
    static Boolean
    Converts a string to Boolean (null-safe) 字符串转 Boolean(null 安全)
    static int
    toInteger(boolean value)
    boolean 转整数(true=1, false=0)
    static int
    Boolean 转整数(null=0)
    static String
    Boolean 转字符串
    static String
    Converts to 转为 on/off 字符串
    static String
    Converts to 转为 yes/no 字符串
    static String
    Converts to 转为 Y/N 字符串
    static boolean
    xor(boolean... values)
    Logical XOR operation 逻辑异或操作

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • toBoolean

      public static boolean toBoolean(Boolean value)
      Boolean 转 boolean(null 安全)
    • toBoolean

      public static boolean toBoolean(String str)
      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

      public static Boolean toBooleanObject(boolean value)
      boolean 转 Boolean
    • toBooleanObject

      public static Boolean toBooleanObject(String str)
      Converts a string to Boolean (null-safe) 字符串转 Boolean(null 安全)
    • toString

      public static String toString(Boolean value)
      Boolean 转字符串
    • toStringYesNo

      public static String toStringYesNo(Boolean value)
      Converts to 转为 yes/no 字符串
    • toStringOnOff

      public static String toStringOnOff(Boolean value)
      Converts to 转为 on/off 字符串
    • toStringYN

      public static String toStringYN(Boolean value)
      Converts to 转为 Y/N 字符串
    • toInteger

      public static int toInteger(boolean value)
      boolean 转整数(true=1, false=0)
    • toInteger

      public static int toInteger(Boolean value)
      Boolean 转整数(null=0)
    • isTrue

      public static boolean isTrue(Boolean value)
      Checks 判断是否为 true
    • isFalse

      public static boolean isFalse(Boolean value)
      Checks 判断是否为 false
    • isNotTrue

      public static boolean isNotTrue(Boolean value)
      Checks 判断是否不为 true(null 或 false)
    • isNotFalse

      public static boolean isNotFalse(Boolean value)
      Checks 判断是否不为 false(null 或 true)
    • negate

      public static boolean negate(boolean value)
      Negation operation 取反操作
    • negate

      public static Boolean negate(Boolean value)
      Negation operation (Boolean, null returns null) 取反操作(Boolean,null 返回 null)
    • 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