ptolemy.data
Class ComplexToken

java.lang.Object
  extended by ptolemy.data.Token
      extended by ptolemy.data.ScalarToken
          extended by ptolemy.data.ComplexToken
All Implemented Interfaces:
java.io.Serializable, BitwiseOperationToken

public class ComplexToken
extends ScalarToken

A token that contains a Complex number represented by a 64-bit double-precision floating point real and imaginary parts.

Since:
Ptolemy II 0.2
Version:
$Id: ComplexToken.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Yuhong Xiong, Neil Smyth, Christopher Hylands, Steve Neuendorffer
See Also:
Token, Complex, Serialized Form
Accepted Rating:
Green (cxh)
Proposed Rating:
Green (neuendor)

Field Summary
private  Complex _value
           
static ComplexToken NIL
          A token that represents a missing value.
 
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
protected  ScalarToken _absolute()
          Return a ScalarToken containing the absolute value of the value of this token.
protected  ScalarToken _add(ScalarToken rightArgument)
          Return a new token whose value is the value of the argument Token added to the value of this Token.
protected  ScalarToken _bitwiseAnd(ScalarToken rightArgument)
          Throw an exception because bitwise AND is not supported.
protected  ScalarToken _bitwiseNot()
          Throw an exception because bitwise NOT is not supported.
protected  ScalarToken _bitwiseOr(ScalarToken rightArgument)
          Throw an exception because bitwise OR is not supported.
protected  ScalarToken _bitwiseXor(ScalarToken rightArgument)
          Throw an exception because bitwise XOR is not supported.
protected  ScalarToken _divide(ScalarToken rightArgument)
          Return a new token whose value is the value of this token divided by the value of the argument token.
protected  BooleanToken _isCloseTo(ScalarToken rightArgument, double epsilon)
          Test that the value of this rightArgument is close to the first argument, where "close" means that the distance between their values is less than or equal to the second argument.
protected  BooleanToken _isLessThan(ScalarToken rightArgument)
          Throw an exception because complex values cannot be compared.
protected  ScalarToken _modulo(ScalarToken rightArgument)
          Throw an exception because the modulo operation does not make sense for complex values.
protected  ScalarToken _multiply(ScalarToken rightArgument)
          Return a new token whose value is the value of this token multiplied by the value of the argument token.
protected  ScalarToken _subtract(ScalarToken rightArgument)
          Return a new token whose value is the value of the argument token subtracted from the value of this token.
 Complex complexValue()
          Return the value of this token as a Complex.
static ComplexToken convert(Token token)
          Convert the specified token into an instance of ComplexToken.
 boolean equals(java.lang.Object object)
          Return true if the argument's class is IntToken and it has the same values as this token.
 Type getType()
          Return the type of this token.
 int hashCode()
          Return a hash code value for this token.
 boolean isNil()
          Return true if the token is nil, (aka null or missing).
 Token one()
          Returns a new ComplexToken with value 1.0.
 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, _isEqualTo, _isUnitless, _subtractCategoryExponents, absolute, add, addReverse, bitwiseAnd, bitwiseNot, bitwiseOr, bitwiseXor, byteValue, divide, divideReverse, doubleValue, fixValue, floatValue, intValue, inUnitsOf, isCloseTo, isEqualTo, isGreaterThan, isLessThan, leftShift, logicalRightShift, longValue, modulo, moduloReverse, multiply, multiplyReverse, rightShift, setUnitCategory, shortValue, subtract, subtractReverse, unitsString
 
Methods inherited from class ptolemy.data.Token
isCloseTo, notSupportedConversionMessage, notSupportedIncomparableConversionMessage, notSupportedIncomparableMessage, notSupportedMessage, notSupportedNullNilStringMessage, pow, zeroReturnType
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

NIL

public static final ComplexToken NIL
A token that represents a missing value. Null or missing tokens are common in analytical systems like R and SAS where they are used to handle sparsely populated data sources. In database parlance, missing tokens are sometimes called null tokens. Since null is a Java keyword, we use the term "nil". The toString() method on a nil token returns the string "nil".


_value

private Complex _value
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.

Parameters:
value - The specified value.

ComplexToken

public ComplexToken(java.lang.String init)
             throws IllegalActionException
Construct a ComplexToken from the specified string.

Parameters:
init - The initialization string, of the format real+imaginaryi, for example 1.0+2.0i.
Throws:
IllegalActionException - If the string does not represent a parsable complex number.
Method Detail

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 ComplexToken convert(Token token)
                            throws IllegalActionException
Convert the specified token into an instance of ComplexToken. This method does lossless conversion. The units of the returned token will be the same as the units of the given token. 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.

equals

public boolean equals(java.lang.Object object)
Return true if the argument's class is IntToken and it has the same values as this token.

Overrides:
equals in class java.lang.Object
Parameters:
object - An instance of Object.
Returns:
True if the argument is a ComplexToken with the same value.

isNil

public boolean isNil()
Return true if the token is nil, (aka null or missing). Nil or missing tokens occur when a data source is sparsely populated.

Overrides:
isNil in class Token
Returns:
True if the token is the NIL token.

getType

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

Specified by:
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 java.lang.Object
Returns:
A hash code value for this token.

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.

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.

_absolute

protected ScalarToken _absolute()
Return a ScalarToken containing the absolute value of the value of this token. If this token contains a non-negative number, it is returned directly; otherwise, a new token is is return. Note that it is explicitly allowable to return this token, since the units are the same.

Specified by:
_absolute in class ScalarToken
Returns:
A DoubleToken.

_add

protected ScalarToken _add(ScalarToken rightArgument)
Return a new token whose value is the value of the argument Token added to the value of this Token. It is assumed that the type of the argument is an ComplexToken.

Specified by:
_add in class ScalarToken
Parameters:
rightArgument - The token to add to this token.
Returns:
A new ComplexToken containing the result.

_bitwiseAnd

protected ScalarToken _bitwiseAnd(ScalarToken rightArgument)
                           throws IllegalActionException
Throw an exception because bitwise AND is not supported.

Specified by:
_bitwiseAnd in class ScalarToken
Parameters:
rightArgument - The ComplexToken to bitwise AND with this one.
Returns:
An exception.
Throws:
IllegalActionException - Always thrown.

_bitwiseNot

protected ScalarToken _bitwiseNot()
                           throws IllegalActionException
Throw an exception because bitwise NOT is not supported.

Specified by:
_bitwiseNot in class ScalarToken
Returns:
An exception.
Throws:
IllegalActionException - Always thrown.

_bitwiseOr

protected ScalarToken _bitwiseOr(ScalarToken rightArgument)
                          throws IllegalActionException
Throw an exception because bitwise OR is not supported.

Specified by:
_bitwiseOr in class ScalarToken
Parameters:
rightArgument - The ComplexToken to bitwise OR with this one.
Returns:
An exception.
Throws:
IllegalActionException - Always thrown.

_bitwiseXor

protected ScalarToken _bitwiseXor(ScalarToken rightArgument)
                           throws IllegalActionException
Throw an exception because bitwise XOR is not supported.

Specified by:
_bitwiseXor in class ScalarToken
Parameters:
rightArgument - The ComplexToken to bitwise XOR with this one.
Returns:
An exception.
Throws:
IllegalActionException - Always thrown.

_divide

protected ScalarToken _divide(ScalarToken rightArgument)
                       throws IllegalActionException
Return a new token whose value is the value of this token divided by the value of the argument token. It is assumed that the type of the argument is an ComplexToken

Specified by:
_divide in class ScalarToken
Parameters:
rightArgument - The token to divide this token by.
Returns:
A new ComplexToken containing the result.
Throws:
IllegalActionException - Not thrown by this base class.

_isCloseTo

protected BooleanToken _isCloseTo(ScalarToken rightArgument,
                                  double epsilon)
Test that the value of this rightArgument is close to the first argument, where "close" means that the distance between their values is less than or equal to the second argument. It is assumed that the type of the argument is ComplexToken.

Specified by:
_isCloseTo in class ScalarToken
Parameters:
rightArgument - The rightArgument to compare to this rightArgument.
epsilon - The value that we use to determine whether two tokens are close.
Returns:
A true-valued rightArgument if the first argument is close in value to this rightArgument.

_isLessThan

protected BooleanToken _isLessThan(ScalarToken rightArgument)
                            throws IllegalActionException
Throw an exception because complex values cannot be compared.

Specified by:
_isLessThan in class ScalarToken
Parameters:
rightArgument - The token to compare to this token.
Returns:
An exception.
Throws:
IllegalActionException - Always thrown.

_modulo

protected ScalarToken _modulo(ScalarToken rightArgument)
                       throws IllegalActionException
Throw an exception because the modulo operation does not make sense for complex values.

Specified by:
_modulo in class ScalarToken
Parameters:
rightArgument - The token to modulo this token by.
Returns:
An exception.
Throws:
IllegalActionException - Always thrown.

_multiply

protected ScalarToken _multiply(ScalarToken rightArgument)
Return a new token whose value is the value of this token multiplied by the value of the argument token. It is assumed that the type of the argument is an ComplexToken.

Specified by:
_multiply in class ScalarToken
Parameters:
rightArgument - The token to multiply this token by.
Returns:
A new ComplexToken containing the result.

_subtract

protected ScalarToken _subtract(ScalarToken rightArgument)
Return a new token whose value is the value of the argument token subtracted from the value of this token. It is assumed that the type of the argument is an ComplexToken.

Specified by:
_subtract in class ScalarToken
Parameters:
rightArgument - The token to subtract from this token.
Returns:
A new ComplexToken containing the result.