Class Counter

  • All Implemented Interfaces:
    java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

    public class Counter
    extends TypedAtomicActor
    This actor implements an up-down counter of received tokens. Whenever a token is received from the increment input, the internal counter is incremented. Whenever a token is received from the decrement port, the internal counter is decremented. Whenever a token is received from either input port, a token is created on the output port with the integer value of the current count. At most one token will be consumed from each input during each firing. If a token is present on both input ports during any firing, then the increment and the decrement will cancel out, and only one output token will be produced. If any firing a reset input is present and true, then the count will be reset.
    Since:
    Ptolemy II 2.0
    Version:
    $Id$
    Author:
    Steve Neuendorffer
    Pt.AcceptedRating:
    Yellow (neuendor)
    Pt.ProposedRating:
    Yellow (neuendor)
    • Field Detail

      • increment

        public TypedIOPort increment
        The increment port. If this input port receives a token, then the counter is incremented. The port has type general.
      • decrement

        public TypedIOPort decrement
        The decrement port. If this input port receives a token, then the counter is decremented. The port has type general.
      • output

        public TypedIOPort output
        The output port with type IntToken.
      • reset

        public TypedIOPort reset
        The reset input port. This is of type boolean.
    • Method Detail

      • fire

        public void fire()
                  throws IllegalActionException
        Consume at most one token from each input and update the counter appropriately. Send the current value of the counter to the output. If there are no input tokens available, no output will be produced. If a token is consumed from only the increment port the output value will be one more than the previous output value. If a token consumed from only the decrement port the output value will be one less than the previous output value. If a token is consumed from both input ports, then the output value will be the same as the previous output value. If the fire method is invoked multiple times in one iteration, then only the input read on the last invocation in the iteration will affect future outputs of the counter.
        Specified by:
        fire in interface Executable
        Overrides:
        fire in class AtomicActor<TypedIOPort>
        Throws:
        IllegalActionException - If there is no director.