Search in sources :

Example 1 with UnregisterFormulaCommand

use of de.prob.animator.command.UnregisterFormulaCommand in project prob2 by bendisposto.

the class StateSpace method unsubscribe.

public boolean unsubscribe(final Object subscriber, final Collection<? extends IEvalElement> formulas, boolean unregister) {
    boolean success = false;
    final List<AbstractCommand> unsubscribeCmds = new ArrayList<>();
    for (IEvalElement formula : formulas) {
        if (formulaRegistry.containsKey(formula)) {
            final WeakHashMap<Object, Object> subscribers = formulaRegistry.get(formula);
            subscribers.remove(subscriber);
            if (subscribers.isEmpty() && unregister) {
                unsubscribeCmds.add(new UnregisterFormulaCommand(formula));
            }
            success = true;
        }
    }
    if (!unsubscribeCmds.isEmpty()) {
        execute(new ComposedCommand(unsubscribeCmds));
    }
    return success;
}
Also used : AbstractCommand(de.prob.animator.command.AbstractCommand) ArrayList(java.util.ArrayList) IEvalElement(de.prob.animator.domainobjects.IEvalElement) UnregisterFormulaCommand(de.prob.animator.command.UnregisterFormulaCommand) ComposedCommand(de.prob.animator.command.ComposedCommand)

Aggregations

AbstractCommand (de.prob.animator.command.AbstractCommand)1 ComposedCommand (de.prob.animator.command.ComposedCommand)1 UnregisterFormulaCommand (de.prob.animator.command.UnregisterFormulaCommand)1 IEvalElement (de.prob.animator.domainobjects.IEvalElement)1 ArrayList (java.util.ArrayList)1