Package io.github.brantunger.unruly.api
Interface FactStore<T extends @Nullable Object>
- Type Parameters:
T- The object/value type of the fact. A fact's value, and aFactReferencein the store, can benull.
- 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 Summary
Modifier and TypeMethodDescriptionMap<String, @Nullable FactReference<T>> asMap()Returns a read-only view of the facts, keyed by name.@Nullable TGets the value of the fact stored under a name.@Nullable FactReference<T> put(FactReference<T> ref) Stores aFactReferenceunder its name.voidSets the value of the named fact.
-
Method Details
-
getValue
Gets the value of the fact stored under a name.- Parameters:
name- The fact's name- Returns:
- The value, or
nulleither if there is no fact with that name or if the fact's value isnull. To tell the two apart, askasMap()whether itcontainsKey(name). - Throws:
IllegalArgumentException- if the store rejectsname, asFactMapdoes fornull
-
setValue
Sets the value of the named fact.- Parameters:
name- The nameobj- The value- Throws:
IllegalArgumentException- if the store rejectsname, asFactMapdoes fornull
-
put
Stores aFactReferenceunder its name.- Parameters:
ref- TheFactReferenceto store- Returns:
- The previous
FactReferencestored under the fact's name, ornullif there was none, as withMap.put(Object, Object) - Throws:
IllegalArgumentException- if the store rejects the fact's name, asFactMapdoes fornull
-
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 benull: anullone fails the run with aNullPointerException
-