ptolemy.data
Class ComplexToken

java.lang.Object
  |
  +--ptolemy.data.Token
        |
        +--ptolemy.data.ScalarToken
              |
              +--ptolemy.data.ComplexToken
All Implemented Interfaces:
java.io.Serializable

public class ComplexToken
extends ScalarToken

A token that contains a Complex.

Since:
Ptolemy II 0.2
Version:
$Id: ComplexToken.java,v 1.47 2002/02/21 18:03:34 cxh Exp $
Author:
Yuhong Xiong, Neil Smyth, Christopher Hylands
See Also:
Token, Complex, Serialized Form

Fields inherited from class ptolemy.data.ScalarToken
_unitCategoryExponents
 
Constructor Summary
ComplexToken()
          Construct a ComplexToken with Complex 0.0+0.0i
ComplexToken(Complex value)
          Construct a ComplexToken with the specified value.
ComplexToken(java.lang.String init)
          Construct a ComplexToken from the specified string.
 
Method Summary
 ScalarToken absolute()
          Return a DoubleToken containing the magnitude of the complex value of this token.
 Token add(Token token)
          Return a new token whose value is the sum of this token and the argument.
 Token addReverse(Token token)
          Return a new token whose value is the sum of this token and the argument.
 Complex complexValue()
          Return the value of this token as a Complex.
static Token convert(Token token)
          Convert the specified token into an instance of ComplexToken.
 Token divide(Token divisor)
          Return a new Token whose value is the value of this token divided by the value of the argument token.
 Token divideReverse(Token dividend)
          Return a new token whose value is the value of the argument token divided by the value of this token.
 boolean equals(java.lang.Object object)
          Return true if the argument is an instance of ComplexToken with the same value.
 Type getType()
          Return the type of this token.
 int hashCode()
          Return a hash code value for this token.
 BooleanToken isCloseTo(Token token)
          Test that the magnitude of this Token is close to the magnitude of the argument.
 BooleanToken isCloseTo(Token token, double epsilon)
          Test that the magnitude of this Token is close to the magnitude of the argument and that the units of this Token and the argument token are equal.
 BooleanToken isEqualTo(Token token)
          Test the values of this Token and the argument Token for equality.
 BooleanToken isLessThan(ScalarToken arg)
          Check if the value of this token is strictly less than that of the argument token.
 Token multiply(Token token)
          Return a new token whose value is the product of this token and the argument.
 Token multiplyReverse(Token token)
          Return a new token whose value is the product of this token and the argument.
 Token one()
          Returns a new ComplexToken with value 1.0.
 Token subtract(Token rightArgument)
          Return a new Token whose value is the value of the argument token subtracted by the value of this token.
 Token subtractReverse(Token leftArgument)
          Return a new token whose value is the value of this token subtracted from the value of the argument 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.
 Token zero()
          Returns a new ComplexToken with value Complex.ZERO.
 
Methods inherited from class ptolemy.data.ScalarToken
_addCategoryExponents, _areUnitsEqual, _copyOfCategoryExponents, _isUnitless, _subtractCategoryExponents, doubleValue, fixValue, intValue, inUnitsOf, longValue, setUnitCategory, unitsString
 
Methods inherited from class ptolemy.data.Token
_notSupportedMessage, modulo, moduloReverse
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ComplexToken

public ComplexToken()
Construct a ComplexToken with Complex 0.0+0.0i

ComplexToken

public ComplexToken(Complex value)
Construct a ComplexToken with the specified value.

ComplexToken

public ComplexToken(java.lang.String init)
             throws IllegalActionException
Construct a ComplexToken from the specified string.
Throws:
IllegalActionException - If the string does not represent a parsable complex number.
Method Detail

absolute

public ScalarToken absolute()
Return a DoubleToken containing the magnitude of the complex value of this token.
Overrides:
absolute in class ScalarToken
Returns:
A DoubleToken.

add

public Token add(Token token)
          throws IllegalActionException
Return a new token whose value is the sum of this token and the argument. The type of the specified token must be such that either it can be converted to the type of this token, or the type of this token can be converted to the type of the specified token, without loss of information. The type of the returned token is one of the above two types that allows lossless conversion from the other.
Overrides:
add in class Token
Parameters:
token - The token to add to this Token.
Returns:
A new Token containing the result.
Throws:
IllegalActionException - If the specified token is not of a type that can be added to this Tokens value.

addReverse

public Token addReverse(Token token)
                 throws IllegalActionException
Return a new token whose value is the sum of this token and the argument. The type of the specified token must be lower than ComplexToken.
Overrides:
addReverse in class Token
Parameters:
token - The token to add this Token to.
Returns:
A new Token containing the result.
Throws:
IllegalActionException - If the type of the specified token is not lower than ComplexToken.

complexValue

public Complex complexValue()
Return the value of this token as a Complex.
Overrides:
complexValue in class ScalarToken
Returns:
The value of this token as a Complex

convert

public static Token convert(Token token)
                     throws IllegalActionException
Convert the specified token into an instance of ComplexToken. This method does lossless conversion. If the argument is already an instance of ComplexToken, it is returned without any change. Otherwise, if the argument is below ComplexToken in the type hierarchy, it is converted to an instance of ComplexToken or one of the subclasses of ComplexToken and returned. If none of the above conditions are met, an exception is thrown.
Parameters:
token - The token to be converted to a ComplexToken.
Returns:
A ComplexToken.
Throws:
IllegalActionException - If the conversion cannot be carried out.

divide

public Token divide(Token divisor)
             throws IllegalActionException
Return a new Token whose value is the value of this token divided by the value of the argument token. The type of the specified token must be such that either it can be converted to the type of this token, or the type of this token can be converted to the type of the specified token, without loss of information. The type of the returned token is one of the above two types that allows lossless conversion from the other.
Overrides:
divide in class Token
Parameters:
divisor - The token to divide this Token by
Returns:
A new Token containing the result.
Throws:
IllegalActionException - If the passed token is not of a type that can divide this Tokens value by.

divideReverse

public Token divideReverse(Token dividend)
                    throws IllegalActionException
Return a new token whose value is the value of the argument token divided by the value of this token. The type of the specified token must be lower than ComplexToken.
Overrides:
divideReverse in class Token
Parameters:
dividend - The token to be divided by the value of this Token.
Returns:
A new token containing the result.
Throws:
IllegalActionException - If the type of the specified token is not lower than ComplexToken.

equals

public boolean equals(java.lang.Object object)
Return true if the argument is an instance of ComplexToken with the same value.
Overrides:
equals in class Token
Parameters:
object - An instance of Object.
Returns:
True if the argument is an instance of ComplexToken with the same value.

getType

public Type getType()
Return the type of this token.
Overrides:
getType in class ScalarToken
Returns:
BaseType.COMPLEX

hashCode

public int hashCode()
Return a hash code value for this token. This method returns the integer portion of the magnitude of the contained complex number.
Overrides:
hashCode in class Token
Returns:
A hash code value for this token.

isCloseTo

public BooleanToken isCloseTo(Token token)
                       throws IllegalActionException
Test that the magnitude of this Token is close to the magnitude of the argument. The value of the ptolemy.math.Complex epsilon field is used to determine whether the two Tokens are close.

If A and B are the values of the tokens, and if the following is true:

  absolute(A-B) < epsilon
  
and the units of A and B are equal, then A and B are considered close.
Overrides:
isCloseTo in class Token
Parameters:
token - The token to test closeness of this token with.
Returns:
a boolean token that contains the value true if the magnitude of this token is close to the magnitude of the argument token and the units of both tokens are equal.
Throws:
IllegalActionException - If the argument token is not of a type that can be compared with this token.
See Also:
Complex.epsilon, isEqualTo(ptolemy.data.Token), absolute()

isCloseTo

public BooleanToken isCloseTo(Token token,
                              double epsilon)
                       throws IllegalActionException
Test that the magnitude of this Token is close to the magnitude of the argument and that the units of this Token and the argument token are equal. The value of the ptolemy.math.Complex epsilon field is used to determine whether the two Tokens are close.

If A and B are the complex values of the tokens, and if the following is true:

  absolute(A-B) < epsilon
  
and the units of A and B are equal, then A and B are considered close.
Overrides:
isCloseTo in class Token
Parameters:
token - The token to test closeness of this token with.
epsilon - The value that we use to determine whether two tokens are close.
Returns:
a boolean token that contains the value true if the magnitude of this token is close to the magnitude of the argument token and the units of both tokens are equal.
Throws:
IllegalActionException - If the argument token is not of a type that can be compared with this token.
See Also:
isEqualTo(ptolemy.data.Token), absolute()

isEqualTo

public BooleanToken isEqualTo(Token token)
                       throws IllegalActionException
Test the values of this Token and the argument Token for equality. The type of the specified token must be such that either it can be converted to the type of this token, or the type of this token can be converted to the type of the specified token, without loss of information.
Overrides:
isEqualTo in class Token
Parameters:
token - The token to test equality of this token with.
Returns:
BooleanToken indicating whether the values are equal.
Throws:
IllegalActionException - If the specified token is not of a type that can be compared with this Token.
See Also:
isCloseTo(ptolemy.data.Token)

isLessThan

public BooleanToken isLessThan(ScalarToken arg)
                        throws IllegalActionException
Check if the value of this token is strictly less than that of the argument token. Mathematically, there is no "less than" relationship among complex numbers. So this method always throws an exception.
Overrides:
isLessThan in class ScalarToken
Parameters:
arg - A ScalarToken.
Returns:
A BooleanToken
Throws:
IllegalActionException - Always thrown.

multiply

public Token multiply(Token token)
               throws IllegalActionException
Return a new token whose value is the product of this token and the argument. The type of the specified token must be such that either it can be converted to the type of this token, or the type of this token can be converted to the type of the specified token, without loss of information. The type of the returned token is one of the above two types that allows lossless conversion from the other.
Overrides:
multiply in class Token
Parameters:
token - The token to multiply to this Token.
Returns:
A new Token containing the result.
Throws:
IllegalActionException - If the specified token is not of a type that can be multiplied to this Token.

multiplyReverse

public Token multiplyReverse(Token token)
                      throws IllegalActionException
Return a new token whose value is the product of this token and the argument. The type of the specified token must be lower than ComplexToken.
Overrides:
multiplyReverse in class Token
Parameters:
token - The token to multiply this Token to.
Returns:
A new Token containing the result.
Throws:
IllegalActionException - If the type of the specified token is not lower than ComplexToken.

one

public Token one()
Returns a new ComplexToken with value 1.0.
Overrides:
one in class Token
Returns:
A new ComplexToken with value 1.0.

subtract

public Token subtract(Token rightArgument)
               throws IllegalActionException
Return a new Token whose value is the value of the argument token subtracted by the value of this token. The type of the specified token must be such that either it can be converted to the type of this token, or the type of this token can be converted to the type of the specified token, without loss of information. The type of the returned token is one of the above two types that allows lossless conversion from the other.
Overrides:
subtract in class Token
Parameters:
rightArgument - The token to subtract this Token by.
Returns:
A new Token containing the result.
Throws:
IllegalActionException - If the specified token is not of a type that can be subtracted from this Token.

subtractReverse

public Token subtractReverse(Token leftArgument)
                      throws IllegalActionException
Return a new token whose value is the value of this token subtracted from the value of the argument token. The type of the specified token must be lower than ComplexToken.
Overrides:
subtractReverse in class Token
Parameters:
leftArgument - The token to subtract this token from.
Returns:
A new token containing the result.
Throws:
IllegalActionException - If the type of the specified token is not lower than ComplexToken;

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.
Overrides:
toString in class Token
Returns:
A String formed using java.lang.Complex.toString().

zero

public Token zero()
Returns a new ComplexToken with value Complex.ZERO.
Overrides:
zero in class Token
Returns:
A new ComplexToken with value Complex.ZERO.