public abstract class ScalarToken extends Token implements BitwiseOperationToken, PartiallyOrderedToken
This class has a number of protected abstract methods that subclasses must implement. These methods need only implement the numerical portion of the operation between two tokens of the same type. This base class will handle the conversion of tokens from different types to the same type before calling the protected method, and the proper computation of the units of the returned token afterwards.
In general, any instance of a scalar token may be optionally associated with a set of units. In the arithmetic methods add(), modulo(), and subtract(), the two operands must have the same units. Otherwise, an exception will be thrown. In the methods multiply() and divide(), the units of the resulting token will be computed automatically. IMPORTANT: The protected methods implemented in derived classes are expected to return a new token in the case of multiply and divide. This new token will automatically have its units set correctly by this base class implementation. Certain cases, such as multiplication by one, cannot be optimized to simply return an the input token without performing the multiplication, since the units of the result may be different than the units of either input token.
Green (yuhong) 
Green (neuendor) 
Modifier and Type  Field and Description 

protected int[] 
_unitCategoryExponents
The unit category exponents.

Constructor and Description 

ScalarToken() 
Modifier and Type  Method and Description 

protected abstract ScalarToken 
_absolute()
Return a ScalarToken containing the absolute value of the
value of this token.

protected abstract 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 int[] 
_addCategoryExponents(ScalarToken token)
Add the corresponding unit category exponents.

protected boolean 
_areUnitsEqual(ScalarToken scalarToken)
Return true if the units of this token are the same as that of the
argument token.

protected abstract ScalarToken 
_bitwiseAnd(ScalarToken rightArgument)
Returns a token representing the bitwise AND of this token and
the given token.

protected abstract ScalarToken 
_bitwiseNot()
Returns a token representing the bitwise NOT of this token.

protected abstract ScalarToken 
_bitwiseOr(ScalarToken rightArgument)
Returns a token representing the bitwise OR of this token and
the given token.

protected abstract ScalarToken 
_bitwiseXor(ScalarToken rightArgument)
Returns a token representing the bitwise XOR of this token and
the given token.

protected int[] 
_copyOfCategoryExponents()
Return a copy of the unit category exponents array.

protected abstract 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 abstract BooleanToken 
_isCloseTo(ScalarToken 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(ScalarToken token)
Test for equality of the values of this token and the argument.

protected abstract BooleanToken 
_isLessThan(ScalarToken rightArgument)
Test for ordering of the values of this Token and the argument
Token.

protected boolean 
_isUnitless()
Return true if this token does not have a unit.

protected abstract ScalarToken 
_modulo(ScalarToken rightArgument)
Return a new token whose value is the value of this token
modulo the value of the argument token.

protected abstract 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 abstract ScalarToken 
_subtract(ScalarToken rightArgument)
Return a new token whose value is the value of the argument
token subtracted from the value of this token.

protected int[] 
_subtractCategoryExponents(ScalarToken token)
Subtract the corresponding unit category exponents of the
argument token from that of this token.

ScalarToken 
absolute()
Return a ScalarToken containing the absolute value of the
value of this token.

Token 
add(Token rightArgument)
Return a new token whose value is the sum of this token and
the argument.

Token 
addReverse(Token leftArgument)
Return a new token whose value is the sum of this token and
the argument.

BitwiseOperationToken 
bitwiseAnd(Token rightArgument)
Returns a token representing the bitwise AND of this token and
the given token.

BitwiseOperationToken 
bitwiseNot()
Returns a token representing the bitwise NOT of this token.

BitwiseOperationToken 
bitwiseOr(Token rightArgument)
Returns a token representing the bitwise OR of this token and
the given token.

BitwiseOperationToken 
bitwiseXor(Token rightArgument)
Returns a token representing the bitwise XOR of this token and
the given token.

byte 
byteValue()
Return the value in the token as a byte.

Complex 
complexValue()
Return the value of this token as a Complex.

Token 
divide(Token rightArgument)
Return a new token whose value is the value of this token
divided by the value of the argument token.

Token 
divideReverse(Token leftArgument)
Return a new token whose value is the value of this token
divided into the value of the argument token.

double 
doubleValue()
Return the value of this token as a double.

FixPoint 
fixValue()
Return the value of this token as a FixPoint.

float 
floatValue()
Return the value of this token as a float
In this base class, we just throw an exception.

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

int 
intValue()
Return the value of this token as an int.

ScalarToken 
inUnitsOf(ScalarToken units)
Return a scalar token that contains the value of this token in the
units of the argument token.

BooleanToken 
isCloseTo(Token rightArgument,
double epsilon)
Test whether the value of this Token is close to the argument
Token.

BooleanToken 
isEqualTo(Token rightArgument)
Test for equality of the values of this Token and the argument
Token.

BooleanToken 
isGreaterThan(ScalarToken rightArgument)
Check whether the value of this token is strictly greater than
that of the argument token.

BooleanToken 
isLessThan(PartiallyOrderedToken rightArgument)
Check whether the value of this token is strictly less than that of the
argument token.

BooleanToken 
isLessThan(ScalarToken rightArgument)
Check whether the value of this token is strictly less than that of the
argument token.

ScalarToken 
leftShift(int bits)
Returns a token representing the result of shifting the bits
of this token towards the most significant bit, filling the
least significant bits with zeros.

ScalarToken 
logicalRightShift(int bits)
Returns a token representing the result of shifting the bits
of this token towards the least significant bit, filling the
most significant bits with zeros.

long 
longValue()
Return the value of this token as a long integer.

Token 
modulo(Token rightArgument)
Return a new token whose value is the value of this token
modulo the value of the argument token.

Token 
moduloReverse(Token leftArgument)
Return a new token whose value is the value of this token
modulo the value of the argument token.

Token 
multiply(Token rightArgument)
Return a new token whose value is the value of this token
multiplied by the value of the argument token.

Token 
multiplyReverse(Token leftArgument)
Return a new token whose value is the value of this token
multiplied by the value of the argument token.

ScalarToken 
rightShift(int bits)
Returns a token representing the result of shifting the bits
of this token towards the least significant bit, filling the
most significant bits with the sign of the value.

void 
setUnitCategory(int index)
Deprecated.
We need a better way of manufacturing the tokens
for base units, since this method violates the immutability of
tokens.

short 
shortValue()
Return the value of this token as a short.

Token 
subtract(Token rightArgument)
Return a new token whose value is the value of the argument
token subtracted from the value of this token.

Token 
subtractReverse(Token leftArgument)
Return a new token whose value is the value of the argument
token subtracted from the value of this token.

java.lang.String 
unitsString()
Return the string representation of the units of this token.

isCloseTo, isNil, notSupportedConversionMessage, notSupportedIncomparableConversionMessage, notSupportedIncomparableMessage, notSupportedMessage, notSupportedNullNilStringMessage, one, pow, toString, zero, zeroReturnType
protected int[] _unitCategoryExponents
public final ScalarToken absolute()
Token.NIL
is returned.public final Token add(Token rightArgument) throws IllegalActionException
add
in class Token
rightArgument
 The token to add to this token.IllegalActionException
 If the argument token and
this token are of incomparable types, or have different units,
or the operation does not make sense for the given types.public final Token addReverse(Token leftArgument) throws IllegalActionException
addReverse
in class Token
leftArgument
 The token to add this token to.IllegalActionException
 If the argument token and
this token are of incomparable types, or have different units,
or the operation does not make sense for the given types.public BitwiseOperationToken bitwiseAnd(Token rightArgument) throws IllegalActionException
bitwiseAnd
in interface BitwiseOperationToken
rightArgument
 The ScalarToken to bitwise AND with this one.IllegalActionException
 If the given token is not
compatible for this operation, or the operation does not make
sense for this type.public BitwiseOperationToken bitwiseNot() throws IllegalActionException
bitwiseNot
in interface BitwiseOperationToken
IllegalActionException
 If the given token is not
compatible for this operation, or the operation does not make
sense for this type.public BitwiseOperationToken bitwiseOr(Token rightArgument) throws IllegalActionException
bitwiseOr
in interface BitwiseOperationToken
rightArgument
 The ScalarToken to bitwise OR with this one.IllegalActionException
 If the given token is not
compatible for this operation, or the operation does not make
sense for this type.public BitwiseOperationToken bitwiseXor(Token rightArgument) throws IllegalActionException
bitwiseXor
in interface BitwiseOperationToken
rightArgument
 The ScalarToken to bitwise XOR with this one.IllegalActionException
 If the given token is not
compatible for this operation, or the operation does not make
sense for this type.public byte byteValue() throws IllegalActionException
IllegalActionException
 Always thrown.public Complex complexValue() throws IllegalActionException
IllegalActionException
 Always thrown.public final Token divide(Token rightArgument) throws IllegalActionException
divide
in class Token
rightArgument
 The token to divide into this token.IllegalActionException
 If the argument token and
this token are of incomparable types, or the operation does
not make sense for the given types.public final Token divideReverse(Token leftArgument) throws IllegalActionException
divideReverse
in class Token
leftArgument
 The token to be divided into the value of
this token.IllegalActionException
 If the argument token and
this token are of incomparable types, or the operation does
not make sense for the given types.public double doubleValue() throws IllegalActionException
IllegalActionException
 Always thrownpublic FixPoint fixValue() throws IllegalActionException
IllegalActionException
 Always thrown.public float floatValue() throws IllegalActionException
IllegalActionException
 Always thrownpublic abstract Type getType()
public ScalarToken inUnitsOf(ScalarToken units) throws IllegalActionException
units
 A scalar token that represents a unit.IllegalActionException
 If the unit category of the
argument token is not the same as that of this one.public int intValue() throws IllegalActionException
IllegalActionException
 Always thrown.public final BooleanToken isCloseTo(Token rightArgument, double epsilon) throws IllegalActionException
isCloseTo
in class Token
rightArgument
 The token to test closeness of this token with.epsilon
 The value that we use to determine whether two
tokens are close.IllegalActionException
 If the argument token is not
of a type that can be compared with this token, or the units
are not the same.isEqualTo(ptolemy.data.Token)
public final BooleanToken isEqualTo(Token rightArgument) throws IllegalActionException
isEqualTo
in class Token
rightArgument
 The token with which to test equality.IllegalActionException
 If this method is not
supported by the derived class.isCloseTo(ptolemy.data.Token, double)
public final BooleanToken isGreaterThan(ScalarToken rightArgument) throws IllegalActionException
rightArgument
 The token to compare against.IllegalActionException
 If the argument token and
this token are of incomparable types, or have different units,
or the operation does not make sense for the given types.public final BooleanToken isLessThan(PartiallyOrderedToken rightArgument) throws IllegalActionException
isLessThan
in interface PartiallyOrderedToken
rightArgument
 The token to compare against.IllegalActionException
 If the argument token and
this token are of incomparable types, or have different units,
or the operation does not make sense for the given types.public final BooleanToken isLessThan(ScalarToken rightArgument) throws IllegalActionException
rightArgument
 The token to compare against.IllegalActionException
 If the argument token and
this token are of incomparable types, or have different units,
or the operation does not make sense for the given types.public ScalarToken leftShift(int bits) throws IllegalActionException
bits
 The number of bits to shift.IllegalActionException
 If the given token is not
compatible for this operation, or the operation does not make
sense for this type.public ScalarToken logicalRightShift(int bits) throws IllegalActionException
bits
 The number of bits to shift.IllegalActionException
 If the given token is not
compatible for this operation, or the operation does not make
sense for this type.public long longValue() throws IllegalActionException
IllegalActionException
 Always thrown.public final Token modulo(Token rightArgument) throws IllegalActionException
modulo
in class Token
rightArgument
 The token to modulo with this token.IllegalActionException
 If the argument token and
this token are of incomparable types, or have different units,
or the operation does not make sense for the given types.public final Token moduloReverse(Token leftArgument) throws IllegalActionException
moduloReverse
in class Token
leftArgument
 The token to apply modulo to by the value
of this token.IllegalActionException
 If the argument token and
this token are of incomparable types, or have different units,
or the operation does not make sense for the given types.public final Token multiply(Token rightArgument) throws IllegalActionException
multiply
in class Token
rightArgument
 The token to multiply this token by.IllegalActionException
 If the argument token and
this token are of incomparable types, or the operation does
not make sense for the given types.public final Token multiplyReverse(Token leftArgument) throws IllegalActionException
multiplyReverse
in class Token
leftArgument
 The token to be multiplied by the value of
this token.IllegalActionException
 If the argument token and
this token are of incomparable types, or the operation does
not make sense for the given types.public ScalarToken rightShift(int bits) throws IllegalActionException
bits
 The number of bits to shift.IllegalActionException
 If the given token is not
compatible for this operation, or the operation does not make
sense for this type.@Deprecated public void setUnitCategory(int index)
index
 The unit category index.public short shortValue() throws IllegalActionException
IllegalActionException
 Always thrownpublic final Token subtract(Token rightArgument) throws IllegalActionException
subtract
in class Token
rightArgument
 The token to subtract from this token.IllegalActionException
 If the argument token and
this token are of incomparable types, or have different units,
or the operation does not make sense for the given types.public final Token subtractReverse(Token leftArgument) throws IllegalActionException
subtractReverse
in class Token
leftArgument
 The token to subtract this token from.IllegalActionException
 If the argument token and
this token are of incomparable types, or have different units,
or the operation does not make sense for the given types.public java.lang.String unitsString()
protected abstract ScalarToken _absolute()
protected abstract ScalarToken _add(ScalarToken rightArgument) throws IllegalActionException
rightArgument
 The token to add to this token.IllegalActionException
 If this method is not
supported by the derived class.protected int[] _addCategoryExponents(ScalarToken token)
token
 A token whose exponent will be added with the
exponents of this token.protected boolean _areUnitsEqual(ScalarToken scalarToken)
scalarToken
 A scalar token.protected abstract ScalarToken _bitwiseAnd(ScalarToken rightArgument) throws IllegalActionException
rightArgument
 The ScalarToken to bitwise AND with this one.IllegalActionException
 If the given token is not
compatible for this operation, or the operation does not make
sense for this type.protected abstract ScalarToken _bitwiseNot() throws IllegalActionException
IllegalActionException
 If the given token is not
compatible for this operation, or the operation does not make
sense for this type.protected abstract ScalarToken _bitwiseOr(ScalarToken rightArgument) throws IllegalActionException
rightArgument
 The ScalarToken to bitwise OR with this one.IllegalActionException
 If the given token is not
compatible for this operation, or the operation does not make
sense for this type.protected abstract ScalarToken _bitwiseXor(ScalarToken rightArgument) throws IllegalActionException
rightArgument
 The ScalarToken to bitwise XOR with this one.IllegalActionException
 If the given token is not
compatible for this operation, or the operation does not make
sense for this type.protected int[] _copyOfCategoryExponents()
protected abstract ScalarToken _divide(ScalarToken rightArgument) throws IllegalActionException
rightArgument
 The token to divide this token by.IllegalActionException
 If this method is not
supported by the derived class.protected abstract BooleanToken _isCloseTo(ScalarToken rightArgument, double epsilon) throws IllegalActionException
rightArgument
 The token to compare to this token.epsilon
 The value that we use to determine whether two
tokens are close.IllegalActionException
 If there is a problem processing
the rightArgument.protected BooleanToken _isEqualTo(ScalarToken token) throws IllegalActionException
token
 The token to compare to this token.IllegalActionException
 Not thrown in this base class.protected abstract BooleanToken _isLessThan(ScalarToken rightArgument) throws IllegalActionException
rightArgument
 The token to add to this token.IllegalActionException
 If this method is not
supported by the derived class.protected boolean _isUnitless()
protected abstract ScalarToken _modulo(ScalarToken rightArgument) throws IllegalActionException
rightArgument
 The token to modulo this token by.IllegalActionException
 If this method is not
supported by the derived class.protected abstract ScalarToken _multiply(ScalarToken rightArgument) throws IllegalActionException
rightArgument
 The token to multiply this token by.IllegalActionException
 If this method is not
supported by the derived class.protected abstract ScalarToken _subtract(ScalarToken rightArgument) throws IllegalActionException
rightArgument
 The token to subtract from this token.IllegalActionException
 If this method is not
supported by the derived class.protected int[] _subtractCategoryExponents(ScalarToken token)
token
 A token whose exponent will be subtracted from
the exponents of this token.