Interface FactStore

All Known Implementing Classes:
DefaultFactStore

public interface FactStore
Fact Store Interface - Manages Facts in Rule Context 事实存储接口 - 管理规则上下文中的事实

Provides typed storage and retrieval of fact objects used during rule evaluation.

提供在规则评估期间使用的事实对象的类型化存储和检索。

Features | 主要功能:

  • Type-based fact retrieval - 基于类型的事实检索
  • Named fact support - 命名事实支持
  • Multiple facts of same type - 同类型多个事实

Usage Examples | 使用示例:

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

Security | 安全性:

  • Thread-safe: Implementation dependent - 线程安全: 取决于实现
  • Null-safe: No (names and types must not be null) - 空值安全: 否(名称和类型不能为null)
Since:
JDK 25, opencode-base-rules V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(Object fact)
    Adds a fact to the store 向存储添加事实
    void
    add(String name, Object fact)
    Adds a named fact to the store 向存储添加命名事实
    void
    Clears all facts 清除所有事实
    default <T> boolean
    Checks if a typed key exists in the store 检查类型化键是否存在于存储中
    boolean
    contains(Class<?> type)
    Checks if a fact of the given type exists 检查给定类型的事实是否存在
    boolean
    Checks if a named fact exists 检查命名事实是否存在
    default <T> Optional<T>
    get(TypedKey<T> key)
    Gets a typed fact value by typed key 通过类型化键获取类型化事实值
    <T> Optional<T>
    get(Class<T> type)
    Gets a fact by type 按类型获取事实
    get(String name)
    Gets a fact by name 按名称获取事实
    <T> List<T>
    getAll(Class<T> type)
    Gets all facts of a specific type 获取特定类型的所有事实
    default <T> void
    put(TypedKey<T> key, T value)
    Puts a typed value by typed key 通过类型化键存放类型化值
    remove(String name)
    Removes a named fact 移除命名事实
    <T> List<T>
    removeAll(Class<T> type)
    Removes all facts of a specific type 移除特定类型的所有事实
    int
    Gets the total number of facts 获取事实总数
  • Method Details

    • add

      void add(Object fact)
      Adds a fact to the store 向存储添加事实
      Parameters:
      fact - the fact object | 事实对象
    • add

      void add(String name, Object fact)
      Adds a named fact to the store 向存储添加命名事实
      Parameters:
      name - the fact name | 事实名称
      fact - the fact object | 事实对象
    • get

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

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

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

      boolean contains(String name)
      Checks if a named fact exists 检查命名事实是否存在
      Parameters:
      name - the fact name | 事实名称
      Returns:
      true if exists | 如果存在返回true
    • contains

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

      Object remove(String name)
      Removes a named fact 移除命名事实
      Parameters:
      name - the fact name | 事实名称
      Returns:
      the removed fact, or null | 被移除的事实,或null
    • removeAll

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

      void clear()
      Clears all facts 清除所有事实
    • size

      int size()
      Gets the total number of facts 获取事实总数
      Returns:
      fact count | 事实数量
    • get

      default <T> Optional<T> get(TypedKey<T> key)
      Gets a typed fact value by typed key 通过类型化键获取类型化事实值
      Type Parameters:
      T - the value type | 值类型
      Parameters:
      key - the typed key | 类型化键
      Returns:
      optional containing the typed value | 包含类型化值的Optional
      Since:
      JDK 25, opencode-base-rules V1.0.3
    • put

      default <T> void put(TypedKey<T> key, T value)
      Puts a typed value by typed key 通过类型化键存放类型化值
      Type Parameters:
      T - the value type | 值类型
      Parameters:
      key - the typed key | 类型化键
      value - the value | 值
      Since:
      JDK 25, opencode-base-rules V1.0.3
    • contains

      default <T> boolean contains(TypedKey<T> key)
      Checks if a typed key exists in the store 检查类型化键是否存在于存储中
      Type Parameters:
      T - the value type | 值类型
      Parameters:
      key - the typed key | 类型化键
      Returns:
      true if exists | 如果存在返回true
      Since:
      JDK 25, opencode-base-rules V1.0.3