use of de.prob.animator.command.RegisterFormulaCommand in project prob2 by bendisposto.
the class StateSpace method subscribe.
/**
* This method lets ProB know that the subscriber is interested in the
* specified formulas. ProB will then evaluate the formulas for every state
* (after which the values can be retrieved from the
* {@link State#getValues()} method).
*
* @param subscriber
* who is interested in the given formulas
* @param formulas
* that are of interest
* @return whether or not the subscription was successful (will return true
* if at least one of the formulas was successfully subscribed)
*/
public boolean subscribe(final Object subscriber, final Collection<? extends IEvalElement> formulas) {
boolean success = false;
List<AbstractCommand> subscribeCmds = new ArrayList<>();
for (IEvalElement formulaOfInterest : formulas) {
if (formulaOfInterest instanceof CSP) {
logger.info("CSP formula {} not subscribed because CSP evaluation is not state based. Use eval method instead", formulaOfInterest.getCode());
} else {
if (formulaRegistry.containsKey(formulaOfInterest)) {
formulaRegistry.get(formulaOfInterest).put(subscriber, new WeakReference<Object>(formulaOfInterest));
success = true;
} else {
WeakHashMap<Object, Object> subscribers = new WeakHashMap<>();
subscribers.put(subscriber, new WeakReference<Object>(subscriber));
formulaRegistry.put(formulaOfInterest, subscribers);
subscribeCmds.add(new RegisterFormulaCommand(formulaOfInterest));
success = true;
}
}
}
if (!subscribeCmds.isEmpty()) {
execute(new ComposedCommand(subscribeCmds));
}
return success;
}
Aggregations