Class TypeCoercion
java.lang.Object
cloud.opencode.base.expression.eval.TypeCoercion
Type Coercion Utility
类型转换工具
Provides type conversion and coercion for expression evaluation.
为表达式求值提供类型转换和强制转换。
Features | 主要功能:
- Convert to primitives: boolean, int, long, double - 转换为基本类型
- Convert to BigDecimal, BigInteger - 转换为BigDecimal、BigInteger
- Convert to date types: LocalDate, LocalDateTime - 转换为日期类型
- Truthiness evaluation for any type - 任何类型的真值求值
- Convertibility check - 可转换性检查
Usage Examples | 使用示例:
boolean b = TypeCoercion.toBoolean("true"); // true
int i = TypeCoercion.toInt("42"); // 42
Integer typed = TypeCoercion.convert("42", Integer.class); // 42
boolean can = TypeCoercion.canConvert("42", Integer.class); // true
Security | 安全性:
- Thread-safe: Yes, stateless utility class - 线程安全: 是,无状态工具类
- Null-safe: Yes, null returns default values (0, false, "null") - 空值安全: 是,null返回默认值
- Since:
- JDK 25, opencode-base-expression V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleancanConvert(Object value, Class<?> targetType) Check if value can be converted to target type 检查值是否可以转换为目标类型static <T> TConvert value to target type 将值转换为目标类型static booleanConvert value to boolean 将值转换为布尔值static doubleConvert value to double 将值转换为双精度浮点数static intConvert value to integer 将值转换为整数static longConvert value to long 将值转换为长整数static StringConvert value to string 将值转换为字符串
-
Method Details
-
toBoolean
Convert value to boolean 将值转换为布尔值- Parameters:
value- the value | 值- Returns:
- the boolean value | 布尔值
-
toInt
Convert value to integer 将值转换为整数- Parameters:
value- the value | 值- Returns:
- the integer value | 整数值
-
toLong
Convert value to long 将值转换为长整数- Parameters:
value- the value | 值- Returns:
- the long value | 长整数值
-
toDouble
Convert value to double 将值转换为双精度浮点数- Parameters:
value- the value | 值- Returns:
- the double value | 双精度值
-
toString
-
convert
-
canConvert
-