Class FixedPointReceiver

  • All Implemented Interfaces:
    Receiver

    public class FixedPointReceiver
    extends AbstractReceiver
    The receiver for use with FixedPointDirector or any of its subclasses. This receiver has capacity 1. The status of this receiver can be either known or unknown. If it is known, then it can be either present or absent. If it is present, then it has a token, which provides a value.

    At first, an instance of this class has status unknown. The clear() method makes the status known and absent. The put() method makes the status known and present, and provides a value. The reset() method reverts the status to unknown. Once the status of a receiver becomes known, the value cannot be changed, nor can the status be changed from present to absent or vice versa. To change the value or the status, call reset() first. Normally, the reset() method is called only by the director and constructors.

    The isKnown() method returns true if the receiver has status known. The hasRoom() method returns true if the receiver has status unknown. If the receiver has a known status, the hasToken() method returns true if the receiver contains a token. If the receiver has an unknown status, the hasToken() method will throw an InvalidStateException.

    This class is based on the original SRReceiver, written by Paul Whitaker.

    Since:
    Ptolemy II 5.2
    Version:
    $Id$
    Author:
    Haiyang Zheng and Edward A. Lee
    Pt.AcceptedRating:
    Yellow (eal)
    Pt.ProposedRating:
    Green (hyzheng)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected FixedPointDirector _director
      The director of this receiver.
      protected boolean _known
      A flag indicating whether this receiver has status known.
      protected Token _token
      The token held.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Set the status of this receiver to be known and absent.
      java.util.List<Token> elementList()
      Return a list with the token currently in the receiver, or an empty list if there is no such token.
      Token get()
      Return the contained token.
      boolean hasRoom()
      Return true if the status of the receiver is unknown.
      boolean hasRoom​(int numberOfTokens)
      If the argument is 1, return true if the status of the receiver is unknown.
      boolean hasToken()
      Return true if the receiver contains a token, and false otherwise.
      boolean hasToken​(int numberOfTokens)
      If the argument is 1, return true if the receiver contains a token, and false otherwise.
      boolean isKnown()
      Return true if this receiver has status known, that is, this receiver either is either known to have a token or known to not to have a token.
      void put​(Token token)
      If the specified token is non-null, then set the status of this receiver to known and present, and to contain the specified token.
      void reset()
      Reset the receiver by deleting any contained tokens and setting the status of this receiver to unknown, unless the containing port has no sources, in which case set to known and absent.
      void setContainer​(IOPort port)
      Set the container.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • _known

        protected boolean _known
        A flag indicating whether this receiver has status known.
      • _token

        protected Token _token
        The token held.
    • Constructor Detail

      • FixedPointReceiver

        public FixedPointReceiver()
        Construct an FixedPointReceiver with unknown status. This constructor does not need a director.
      • FixedPointReceiver

        public FixedPointReceiver​(FixedPointDirector director)
        Construct an FixedPointReceiver with unknown status.
        Parameters:
        director - The director of this receiver.
    • Method Detail

      • elementList

        public java.util.List<Token> elementList()
        Return a list with the token currently in the receiver, or an empty list if there is no such token.
        Specified by:
        elementList in interface Receiver
        Overrides:
        elementList in class AbstractReceiver
        Returns:
        A list of instances of Token.
      • hasRoom

        public boolean hasRoom()
        Return true if the status of the receiver is unknown.
        Specified by:
        hasRoom in interface Receiver
        Specified by:
        hasRoom in class AbstractReceiver
        Returns:
        True if the status of the receiver is unknown.
        See Also:
        isKnown()
      • hasRoom

        public boolean hasRoom​(int numberOfTokens)
                        throws java.lang.IllegalArgumentException
        If the argument is 1, return true if the status of the receiver is unknown. Otherwise, throw an exception. This receiver has capacity one.
        Specified by:
        hasRoom in interface Receiver
        Specified by:
        hasRoom in class AbstractReceiver
        Parameters:
        numberOfTokens - The number of tokens to put into the receiver.
        Returns:
        True if the receiver can accept a token.
        Throws:
        java.lang.IllegalArgumentException - If the argument is not positive.
        See Also:
        isKnown(), hasRoom()
      • hasToken

        public boolean hasToken()
        Return true if the receiver contains a token, and false otherwise. If the receiver has status unknown, this method will throw an exception.
        Specified by:
        hasToken in interface Receiver
        Specified by:
        hasToken in class AbstractReceiver
        Returns:
        True if this receiver contains a token.
        Throws:
        InvalidStateException - If the status is unknown.
      • hasToken

        public boolean hasToken​(int numberOfTokens)
        If the argument is 1, return true if the receiver contains a token, and false otherwise. If the argument is larger than 1, return false (this receiver has capacity one). If the receiver has status unknown, throw an exception.
        Specified by:
        hasToken in interface Receiver
        Specified by:
        hasToken in class AbstractReceiver
        Parameters:
        numberOfTokens - The number of tokens.
        Returns:
        True if the argument is 1 and the receiver has a token.
        Throws:
        java.lang.IllegalArgumentException - If the argument is not positive.
        InvalidStateException - If the status is unknown.
        See Also:
        hasToken()
      • isKnown

        public boolean isKnown()
        Return true if this receiver has status known, that is, this receiver either is either known to have a token or known to not to have a token.
        Specified by:
        isKnown in interface Receiver
        Overrides:
        isKnown in class AbstractReceiver
        Returns:
        True if this receiver has status known.
      • put

        public void put​(Token token)
                 throws IllegalActionException
        If the specified token is non-null, then set the status of this receiver to known and present, and to contain the specified token. If the receiver is already known and the value of the contained token is different from that of the new token, throw an exception. If the specified token is null, then set the status to be known and absent (by calling clear()).
        Specified by:
        put in interface Receiver
        Specified by:
        put in class AbstractReceiver
        Parameters:
        token - The token to be put into this receiver.
        Throws:
        java.lang.IllegalArgumentException - If the argument is null.
        IllegalActionException - If the status is known and absent, or a token is present but not have the same value, or a token is present and cannot be compared to the specified token.
      • reset

        public void reset()
        Reset the receiver by deleting any contained tokens and setting the status of this receiver to unknown, unless the containing port has no sources, in which case set to known and absent. This is called by the , normally in its initialize() and postfire() methods.
        Specified by:
        reset in interface Receiver
        Overrides:
        reset in class AbstractReceiver