Interface ConfigConverter<T>
- Type Parameters:
T- target type | 目标类型
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Configuration Type Converter Interface
配置类型转换器接口
Functional interface for converting string configuration values to target types.
用于将字符串配置值转换为目标类型的函数式接口。
Features | 主要功能:
- Type-safe string to object conversion - 类型安全的字符串到对象转换
- Functional interface with lambda support - 支持Lambda的函数式接口
- Extensible via SPI - 可通过SPI扩展
Usage Examples | 使用示例:
// Register custom converter
registry.register(LocalDate.class, LocalDate::parse);
// Complex converter
registry.register(InetAddress.class, value -> {
try {
return InetAddress.getByName(value);
} catch (UnknownHostException e) {
throw new OpenConfigException("Invalid address: " + value, e);
}
});
// Enum converter (handled automatically)
registry.register(LogLevel.class, value ->
LogLevel.valueOf(value.toUpperCase()));
Performance | 性能特性:
- Time complexity: O(1) for conversion - 时间复杂度: 转换为O(1)
- Results can be cached - 结果可以被缓存
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Null-safe: Should handle null input - 空值安全: 应处理空输入
- Since:
- JDK 25, opencode-base-config V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
-
Method Details
-
convert
Convert string value to target type 将字符串值转换为目标类型Examples | 示例:
convert("123") -> 123 // Integer converter convert("true") -> Boolean.TRUE // Boolean converter convert("30s") -> Duration.ofSeconds(30) // Duration converter convert("localhost") -> InetAddress.getByName("localhost") // InetAddress converter- Parameters:
value- string value from configuration | 配置中的字符串值- Returns:
- converted object | 转换后的对象
- Throws:
OpenConfigException- if conversion fails | 如果转换失败
-
getType
-