Trull

edu.luc.cs.trull
Class If

java.lang.Object
  extended by edu.luc.cs.trull.EmptyComponent
      extended by edu.luc.cs.trull.TerminatingComponent
          extended by edu.luc.cs.trull.AbstractComponent
              extended by edu.luc.cs.trull.AbstractCombinator
                  extended by edu.luc.cs.trull.Switch
                      extended by edu.luc.cs.trull.If
All Implemented Interfaces:
Combinator, Component, PropertyChangeSource, Startable, Suspendable, Terminating, java.beans.PropertyChangeListener, java.util.EventListener

public class If
extends Switch

A data-driven selection mechanism that evaluates its predicate and immediately chooses and starts the corresponding branch. The resulting component terminates when the chosen branch terminates.


Nested Class Summary
 
Nested classes/interfaces inherited from class edu.luc.cs.trull.Switch
Switch.LocalListener, Switch.SwitchTerminationListener
 
Nested classes/interfaces inherited from class edu.luc.cs.trull.AbstractCombinator
AbstractCombinator.DefaultTerminationListener
 
Field Summary
private  EventPredicate predicate
          The predicate used by this combinator.
 
Fields inherited from class edu.luc.cs.trull.AbstractCombinator
components
 
Constructor Summary
If()
          Constructs an empty If component.
If(EventPredicate predicate, Component yes)
          Constructs an If component with only a yes branch.
If(EventPredicate predicate, Component yes, Component no)
          Constructs an If component.
 
Method Summary
 EventPredicate getPredicate()
          Returns the event predicate used by this If component.
protected static EventValuator predicateToValuator(EventPredicate predicate)
          Converts an event predicate to an event valuator.
 void setPredicate(EventPredicate predicate)
          Sets the event predicate used by this If component.
 
Methods inherited from class edu.luc.cs.trull.Switch
disconnectComponent, getChildTerminationListener, getCurrentComponent, getValuator, propertyChange, removeComponent, resume, setValuator, start, stop, suspend, switchToComponent
 
Methods inherited from class edu.luc.cs.trull.AbstractCombinator
addComponent, addComponent, addComponent, getComponent, getComponentCount, getComponents, removeAllComponents, removeComponent
 
Methods inherited from class edu.luc.cs.trull.AbstractComponent
addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, getExternalListeners, getPropertyChangeListeners, removePropertyChangeListener
 
Methods inherited from class edu.luc.cs.trull.TerminatingComponent
fireTermination, getParent, getTermEvent, scheduleTermination, setTerminationListener
 
Methods inherited from class edu.luc.cs.trull.EmptyComponent
getTerminationListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface edu.luc.cs.trull.PropertyChangeSource
addPropertyChangeListener, getPropertyChangeListeners, removePropertyChangeListener
 
Methods inherited from interface edu.luc.cs.trull.Terminating
getTerminationListener, setTerminationListener
 

Field Detail

predicate

private EventPredicate predicate
The predicate used by this combinator.

Constructor Detail

If

public If()
Constructs an empty If component. Specific properties can be changed later.


If

public If(EventPredicate predicate,
          Component yes)
Constructs an If component with only a yes branch.

Parameters:
predicate - the event predicate used in choosing a branch.
yes - the branch chosen when the predicate evalutes to true.

If

public If(EventPredicate predicate,
          Component yes,
          Component no)
Constructs an If component.

Parameters:
predicate - the event predicate used in choosing a branch.
yes - the branch chosen when the predicate evalutes to true.
no - the branch chosen when the predicate evalutes to false.
Method Detail

getPredicate

public EventPredicate getPredicate()
Returns the event predicate used by this If component.

Returns:
the event predicate.

predicateToValuator

protected static EventValuator predicateToValuator(EventPredicate predicate)
Converts an event predicate to an event valuator. This method is used since the If combinator is implemented as a Switch.

Parameters:
predicate - the event predicate.
Returns:
the corresponding event valuator.

setPredicate

public void setPredicate(EventPredicate predicate)
Sets the event predicate used by this If component.

Parameters:
predicate - the event predicate.

Trull

http://www.cs.luc.edu/trull/