Package io.github.brantunger.unruly.api
Class Fact<T extends @Nullable Object>
java.lang.Object
io.github.brantunger.unruly.api.Fact<T>
- Type Parameters:
T- The object/value type of the fact. A fact's value can benull.
- All Implemented Interfaces:
FactReference<T>
The built-in, immutable
FactReference. A rule sees the fact's value under the fact's name, so a fact named
applicant is applicant in a condition or action. The value object isn't copied: a rule or a listener
gets the same object the fact holds.
A fact's name and value can't change. To give a name a new value, store a new fact, as
FactStore.setValue(String, Object) does. The value object itself isn't copied, so changes to it are seen
everywhere it's held.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Fact
Instantiate a Fact from the name and value.- Parameters:
name- The name of the factvalue- The value of the fact- Throws:
NullPointerException- ifnameisnull
-
Fact
Instantiate a Fact from another Fact object. The source may hold a narrower type, so aFact<String>can be copied into aFact<Object>.- Parameters:
fact- The existing Fact object to get the value and name from- Throws:
NullPointerException- iffactor its name isnull
-
-
Method Details
-
getName
Description copied from interface:FactReferenceGets the name of the fact.- Specified by:
getNamein interfaceFactReference<T extends @Nullable Object>- Returns:
- The name
-
getValue
Description copied from interface:FactReferenceGets the value of the fact. A run calls it once, when it starts.If it throws,
run()orrunWithResult()throws that exception unchanged before any listener callback, so no listener hears of the run, and the engine doesn't log it; see Implementing FactStore.- Specified by:
getValuein interfaceFactReference<T extends @Nullable Object>- Returns:
- The value, which can be
null
-
equals
-
hashCode
public int hashCode()Based on the name and value. A fact whose value is changed in place, such as a list that gains an element, gets a different hash code, so don't change a value while its fact is in a hashed collection such as aHashSet. -
toString
-