Class GenericCondObsrvrImpl<C extends GenericCondition,P extends SimObject>

java.lang.Object
org.bzdev.drama.generic.GenericCondObsrvrImpl<C,P>
Direct Known Subclasses:
CondObserverImpl

public abstract class GenericCondObsrvrImpl<C extends GenericCondition,P extends SimObject> extends Object
Implement a condition observer. This class' subclass CondObserverImpl should be used. An overview of this class appears in the documentation for that class.
See Also:
  • Constructor Details

    • GenericCondObsrvrImpl

      protected GenericCondObsrvrImpl(P parent)
      Constructor.
      Parameters:
      parent - a simulation object (SimObject) that implements CondObserver
  • Method Details

    • setCondObserverImpl

      protected void setCondObserverImpl(CondObserverImpl<C,P> instance)
      Indicate the actual class of this object.
      Parameters:
      instance - this object as a CondObserverImpl
    • getParent

      public P getParent()
      Get a condition-observer implementation's parent. The parent is an instance of SimObject that implements CondObserver.
      Returns:
      the parent
    • transformedMode

      protected ConditionMode transformedMode(ConditionMode mode)
      The mode to store in a map argument for onCondition. The default simply returns its argument. Subclasses should override this when a more appropriate mode is desired. For example, when an addCondition method is called for a domain, the appropriate mode when the change is propagated to actors and domain members is DOMAIN_ADDED_CONDITION rather than OBSERVER_ADDED_CONDITION.
      Parameters:
      mode - the original mode
      Returns:
      the new mode
    • addCondition

      public boolean addCondition(C c)
      Associate a condition with an observer.
      Parameters:
      c - the condition
      Returns:
      true on success; false on failure
    • removeCondition

      public boolean removeCondition(C c)
      Disassociate a condition with a condition observer.
      Parameters:
      c - the condition
      Returns:
      true on success; false on failure
    • removeAllConditions

      public void removeAllConditions()
      Remove all conditions. Provided for cleanup by onDelete() for a SimObject that implements a condition observer, using this class.
    • hasCondition

      public boolean hasCondition(C c)
      Determine if a condition observer has (is associated with) a condition.
      Parameters:
      c - the condition
      Returns:
      true if the condition observer has condition c; false otherwise
    • conditionSet

      public Set<C> conditionSet()
      Get a set of conditions.
      Returns:
      the set of conditions that are associated with this condition observer
    • setConditionChangeQMode

      public void setConditionChangeQMode(boolean value)
      Set whether condition-change notifications should be queued or sent immediately. Setting this mode to true will improve performance when many conditions are changed at the same simulation time. If the mode is changed from true to false while there are some queued notifications, those will be forwarded.
      Parameters:
      value - true if notifications should be queued; false if they should be sent immediately.
    • getConditionChangeQMode

      public boolean getConditionChangeQMode()
      Determine if condition-change notifications are queued.
      Returns:
      true if queued; false otherwise.
    • doConditionChange

      protected abstract void doConditionChange(C c, ConditionMode mode, SimObject source)
      Respond to a condition change. Subclasses must implement this method. It will be called for each condition change either immediately or (with the default implementation of doConditionChange(Set)) at some later time depending on whether condition-queue mode is set.
      Parameters:
      c - the condition that changed
      mode - the mode for the condition change
      source - the object that changed the condition
    • doConditionChange

      protected void doConditionChange(Map<C,ConditionInfo> cmap)
      Respond to a set of condition changes. A set of conditions is stored when condition-queue mode is set and then used when completeNotification is called. The default implementation goes through each member of the set and passes that condition to doConditionChange(C).
      Parameters:
      cmap - a set of conditions