public class FixedPointReceiver extends AbstractReceiver
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.
Yellow (eal) |
Green (hyzheng) |
Modifier and Type | Field and 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.
|
Constructor and Description |
---|
FixedPointReceiver()
Construct an FixedPointReceiver with unknown status.
|
FixedPointReceiver(FixedPointDirector director)
Construct an FixedPointReceiver with unknown status.
|
Modifier and Type | Method and 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.
|
getArray, getContainer, getCurrentTime, getModelTime, putArray, putArrayToAll, putToAll, toString
protected FixedPointDirector _director
protected boolean _known
protected Token _token
public FixedPointReceiver()
public FixedPointReceiver(FixedPointDirector director)
director
- The director of this receiver.public void clear() throws IllegalActionException
clear
in interface Receiver
clear
in class AbstractReceiver
IllegalActionException
- If this receiver is known and
present.public java.util.List<Token> elementList()
elementList
in interface Receiver
elementList
in class AbstractReceiver
public Token get() throws NoTokenException
get
in interface Receiver
get
in class AbstractReceiver
NoTokenException
- If there is no token.InvalidStateException
- If the status is unknown.public boolean hasRoom()
hasRoom
in interface Receiver
hasRoom
in class AbstractReceiver
isKnown()
public boolean hasRoom(int numberOfTokens) throws java.lang.IllegalArgumentException
hasRoom
in interface Receiver
hasRoom
in class AbstractReceiver
numberOfTokens
- The number of tokens to put into the receiver.java.lang.IllegalArgumentException
- If the argument is not positive.isKnown()
,
hasRoom()
public boolean hasToken()
hasToken
in interface Receiver
hasToken
in class AbstractReceiver
InvalidStateException
- If the status is unknown.public boolean hasToken(int numberOfTokens)
hasToken
in interface Receiver
hasToken
in class AbstractReceiver
numberOfTokens
- The number of tokens.java.lang.IllegalArgumentException
- If the argument is not positive.InvalidStateException
- If the status is unknown.hasToken()
public boolean isKnown()
isKnown
in interface Receiver
isKnown
in class AbstractReceiver
public void put(Token token) throws IllegalActionException
clear()
).put
in interface Receiver
put
in class AbstractReceiver
token
- The token to be put into this receiver.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.public void reset()
reset
in interface Receiver
reset
in class AbstractReceiver
public void setContainer(IOPort port) throws IllegalActionException
setContainer
in interface Receiver
setContainer
in class AbstractReceiver
port
- The container.IllegalActionException
- If the container is not of
an appropriate subclass of IOPort. Not thrown in this base class,
but may be thrown in derived classes.AbstractReceiver.getContainer()