Interface FactStore<T extends @Nullable Object>

Type Parameters:
T - The object/value type of the fact. A fact's value, and a FactReference in the store, can be null.
All Known Implementing Classes:
FactMap

public interface FactStore<T extends @Nullable Object>
A store of facts, each kept under its name. Rules refer to a fact by that name. FactMap is the built-in implementation.

The engine reads the facts through asMap() once, when a run starts, and each FactReference's value once too, and never changes the store. A fact added, replaced or removed while that run is going isn't seen by it; a change inside the object a fact's value was at the start is. So one store can serve one run after another.

See Also:
  • Method Details

    • getValue

      @Nullable T getValue(String name)
      Gets the value of the fact stored under a name.
      Parameters:
      name - The fact's name
      Returns:
      The value, or null either if there is no fact with that name or if the fact's value is null. To tell the two apart, ask asMap() whether it containsKey(name).
      Throws:
      IllegalArgumentException - if the store rejects name, as FactMap does for null
    • setValue

      void setValue(String name, T obj)
      Sets the value of the named fact.
      Parameters:
      name - The name
      obj - The value
      Throws:
      IllegalArgumentException - if the store rejects name, as FactMap does for null
    • put

      @Nullable FactReference<T> put(FactReference<T> ref)
      Stores a FactReference under its name.
      Parameters:
      ref - The FactReference to store
      Returns:
      The previous FactReference stored under the fact's name, or null if there was none, as with Map.put(Object, Object)
      Throws:
      IllegalArgumentException - if the store rejects the fact's name, as FactMap does for null
    • asMap

      Map<String,@Nullable FactReference<T>> asMap()
      Returns a read-only view of the facts, keyed by name. The view follows later changes to the store. A run copies its entries once, when it starts, binding each fact's value to its key.
      Returns:
      An unmodifiable map of each name to its FactReference; must not be null: a null one fails the run with a NullPointerException