public class BeliefObserver extends Observer
Modifier and Type | Field and Description |
---|---|
(package private) FormulaFilter |
filter |
(package private) CasaKB |
kbase |
(package private) Runnable1<Formula,Object> |
runnable |
Constructor and Description |
---|
BeliefObserver(CasaKB kbase,
Formula formula,
FormulaFilter filter,
Runnable1<Formula,Object> runnable)
Constructs and new BeliefObserver to monitor the knowledge base for changes
to one or more formulas and execute runnable when its value changes,
subject to filter.
|
Modifier and Type | Method and Description |
---|---|
static BeliefObserver |
onValueChange(CasaKB kbase,
String var,
FormulaFilter filter,
Runnable1<Object,Object> runnable)
Creates a BeliefObserver and adds it to the kbase so that runnable is executed
every time the var changes, subject to the filter.
|
void |
setFilter(FormulaFilter f) |
boolean |
update(Formula formula)
Called whenever the formula changes.
|
addFormula, disableTimeout, getMyKBase, getObservedFormulas, getTimeOut, getWakeUpDate, isEnabledTimeout, timeout, toString
CasaKB kbase
FormulaFilter filter
public BeliefObserver(CasaKB kbase, Formula formula, FormulaFilter filter, Runnable1<Formula,Object> runnable)
kbase
- The KB to monitor.formula
- The formula (perhaps first of many) to monitor.filter
- A filter that can suppress the calling of runnable.run(Formula)runnable
- A type parameterized runnable to run when the formula changes (the return value is ignored).public boolean update(Formula formula)
public void setFilter(FormulaFilter f)
public static BeliefObserver onValueChange(CasaKB kbase, String var, FormulaFilter filter, Runnable1<Object,Object> runnable) throws ParseException
To stop observing this change, call kbase.removeObserver() with the parameter being the returned BeliefObject from this method call.
kbase
- The KB to monitor.var
- The variable to monitor; what's actually monitored is a unique predicate in the kb of the form "(var value)".filter
- A filter that can suppress the calling of runnable.run(Formula)runnable
- A type parameterized runnable to run when the formula changes (the return value is ignored, and the parameter of the run() method is the VALUE of the variable in KB).ParseException