ptolemy.actor.lib.logic
Class Comparator

java.lang.Object
  extended byptolemy.kernel.util.NamedObj
      extended byptolemy.kernel.InstantiableNamedObj
          extended byptolemy.kernel.Entity
              extended byptolemy.kernel.ComponentEntity
                  extended byptolemy.actor.AtomicActor
                      extended byptolemy.actor.TypedAtomicActor
                          extended byptolemy.actor.lib.logic.Comparator
All Implemented Interfaces:
ptolemy.actor.Actor, ptolemy.kernel.util.Changeable, java.lang.Cloneable, ptolemy.kernel.util.Debuggable, ptolemy.kernel.util.DebugListener, ptolemy.kernel.util.Derivable, ptolemy.actor.Executable, ptolemy.kernel.util.Instantiable, ptolemy.kernel.util.ModelErrorHandler, ptolemy.kernel.util.MoMLExportable, ptolemy.kernel.util.Nameable, java.io.Serializable, ptolemy.actor.TypedActor

public class Comparator
extends ptolemy.actor.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:

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,v 1.16 2004/04/13 03:09:23 cxh Exp $
Author:
Edward A. Lee
See Also:
Serialized Form
Accepted Rating:
Green (neuendor)
Proposed Rating:
Green (eal)

Nested Class Summary
 
Nested classes inherited from class ptolemy.kernel.Entity
ptolemy.kernel.Entity.ContainedObjectsIterator
 
Field Summary
 ptolemy.kernel.util.StringAttribute comparison
          The comparison operator.
 ptolemy.actor.TypedIOPort left
          The left input port, which has type double.
 ptolemy.actor.TypedIOPort output
          The output port, which has type boolean.
 ptolemy.actor.TypedIOPort right
          The right input port, which has type double.
 ptolemy.data.expr.Parameter tolerance
          The tolerance for the comparison.
 
Fields inherited from class ptolemy.actor.AtomicActor
_stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
Comparator(ptolemy.kernel.CompositeEntity container, java.lang.String name)
          Construct an actor with the given container and name.
 
Method Summary
 void attributeChanged(ptolemy.kernel.util.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.TypedAtomicActor
_addPort, attributeTypeChanged, clone, newPort, typeConstraintList
 
Methods inherited from class ptolemy.actor.AtomicActor
_createReceivers, clone, connectionsChanged, getDirector, getExecutiveDirector, getFunctionDependency, getManager, initialize, inputPortList, iterate, newReceiver, outputPortList, postfire, preinitialize, pruneDependencies, removeDependency, setContainer, stop, stopFire, terminate, wrapup
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName, validateSettables
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, getAttribute, getAttributes, getChangeListeners, getClassName, getDerivedLevel, getDerivedList, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setModelErrorHandler, setPersistent, setSource, toplevel, toString, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
getDirector, getExecutiveDirector, getFunctionDependency, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
initialize, iterate, postfire, preinitialize, stop, stopFire, terminate, wrapup
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getFullName, getName, getName
 

Field Detail

left

public ptolemy.actor.TypedIOPort left
The left input port, which has type double.


right

public ptolemy.actor.TypedIOPort right
The right input port, which has type double.


output

public ptolemy.actor.TypedIOPort output
The output port, which has type boolean.


comparison

public ptolemy.kernel.util.StringAttribute comparison
The comparison operator. This is a string-valued attribute that defaults to ">".


tolerance

public ptolemy.data.expr.Parameter tolerance
The tolerance for the comparison. This has type double, and defaults to 0.0.

Constructor Detail

Comparator

public Comparator(ptolemy.kernel.CompositeEntity container,
                  java.lang.String name)
           throws ptolemy.kernel.util.NameDuplicationException,
                  ptolemy.kernel.util.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:
ptolemy.kernel.util.IllegalActionException - If the actor cannot be contained by the proposed container.
ptolemy.kernel.util.NameDuplicationException - If the container already has an actor with this name.
Method Detail

attributeChanged

public void attributeChanged(ptolemy.kernel.util.Attribute attribute)
                      throws ptolemy.kernel.util.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.

Parameters:
attribute - The attribute that changed.
Throws:
ptolemy.kernel.util.IllegalActionException - If the comparison is not recognized.

fire

public void fire()
          throws ptolemy.kernel.util.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().

Throws:
ptolemy.kernel.util.IllegalActionException - If there is no director.

prefire

public boolean prefire()
                throws ptolemy.kernel.util.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.

Returns:
True if there inputs available on both input ports.
Throws:
ptolemy.kernel.util.IllegalActionException - If the base class throws it.