Interface ConfigSourceType

All Known Implementing Classes:
ConfigSourceType.Classpath, ConfigSourceType.Environment, ConfigSourceType.File, ConfigSourceType.InMemory, ConfigSourceType.System

Sealed Configuration Source Type for JDK 25 JDK 25的密封配置源类型

Provides type-safe configuration source definitions using JDK 25 sealed types and record patterns. Enables exhaustive pattern matching for source handling.

使用JDK 25密封类型和记录模式提供类型安全的配置源定义。支持完备的模式匹配处理。

Features | 主要功能:

  • Sealed interface with record implementations - 密封接口与记录实现
  • Pattern matching support - 模式匹配支持
  • Type-safe source creation - 类型安全的源创建
  • Exhaustive switch expressions - 完备的switch表达式

Usage Examples | 使用示例:

// Create different source types
ConfigSourceType fileSource = new ConfigSourceType.File(Path.of("config.properties"));
ConfigSourceType envSource = new ConfigSourceType.Environment("APP");
ConfigSourceType sysSource = new ConfigSourceType.System();

// Convert to ConfigSource
ConfigSource source = fileSource.toSource();

// Pattern matching in switch
String desc = switch (sourceType) {
    case File(var path, var watch) -> "File: " + path;
    case Classpath(var res) -> "Classpath: " + res;
    case Environment(var prefix) -> "Env: " + prefix;
    case System() -> "System properties";
    case InMemory(var props) -> "Memory: " + props.size();
};

Supported Types | 支持的类型:

  • File - File system properties - 文件系统属性
  • Classpath - Classpath resources - 类路径资源
  • Environment - Environment variables - 环境变量
  • System - System properties - 系统属性
  • InMemory - In-memory map - 内存映射

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
  • Null-safe: Partial (validates inputs) - 空值安全: 部分(验证输入)
Since:
JDK 25, opencode-base-config V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also: