Class DefaultFactStore

java.lang.Object
cloud.opencode.base.rules.model.DefaultFactStore
All Implemented Interfaces:
FactStore

public class DefaultFactStore extends Object implements FactStore
Default Fact Store Implementation 默认事实存储实现

Thread-safe implementation using ConcurrentHashMap and CopyOnWriteArrayList.

使用ConcurrentHashMap和CopyOnWriteArrayList的线程安全实现。

Features | 主要功能:

  • Named and typed fact storage - 命名和类型化事实存储
  • Type-based retrieval - 基于类型的检索
  • Concurrent access support - 并发访问支持

Usage Examples | 使用示例:

FactStore store = new DefaultFactStore();
store.add("customer", customerObj);
store.add(orderObj);
Optional<Order> order = store.get(Order.class);

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
Since:
JDK 25, opencode-base-rules V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • DefaultFactStore

      public DefaultFactStore()
  • Method Details

    • add

      public void add(Object fact)
      Description copied from interface: FactStore
      Adds a fact to the store 向存储添加事实
      Specified by:
      add in interface FactStore
      Parameters:
      fact - the fact object | 事实对象
    • add

      public void add(String name, Object fact)
      Description copied from interface: FactStore
      Adds a named fact to the store 向存储添加命名事实
      Specified by:
      add in interface FactStore
      Parameters:
      name - the fact name | 事实名称
      fact - the fact object | 事实对象
    • get

      public <T> Optional<T> get(Class<T> type)
      Description copied from interface: FactStore
      Gets a fact by type 按类型获取事实
      Specified by:
      get in interface FactStore
      Type Parameters:
      T - the fact type | 事实类型
      Parameters:
      type - the fact type | 事实类型
      Returns:
      optional containing the fact | 包含事实的Optional
    • get

      public Object get(String name)
      Description copied from interface: FactStore
      Gets a fact by name 按名称获取事实
      Specified by:
      get in interface FactStore
      Parameters:
      name - the fact name | 事实名称
      Returns:
      the fact, or null if not found | 事实,如果未找到则为null
    • getAll

      public <T> List<T> getAll(Class<T> type)
      Description copied from interface: FactStore
      Gets all facts of a specific type 获取特定类型的所有事实
      Specified by:
      getAll in interface FactStore
      Type Parameters:
      T - the fact type | 事实类型
      Parameters:
      type - the fact type | 事实类型
      Returns:
      list of facts | 事实列表
    • contains

      public boolean contains(String name)
      Description copied from interface: FactStore
      Checks if a named fact exists 检查命名事实是否存在
      Specified by:
      contains in interface FactStore
      Parameters:
      name - the fact name | 事实名称
      Returns:
      true if exists | 如果存在返回true
    • contains

      public boolean contains(Class<?> type)
      Description copied from interface: FactStore
      Checks if a fact of the given type exists 检查给定类型的事实是否存在
      Specified by:
      contains in interface FactStore
      Parameters:
      type - the fact type | 事实类型
      Returns:
      true if exists | 如果存在返回true
    • remove

      public Object remove(String name)
      Description copied from interface: FactStore
      Removes a named fact 移除命名事实
      Specified by:
      remove in interface FactStore
      Parameters:
      name - the fact name | 事实名称
      Returns:
      the removed fact, or null | 被移除的事实,或null
    • removeAll

      public <T> List<T> removeAll(Class<T> type)
      Description copied from interface: FactStore
      Removes all facts of a specific type 移除特定类型的所有事实
      Specified by:
      removeAll in interface FactStore
      Type Parameters:
      T - the fact type | 事实类型
      Parameters:
      type - the fact type | 事实类型
      Returns:
      list of removed facts | 被移除的事实列表
    • clear

      public void clear()
      Description copied from interface: FactStore
      Clears all facts 清除所有事实
      Specified by:
      clear in interface FactStore
    • size

      public int size()
      Description copied from interface: FactStore
      Gets the total number of facts 获取事实总数
      Specified by:
      size in interface FactStore
      Returns:
      fact count | 事实数量