Class FileFeatureStore

java.lang.Object
cloud.opencode.base.feature.store.FileFeatureStore
All Implemented Interfaces:
FeatureStore

public class FileFeatureStore extends Object implements FeatureStore
File Feature Store 文件功能存储

File-based storage using simple properties format.

使用简单属性格式的文件存储。

Features | 主要功能:

  • File persistence - 文件持久化
  • Memory cache - 内存缓存
  • Auto-reload support - 自动重载支持

File Format | 文件格式:

# Feature configuration
feature.dark-mode.enabled=true
feature.dark-mode.strategy=always-on
feature.new-ui.enabled=true
feature.new-ui.strategy=percentage
feature.new-ui.percentage=50

Usage Examples | 使用示例:

FeatureStore store = new FileFeatureStore(Path.of("features.properties"));
store.save(Feature.builder("feature-1").alwaysOn().build());
store.reload(); // Reload from file

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
  • Null-safe: Partial (validates inputs) - 空值安全: 部分(验证输入)
Since:
JDK 25, opencode-base-feature V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • FileFeatureStore

      public FileFeatureStore(Path filePath)
      Create file store 创建文件存储
      Parameters:
      filePath - the file path | 文件路径
  • Method Details

    • save

      public void save(Feature feature)
      Description copied from interface: FeatureStore
      Save a feature 保存功能
      Specified by:
      save in interface FeatureStore
      Parameters:
      feature - the feature to save | 要保存的功能
    • find

      public Optional<Feature> find(String key)
      Description copied from interface: FeatureStore
      Find a feature by key 根据键查找功能
      Specified by:
      find in interface FeatureStore
      Parameters:
      key - the feature key | 功能键
      Returns:
      optional containing feature if found | 如果找到则包含功能的Optional
    • findAll

      public List<Feature> findAll()
      Description copied from interface: FeatureStore
      Find all features 查找所有功能
      Specified by:
      findAll in interface FeatureStore
      Returns:
      list of all features | 所有功能的列表
    • delete

      public boolean delete(String key)
      Description copied from interface: FeatureStore
      Delete a feature 删除功能
      Specified by:
      delete in interface FeatureStore
      Parameters:
      key - the feature key | 功能键
      Returns:
      true if deleted | 如果删除成功返回true
    • clear

      public void clear()
      Description copied from interface: FeatureStore
      Clear all features 清除所有功能
      Specified by:
      clear in interface FeatureStore
    • reload

      public void reload()
      Reload features from file 从文件重新加载功能
    • getFilePath

      public Path getFilePath()
      Get the file path 获取文件路径
      Returns:
      file path | 文件路径