ptolemy.actor.lib.logic
Class Comparator
java.lang.Object
ptolemy.kernel.util.NamedObj
ptolemy.kernel.InstantiableNamedObj
ptolemy.kernel.Entity
ptolemy.kernel.ComponentEntity
ptolemy.actor.AtomicActor
ptolemy.actor.TypedAtomicActor
ptolemy.actor.lib.logic.Comparator
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
public class Comparator
- extends TypedAtomicActor
Compare two double-valued inputs, and output the boolean result
of the comparison. The exact comparison performed is given by the
comparison attribute, which can take any of the following
values:
- >: left > right
- >=: left >= right
- <: left < right
- <=: left <= right
- ==: left == right
The default is ">".
The input ports are named left and right to indicate
which side of the comparison operator their value appears on.
The tolerance parameter, which defaults to zero, defines
an error tolerance. That is, the actor may produce true even if
the specified test is not exactly satisfied, but rather is almost
satisfied, within the specified tolerance.
Note that this actor will work with any data type that can be losslessly
converted to doubles, such as integers.
- Since:
- Ptolemy II 1.0
- Version:
- $Id: Comparator.java 57040 2010-01-27 20:52:32Z cxh $
- Author:
- Edward A. Lee
- See Also:
- Serialized Form
- Accepted Rating:
- Proposed Rating:
Fields inherited from class ptolemy.kernel.util.NamedObj |
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS |
Constructor Summary |
Comparator(CompositeEntity container,
java.lang.String name)
Construct an actor with the given container and name. |
Method Summary |
void |
attributeChanged(Attribute attribute)
Override the base class to determine which comparison is being
specified. |
void |
fire()
Consume exactly one input token from each input port,
and compute the specified comparison. |
boolean |
prefire()
Check that each input port has at least one token, and if
so, return the result of the superclass prefire() method. |
Methods inherited from class ptolemy.actor.AtomicActor |
_actorFiring, _actorFiring, addActorFiringListener, addInitializable, clone, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, initialize, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, postfire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate, wrapup |
Methods inherited from class ptolemy.kernel.ComponentEntity |
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName |
Methods inherited from class ptolemy.kernel.Entity |
_description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName |
Methods inherited from class ptolemy.kernel.util.NamedObj |
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
left
public TypedIOPort left
- The left input port, which has type double.
right
public TypedIOPort right
- The right input port, which has type double.
output
public TypedIOPort output
- The output port, which has type boolean.
comparison
public StringAttribute comparison
- The comparison operator. This is a string-valued attribute
that defaults to ">".
tolerance
public Parameter tolerance
- The tolerance for the comparison. This has type double,
and defaults to 0.0.
_comparison
private int _comparison
_tolerance
private double _tolerance
_LT
private static final int _LT
- See Also:
- Constant Field Values
_LE
private static final int _LE
- See Also:
- Constant Field Values
_GT
private static final int _GT
- See Also:
- Constant Field Values
_GE
private static final int _GE
- See Also:
- Constant Field Values
_EQ
private static final int _EQ
- See Also:
- Constant Field Values
Comparator
public Comparator(CompositeEntity container,
java.lang.String name)
throws NameDuplicationException,
IllegalActionException
- Construct an actor with the given container and name. Set the
comparison to the default (">"). Set the types of
the input ports to double, and the type of the output port
to boolean.
- Parameters:
container
- The container.name
- The name of this actor.
- Throws:
IllegalActionException
- If the actor cannot be contained
by the proposed container.
NameDuplicationException
- If the container already has an
actor with this name.
attributeChanged
public void attributeChanged(Attribute attribute)
throws IllegalActionException
- Override the base class to determine which comparison is being
specified. Read the value of the comparison attribute and set
the cached value appropriately.
- Overrides:
attributeChanged
in class NamedObj
- Parameters:
attribute
- The attribute that changed.
- Throws:
IllegalActionException
- If the comparison is not recognized.
fire
public void fire()
throws IllegalActionException
- Consume exactly one input token from each input port,
and compute the specified comparison. This method assumes
that both ports have an input, as checked by prefire().
- Specified by:
fire
in interface Executable
- Overrides:
fire
in class AtomicActor
- Throws:
IllegalActionException
- If there is no director.
prefire
public boolean prefire()
throws IllegalActionException
- Check that each input port has at least one token, and if
so, return the result of the superclass prefire() method.
Otherwise, return false.
- Specified by:
prefire
in interface Executable
- Overrides:
prefire
in class AtomicActor
- Returns:
- True if there inputs available on both input ports.
- Throws:
IllegalActionException
- If the base class throws it.