ptolemy.data
Class ObjectToken

java.lang.Object
  extended by ptolemy.data.Token
      extended by ptolemy.data.ObjectToken
All Implemented Interfaces:
java.io.Serializable

public class ObjectToken
extends Token

A token that contains a reference to an arbitrary object. Note that when this token constructed, the object passed to the constructor is not cloned. Thus, care must be exercised to ensure that actors do not modify that object in a nondeterministic way, unless such nondeterminism is acceptable.

Since:
Ptolemy II 0.2
Version:
$Id: ObjectToken.java,v 1.57 2006/08/21 23:13:25 cxh Exp $
Author:
Edward A. Lee
See Also:
Serialized Form
Accepted Rating:
Yellow (wbwu)
Proposed Rating:
Yellow (yuhong)

Field Summary
protected  java.lang.Object _value
          The actual Object.
 
Fields inherited from class ptolemy.data.Token
NIL
 
Constructor Summary
ObjectToken()
          Construct an empty token.
ObjectToken(java.lang.Object value)
          Construct a token with a reference to the specified object.
 
Method Summary
static ObjectToken convert(Token token)
          Convert the specified token into an instance of ObjectToken.
 boolean equals(java.lang.Object object)
          Return true if the argument is an instance of ObjectToken and its contained object is equal to the object contained in this token, as tested by the equals() method of the contained object.
 Type getType()
          Return the type of this token.
 java.lang.Object getValue()
          Return the value of the token, a reference to an object.
 int hashCode()
          Return a hash code value for this token.
 java.lang.String toString()
          Return the value of this token as a string that can be parsed by the expression language to recover a token with the same value.
 
Methods inherited from class ptolemy.data.Token
add, addReverse, divide, divideReverse, isCloseTo, isCloseTo, isEqualTo, isNil, modulo, moduloReverse, multiply, multiplyReverse, notSupportedConversionMessage, notSupportedIncomparableConversionMessage, notSupportedIncomparableMessage, notSupportedMessage, notSupportedNullNilStringMessage, one, pow, subtract, subtractReverse, zero, zeroReturnType
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_value

protected java.lang.Object _value
The actual Object. This is protected to allow access in derived classes only.

Constructor Detail

ObjectToken

public ObjectToken()
Construct an empty token.


ObjectToken

public ObjectToken(java.lang.Object value)
            throws IllegalActionException
Construct a token with a reference to the specified object.

Parameters:
value - The specified object referred to by this token.
Throws:
IllegalActionException - If the argument is not of the appropriate type (may be thrown by derived classes, but is not thrown here).
Method Detail

convert

public static ObjectToken convert(Token token)
                           throws IllegalActionException
Convert the specified token into an instance of ObjectToken. This method does lossless conversion. If the argument is already an instance of ObjectToken, it is returned without any change. Otherwise, if the argument is below ObjectToken in the type hierarchy, it is converted to an instance of ObjectToken or one of the subclasses of ObjectToken and returned. If none of the above condition is met, an exception is thrown.

Parameters:
token - The token to be converted to an ObjectToken.
Returns:
An ObjectToken.
Throws:
IllegalActionException - If the conversion cannot be carried out.

equals

public boolean equals(java.lang.Object object)
Return true if the argument is an instance of ObjectToken and its contained object is equal to the object contained in this token, as tested by the equals() method of the contained object.

Overrides:
equals in class java.lang.Object
Parameters:
object - An instance of Object.
Returns:
True if the argument is an instance of ObjectToken and its contained object is equal to the object contained in this token.

getType

public Type getType()
Return the type of this token.

Overrides:
getType in class Token
Returns:
BaseType.OBJECT

getValue

public java.lang.Object getValue()
Return the value of the token, a reference to an object.

Returns:
The Object in this token.

hashCode

public int hashCode()
Return a hash code value for this token. This method returns the hash code of the contained object.

Overrides:
hashCode in class java.lang.Object
Returns:
A hash code value for this token.

toString

public java.lang.String toString()
Return the value of this token as a string that can be parsed by the expression language to recover a token with the same value. The returned syntax looks like a function call to a one argument method named "object". The argument is the string representation of the contained object, or the string "null" if the object is null. Notice that this syntax is not currently parseable by the expression language.

Overrides:
toString in class Token
Returns:
A String representing the object.