ptolemy.actor
Class Mailbox

java.lang.Object
  extended by ptolemy.actor.AbstractReceiver
      extended by ptolemy.actor.Mailbox
All Implemented Interfaces:
Receiver
Direct Known Subclasses:
CTReceiver, GRReceiver, MailboxBoundaryReceiver

public class Mailbox
extends AbstractReceiver

A token holder with capacity one.

Since:
Ptolemy II 0.2
Version:
$Id: Mailbox.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Jie Liu, Edward A. Lee, Lukito Muliadi
Accepted Rating:
Green (neuendor)
Proposed Rating:
Green (eal)

Field Summary
protected  Token _token
          The token held.
 
Constructor Summary
Mailbox()
          Construct an empty Mailbox with no container.
Mailbox(IOPort container)
          Construct an empty Mailbox with the specified container.
 
Method Summary
 void clear()
          Clear this receiver of any contained token.
 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.
 boolean hasRoom()
          Return true if this mailbox is empty.
 boolean hasRoom(int numberOfTokens)
          Return true if the argument is 1 and the mailbox is empty, 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 mailbox is not empty, and otherwise return false.
 void put(Token token)
          Put a token into the mailbox.
 
Methods inherited from class ptolemy.actor.AbstractReceiver
getArray, getContainer, getCurrentTime, getModelTime, isKnown, putArray, putArrayToAll, putToAll, reset, setContainer, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_token

protected Token _token
The token held.

Constructor Detail

Mailbox

public Mailbox()
Construct an empty Mailbox with no container.


Mailbox

public Mailbox(IOPort container)
        throws IllegalActionException
Construct an empty Mailbox with the specified container.

Parameters:
container - The container.
Throws:
IllegalActionException - If the container does not accept this receiver.
Method Detail

clear

public void clear()
           throws IllegalActionException
Clear this receiver of any contained token.

Specified by:
clear in interface Receiver
Overrides:
clear in class AbstractReceiver
Throws:
IllegalActionException - If a derived class throws it (not thrown in this base class).

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.

get

public Token get()
          throws NoTokenException
Get the contained Token. If there is none, throw an exception. The token is removed.

Specified by:
get in interface Receiver
Specified by:
get in class AbstractReceiver
Returns:
The token contained by this mailbox.
Throws:
NoTokenException - If this mailbox is empty.

hasRoom

public boolean hasRoom()
Return true if this mailbox is empty.

Specified by:
hasRoom in interface Receiver
Specified by:
hasRoom in class AbstractReceiver
Returns:
True if this mailbox is empty.

hasRoom

public boolean hasRoom(int numberOfTokens)
                throws java.lang.IllegalArgumentException
Return true if the argument is 1 and the mailbox is empty, 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 mailbox.
Returns:
True if the argument is 1 and the mailbox is empty, 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()
Return true if this mailbox is not empty.

Specified by:
hasToken in interface Receiver
Specified by:
hasToken in class AbstractReceiver
Returns:
True if this mailbox is not empty.

hasToken

public boolean hasToken(int numberOfTokens)
                 throws java.lang.IllegalArgumentException
Return true if the argument is 1 and this mailbox 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 mailbox is not empty.
Throws:
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 the mailbox. If the argument is null, then the mailbox will not contain a token after this returns.

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.