Module bus.core

Class Context

java.lang.Object
org.miaixz.bus.core.lang.Keys
org.miaixz.bus.core.Context

public class Context extends Keys
配置属性管理类,用于加载和获取配置属性,支持单例模式
Since:
Java 17+
Author:
Kimi Liu
  • Field Details

    • INSTANCE

      public static final Context INSTANCE
      全局唯一实例,静态初始化,确保单例模式
    • delegate

      public final Properties delegate
      存储配置属性的 Properties 对象,用于键值对存储
  • Constructor Details

    • Context

      public Context()
      私有构造方法,防止外部实例化,确保单例
    • Context

      public Context(Properties properties)
  • Method Details

    • newInstance

      public static Context newInstance(Properties properties)
    • keys

      public Set<String> keys()
    • putAll

      public void putAll(Properties properties)
      设置配置属性,将外部 Properties 对象合并到内部 delegate 中
      Parameters:
      properties - 外部配置属性
    • getProperty

      public String getProperty(String key)
      获取指定键的属性值
      Parameters:
      key - 属性键
      Returns:
      属性值,若不存在返回 null
    • getProperty

      public String getProperty(String key, String defaultValue)
      获取指定键的属性值,若不存在返回默认值
      Parameters:
      key - 属性键
      defaultValue - 默认值
      Returns:
      属性值,若不存在或为空返回默认值
    • getProperty

      public int getProperty(String key, int defaultValue)
      获取指定键的整型属性值,若不存在或无法转换返回默认值
      Parameters:
      key - 属性键
      defaultValue - 默认值
      Returns:
      整型属性值,若无法解析返回默认值
    • getProperty

      public boolean getProperty(String key, boolean defaultValue)
      获取指定键的布尔型属性值,若不存在返回默认值
      Parameters:
      key - 属性键
      defaultValue - 默认值
      Returns:
      布尔型属性值,若不存在返回默认值
    • group

      public Map<String,Properties> group(String group)
      按分组前缀获取配置属性,返回分组后的属性映射
      Parameters:
      group - 分组前缀
      Returns:
      分组后的属性映射,若无匹配返回空映射
    • whenNotBlank

      public Context whenNotBlank(String key, Consumer<String> consumer)
    • whenNotBlank

      public <T> Context whenNotBlank(String key, Function<String,T> function, Consumer<T> consumer)