Package ptolemy.data
Class UnionToken
- java.lang.Object
-
- ptolemy.data.Token
-
- ptolemy.data.AbstractNotConvertibleToken
-
- ptolemy.data.UnionToken
-
public class UnionToken extends AbstractNotConvertibleToken
A token that contains a label/token pairs. This pair is one of the choices in a union type, but the exact type is not stored in this class. Operations on union tokens may require that they have the same field in among the possible choices.- Since:
- Ptolemy II 5.2
- Version:
- $Id$
- Author:
- Yuhong Xiong, Steve Neuendorffer, Elaine Cheong, Edward Lee
- Pt.AcceptedRating:
- Red (cxh)
- Pt.ProposedRating:
- Red (yuhong)
-
-
Constructor Summary
Constructors Constructor Description UnionToken(java.lang.String init)
Construct a UnionToken from the specified string.UnionToken(java.lang.String label, Token value)
Construct a UnionToken with the specified label and value.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Token
_add(Token rightArgument)
Return a new token whose value is the sum of this token and the argument.protected Token
_divide(Token rightArgument)
Return a new token whose value is the division of this token and the argument.protected BooleanToken
_isCloseTo(Token rightArgument, double epsilon)
Test whether the value of this token is close to the first argument, where "close" means that the distance between them is less than or equal to the second argument.protected BooleanToken
_isEqualTo(Token rightArgument)
Return true if the specified token is equal to this one.protected Token
_modulo(Token rightArgument)
Return a new token whose value is the modulo of this token and the argument.protected Token
_multiply(Token rightArgument)
Return a new token whose value is the multiplication of this token and the argument.protected Token
_subtract(Token rightArgument)
Return a new token whose value is the subtraction of this token and the argument.boolean
equals(java.lang.Object object)
Return true if the argument is an UnionToken with the same label and value.Type
getType()
Return the type of this token.int
hashCode()
Return a hash code value for this token.java.lang.String
label()
Return the label of this token.Token
one()
Returns a new UnionToken representing the multiplicative identity.java.lang.String
toString()
Return the value of this token as a string.Token
value()
Return the value of this token.Token
zero()
Returns a new UnionToken representing the additive identity.-
Methods inherited from class ptolemy.data.AbstractNotConvertibleToken
add, addReverse, divide, divideReverse, isCloseTo, isEqualTo, modulo, moduloReverse, multiply, multiplyReverse, notSupportedDifferentClassesMessage, subtract, subtractReverse
-
Methods inherited from class ptolemy.data.Token
isCloseTo, isNil, notSupportedConversionMessage, notSupportedIncomparableConversionMessage, notSupportedIncomparableMessage, notSupportedMessage, notSupportedNullNilStringMessage, pow, zeroReturnType
-
-
-
-
Constructor Detail
-
UnionToken
public UnionToken(java.lang.String label, Token value) throws IllegalActionException
Construct a UnionToken with the specified label and value.- Parameters:
label
- The label.value
- The value of this token.- Throws:
IllegalActionException
- If the label or the value is null.
-
UnionToken
public UnionToken(java.lang.String init) throws IllegalActionException
Construct a UnionToken from the specified string.- Parameters:
init
- A string expression of a record.- Throws:
IllegalActionException
- If the string does not contain a parsable record.
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object object)
Return true if the argument is an UnionToken with the same label and value.- Overrides:
equals
in classjava.lang.Object
- Parameters:
object
- An instance of Object.- Returns:
- True if the argument is equal to this token.
- See Also:
hashCode()
-
getType
public Type getType()
Return the type of this token.
-
hashCode
public int hashCode()
Return a hash code value for this token. This method returns the hash codes of the value token.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- A hash code value for this token.
-
label
public java.lang.String label()
Return the label of this token.- Returns:
- The label of this token.
-
one
public Token one() throws IllegalActionException
Returns a new UnionToken representing the multiplicative identity. The returned token has the same label as this one, and contains the multiplicative identity of the value of this token.- Overrides:
one
in classToken
- Returns:
- A UnionToken.
- Throws:
IllegalActionException
- If multiplicative identity is not supported by any value token.
-
toString
public java.lang.String toString()
Return the value of this token as a string. The syntax is{|label = value|}
-
value
public Token value()
Return the value of this token.- Returns:
- The value of this token.
-
zero
public Token zero() throws IllegalActionException
Returns a new UnionToken representing the additive identity. The returned token has the same label as this one, and contains the additive identity of the value token.- Overrides:
zero
in classToken
- Returns:
- A UnionToken.
- Throws:
IllegalActionException
- If additive identity is not supported by any value token.
-
_add
protected Token _add(Token rightArgument) throws IllegalActionException
Return a new token whose value is the sum of this token and the argument. It is assumed that the class of the argument is UnionToken.- Specified by:
_add
in classAbstractNotConvertibleToken
- Parameters:
rightArgument
- The token to add to this token.- Returns:
- A new UnionToken.
- Throws:
IllegalActionException
- If the label of the argument and this token are different, or calling the add method on the value token throws it.
-
_divide
protected Token _divide(Token rightArgument) throws IllegalActionException
Return a new token whose value is the division of this token and the argument. It is assumed that the class of the argument is UnionToken.- Specified by:
_divide
in classAbstractNotConvertibleToken
- Parameters:
rightArgument
- The token to divide this token by.- Returns:
- A new UnionToken.
- Throws:
IllegalActionException
- If the label of the argument and this token are different, or calling the divide method on the value token throws it.
-
_isCloseTo
protected BooleanToken _isCloseTo(Token rightArgument, double epsilon) throws IllegalActionException
Test whether the value of this token is close to the first argument, where "close" means that the distance between them is less than or equal to the second argument. This method only makes sense for tokens where the distance between them is reasonably represented as a double. It is assumed that the argument is an UnionToken, and the isCloseTo() method of the fields is used. If the fields do not match, then the return value is false.- Specified by:
_isCloseTo
in classAbstractNotConvertibleToken
- Parameters:
rightArgument
- The token to compare to this token.epsilon
- The value that we use to determine whether two tokens are close.- Returns:
- A token containing true if the value of the first argument is close to the value of this token.
- Throws:
IllegalActionException
- If thrown by calling isCloseTo() on the value of this Token.
-
_isEqualTo
protected BooleanToken _isEqualTo(Token rightArgument) throws IllegalActionException
Return true if the specified token is equal to this one. Equal means that both tokens have the same label with the same value. This method is different from equals() in that _isEqualTo() looks for equalities of values irrespective of their types. It is assumed that the type of the argument is UnionToken.- Overrides:
_isEqualTo
in classAbstractNotConvertibleToken
- Parameters:
rightArgument
- The token to compare to this token.- Returns:
- True if the argument is equal to this.
- Throws:
IllegalActionException
- If this method is not supported by the derived class.
-
_modulo
protected Token _modulo(Token rightArgument) throws IllegalActionException
Return a new token whose value is the modulo of this token and the argument. It is assumed that the class of the argument is UnionToken.- Specified by:
_modulo
in classAbstractNotConvertibleToken
- Parameters:
rightArgument
- The token to modulo this token by.- Returns:
- A new UnionToken.
- Throws:
IllegalActionException
- If the label of the argument and this token are different, or calling the modulo method on the value token throws it.
-
_multiply
protected Token _multiply(Token rightArgument) throws IllegalActionException
Return a new token whose value is the multiplication of this token and the argument. It is assumed that the class of the argument is UnionToken.- Specified by:
_multiply
in classAbstractNotConvertibleToken
- Parameters:
rightArgument
- The token to multiply this token by.- Returns:
- A new UnionToken.
- Throws:
IllegalActionException
- If the label of the argument and this token are different, or calling the multiply method on the value token throws it.
-
_subtract
protected Token _subtract(Token rightArgument) throws IllegalActionException
Return a new token whose value is the subtraction of this token and the argument. It is assumed that the class of the argument is UnionToken.- Specified by:
_subtract
in classAbstractNotConvertibleToken
- Parameters:
rightArgument
- The token to subtract from this token.- Returns:
- A new UnionToken.
- Throws:
IllegalActionException
- If the label of the argument and this token are different, or calling the subtract method on the value token throws it.
-
-