Class FSMReceiver

  • All Implemented Interfaces:
    Receiver

    public class FSMReceiver
    extends AbstractReceiver
    A receiver with capacity one for which one can explicitly set the status.
    Since:
    Ptolemy II 8.0
    Version:
    $Id$
    Author:
    Edward A. Lee
    Pt.AcceptedRating:
    Red (cxh)
    Pt.ProposedRating:
    Yellow (eal)
    • Constructor Summary

      Constructors 
      Constructor Description
      FSMReceiver()
      Construct an empty receiver with no container.
      FSMReceiver​(IOPort container)
      Construct an empty receiver with the specified container.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clear this receiver of any contained token and set the known status to true.
      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()
      Get the contained Token.
      Token[] getArray​(int numberOfTokens)
      If the argument is 1, there is a token, and the status is known, then return an array containing the one token.
      boolean hasRoom()
      Return true.
      boolean hasRoom​(int numberOfTokens)
      Return true if the argument is 1, and otherwise return false.
      boolean hasToken()
      Return true if this mailbox is not empty.
      boolean hasToken​(int numberOfTokens)
      Return true if the argument is 1 and this receiver is not empty, and otherwise return false.
      boolean isKnown()
      Return whether the state of the receiver is known.
      void put​(Token token)
      Put a token into this receiver.
      void putArray​(Token[] tokenArray, int numberOfTokens)
      If the argument has one token, then put that token in the receiver.
      void reset()
      Set the receiver to unknown.
      • Methods inherited from class java.lang.Object

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

      • FSMReceiver

        public FSMReceiver()
        Construct an empty receiver with no container. The initial status is unknown.
      • FSMReceiver

        public FSMReceiver​(IOPort container)
                    throws IllegalActionException
        Construct an empty receiver with the specified container. The initial status is unknown.
        Parameters:
        container - The container.
        Throws:
        IllegalActionException - If the container does not accept this receiver.
    • Method Detail

      • clear

        public void clear()
        Clear this receiver of any contained token and set the known status to true.
        Specified by:
        clear in interface Receiver
        Overrides:
        clear in class AbstractReceiver
      • get

        public Token get()
                  throws NoTokenException
        Get the contained Token. If there is none, throw an exception. The token is not removed. It can be repeatedly read.
        Specified by:
        get in interface Receiver
        Specified by:
        get in class AbstractReceiver
        Returns:
        The token contained by this receiver.
        Throws:
        NoTokenException - If this receiver is empty or unknown
      • getArray

        public Token[] getArray​(int numberOfTokens)
                         throws NoTokenException
        If the argument is 1, there is a token, and the status is known, then return an array containing the one token. Otherwise, throw an exception.
        Specified by:
        getArray in interface Receiver
        Overrides:
        getArray in class AbstractReceiver
        Parameters:
        numberOfTokens - The number of tokens to get.
        Returns:
        The array of tokens.
        Throws:
        NoTokenException - If the status is unknown, if there is no token, or if the argument is not 1.
      • hasRoom

        public boolean hasRoom​(int numberOfTokens)
                        throws java.lang.IllegalArgumentException
        Return true if the argument is 1, and otherwise return false.
        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 argument is 1, and otherwise return false.
        Throws:
        java.lang.IllegalArgumentException - If the argument is not positive. This is a runtime exception, so it does not need to be declared explicitly.
      • hasToken

        public boolean hasToken​(int numberOfTokens)
                         throws java.lang.IllegalArgumentException
        Return true if the argument is 1 and this receiver is not empty, and otherwise return false.
        Specified by:
        hasToken in interface Receiver
        Specified by:
        hasToken in class AbstractReceiver
        Parameters:
        numberOfTokens - The number of tokens to get from the receiver.
        Returns:
        True if the argument is 1 and this receiver is not empty.
        Throws:
        InternalErrorException - If the status is not known.
        java.lang.IllegalArgumentException - If the argument is not positive. This is a runtime exception, so it does not need to be declared explicitly.
      • put

        public void put​(Token token)
                 throws NoRoomException
        Put a token into this receiver. If the argument is null, then the receiver will not contain a token after this returns, getting the same effect as calling clear(). If there was previously a token in the receiver, this overwrites that token. Set the known status of the receiver to true.
        Specified by:
        put in interface Receiver
        Specified by:
        put in class AbstractReceiver
        Parameters:
        token - The token to be put into the mailbox.
        Throws:
        NoRoomException - If this mailbox is not empty.
      • putArray

        public void putArray​(Token[] tokenArray,
                             int numberOfTokens)
                      throws NoRoomException,
                             IllegalActionException
        If the argument has one token, then put that token in the receiver. Otherwise, throw an exception.
        Specified by:
        putArray in interface Receiver
        Overrides:
        putArray in class AbstractReceiver
        Parameters:
        tokenArray - The array containing tokens to put into this receiver.
        numberOfTokens - The number of elements of the token array to put into this receiver.
        Throws:
        NoRoomException - If the token array cannot be put.
        IllegalActionException - If the token is not acceptable to one of the ports (e.g., wrong type).