Class CommonConfig

java.lang.Object
com.github.theword.queqiao.tool.config.CommonConfig
Direct Known Subclasses:
Config

public abstract class CommonConfig extends Object
  • Constructor Details

    • CommonConfig

      public CommonConfig(org.slf4j.Logger logger)
  • Method Details

    • getLogger

      public org.slf4j.Logger getLogger()
    • readConfigFile

      protected void readConfigFile(String configFolder, String fileName)
      读取配置文件
      Parameters:
      configFolder - 配置文件所在目录
      fileName - 配置文件名
    • readConfigValues

      protected void readConfigValues(Path path, String fileName)
      读取配置文件内容
      Parameters:
      path - 路径
      fileName - 文件名
    • loadConfigValues

      protected abstract void loadConfigValues(Map<String,Object> configMap)
      加载配置文件内容

      由原版端实现,读取自定义 regex.yml

      Parameters:
      configMap - 配置文件内容
    • checkFileExists

      protected void checkFileExists(Path path, String fileName)
      检查配置文件是否存在
      Parameters:
      path - 路径
      fileName - 文件名
    • synchronizeConfigFile

      protected void synchronizeConfigFile(Path path, String fileName)
      严格同步字段:

      1. 当前缺少默认字段 -> 补默认值

      2. 当前多出未知字段 -> 删除

      3. 类型不匹配 -> 回退默认值

    • readConfigMap

      protected Map<String,Object> readConfigMap(Path path, String fileName)
      读取整个配置文件为 Map。
      Parameters:
      path - 配置文件路径
      fileName - 配置文件名
      Returns:
      配置内容(若读取失败则返回空 Map)
    • readConfigValue

      protected Object readConfigValue(Path path, String fileName, String keyPath)
      按键路径读取配置项。

      键路径使用 "." 分隔,例如:websocket_server.port。

      Parameters:
      path - 配置文件路径
      fileName - 配置文件名
      keyPath - 键路径
      Returns:
      配置值,不存在时返回 null
    • writeConfigMap

      protected boolean writeConfigMap(Path path, String fileName, Map<String,Object> configMap)
      写入整个配置文件。
      Parameters:
      path - 配置文件路径
      fileName - 配置文件名
      configMap - 配置内容
      Returns:
      是否写入成功
    • writeConfigValue

      protected boolean writeConfigValue(Path path, String fileName, String keyPath, Object value)
      按键路径写入配置项。

      键路径使用 "." 分隔,例如:websocket_server.port。

      Parameters:
      path - 配置文件路径
      fileName - 配置文件名
      keyPath - 键路径
      value - 键值
      Returns:
      是否写入成功
    • normalizeKeyPath

      protected String normalizeKeyPath(String keyPath)
      规范化键路径。

      会去除首尾空白、空段,示例:".a..b. " -> "a.b"