Class EnvironmentConfigSource

java.lang.Object
cloud.opencode.base.config.source.EnvironmentConfigSource
All Implemented Interfaces:
ConfigSource

public class EnvironmentConfigSource extends Object implements ConfigSource
Environment Variables Configuration Source 环境变量配置源

Loads configuration from system environment variables with optional prefix filtering and automatic key name conversion.

从系统环境变量加载配置,支持可选的前缀过滤和自动键名转换。

Features | 主要功能:

  • Environment variable to property key conversion - 环境变量到属性键的转换
  • Prefix-based filtering - 基于前缀的过滤
  • Automatic case conversion (UPPER_SNAKE to lower.dot) - 自动大小写转换
  • High priority (100) - 高优先级(100)

Usage Examples | 使用示例:

// All environment variables
ConfigSource source = new EnvironmentConfigSource();
// DATABASE_URL -> database.url

// With prefix filter
ConfigSource source = new EnvironmentConfigSource("APP_");
// APP_DATABASE_URL -> database.url
// APP_SERVER_PORT -> server.port

Performance | 性能特性:

  • Time complexity: O(n) for initialization - 时间复杂度: 初始化为O(n)
  • Environment variables cached at creation - 环境变量在创建时缓存

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
  • Immutable properties - 不可变属性
Since:
JDK 25, opencode-base-config V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • EnvironmentConfigSource

      public EnvironmentConfigSource()
      Create environment config source without prefix 创建无前缀的环境配置源
    • EnvironmentConfigSource

      public EnvironmentConfigSource(String prefix)
      Create environment config source with prefix 创建带前缀的环境配置源
      Parameters:
      prefix - environment variable prefix | 环境变量前缀
  • Method Details

    • getName

      public String getName()
      Description copied from interface: ConfigSource
      Get configuration source name 获取配置源名称
      Specified by:
      getName in interface ConfigSource
      Returns:
      source name | 源名称
    • getProperties

      public Map<String,String> getProperties()
      Description copied from interface: ConfigSource
      Get all configuration properties 获取所有配置属性

      Performance | 性能:

      This method should return a cached immutable map for best performance.

      此方法应返回缓存的不可变映射以获得最佳性能。

      Specified by:
      getProperties in interface ConfigSource
      Returns:
      configuration properties map | 配置属性映射
    • getPriority

      public int getPriority()
      Description copied from interface: ConfigSource
      Get configuration source priority (higher number = higher priority) 获取配置源优先级(数值越大优先级越高)

      Default Priorities | 默认优先级:

      • CommandLine: 200
      • Environment: 100
      • Properties/YAML: 50
      • InMemory: 10
      Specified by:
      getPriority in interface ConfigSource
      Returns:
      priority value | 优先级值