Package ptolemy.data
Class ShortToken
- java.lang.Object
-
- ptolemy.data.Token
-
- ptolemy.data.ScalarToken
-
- ptolemy.data.ShortToken
-
- All Implemented Interfaces:
BitwiseOperationToken
,PartiallyOrderedToken
public class ShortToken extends ScalarToken
A token that contains a signed 16-bit integer number. Generally, this class handles overflow the same way that overflow Java native types are handled. In other words, overflow just past java.lang.Short.MAX_VALUE results in negative values close to java.lang.Short.MIN_VALUE.- Since:
- Ptolemy II 6.1
- Version:
- $Id$
- Author:
- Isaac Liu, based on IntToken by Neil Smyth, Yuhong Xiong, Steve Neuendorffer, contributor: Christopher Brooks
- Pt.AcceptedRating:
- Red (iliu)
- Pt.ProposedRating:
- Red (iliu)
-
-
Field Summary
Fields Modifier and Type Field Description static ShortToken
NIL
A token that represents a missing value.static ShortToken
ONE
A ShortToken with the value 1.0.static ShortToken
ZERO
A ShortToken with the value 0.0.-
Fields inherited from class ptolemy.data.ScalarToken
_unitCategoryExponents
-
-
Constructor Summary
Constructors Constructor Description ShortToken()
Construct a token with short 0.ShortToken(int value)
Construct a ShortToken with the specified integer value.ShortToken(short value)
Construct a token with the specified value.ShortToken(java.lang.String init)
Construct an ShortToken from the specified string.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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)
Returns a token representing the bitwise AND of this token and the given token.protected ScalarToken
_bitwiseNot()
Returns a token representing the bitwise NOT of this token.protected ScalarToken
_bitwiseOr(ScalarToken rightArgument)
Returns a token representing the bitwise OR of this token and the given token.protected ScalarToken
_bitwiseXor(ScalarToken rightArgument)
Returns a token representing the bitwise XOR of this token and the given token.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 whether the value of this token 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)
Test for ordering of the values of this Token and the argument Token.protected ScalarToken
_modulo(ScalarToken rightArgument)
Return a new token whose value is the value of this token modulo the value of the argument token.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 ShortToken
convert(Token token)
Convert the specified token into an instance of ShortToken.double
doubleValue()
Return the value in the token as a double.boolean
equals(java.lang.Object object)
Return true if the argument's class is ShortToken and it has the same values as this token.FixPoint
fixValue()
Return the value in the token as a fixpoint.float
floatValue()
Return the value in the token as a float.Type
getType()
Return the type of this token.int
hashCode()
Return a hash code value for this token.int
intValue()
Return the value in the token as an int.boolean
isNil()
Return true if the token is nil, (aka null or missing).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 in the token as a long.Token
one()
Returns an ShortToken with value 1.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.short
shortValue()
Return the value in the token as a short.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 an ShortToken with value 0.-
Methods inherited from class ptolemy.data.ScalarToken
_addCategoryExponents, _areUnitsEqual, _copyOfCategoryExponents, _isEqualTo, _isUnitless, _subtractCategoryExponents, absolute, add, addReverse, bitwiseAnd, bitwiseNot, bitwiseOr, bitwiseXor, byteValue, divide, divideReverse, inUnitsOf, isCloseTo, isEqualTo, isGreaterThan, isLessThan, isLessThan, modulo, moduloReverse, multiply, multiplyReverse, setUnitCategory, subtract, subtractReverse, unitsString
-
Methods inherited from class ptolemy.data.Token
isCloseTo, notSupportedConversionMessage, notSupportedIncomparableConversionMessage, notSupportedIncomparableMessage, notSupportedMessage, notSupportedNullNilStringMessage, pow, zeroReturnType
-
-
-
-
Field Detail
-
NIL
public static final ShortToken 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".
-
ONE
public static final ShortToken ONE
A ShortToken with the value 1.0.
-
ZERO
public static final ShortToken ZERO
A ShortToken with the value 0.0.
-
-
Constructor Detail
-
ShortToken
public ShortToken()
Construct a token with short 0.
-
ShortToken
public ShortToken(short value)
Construct a token with the specified value.- Parameters:
value
- The specified value.
-
ShortToken
public ShortToken(int value)
Construct a ShortToken with the specified integer value. This method's cast to (byte) keeps only the low order 16 bits of the integer.- Parameters:
value
- The specified value.
-
ShortToken
public ShortToken(java.lang.String init) throws IllegalActionException
Construct an ShortToken from the specified string.- Parameters:
init
- The specified string.- Throws:
IllegalActionException
- If the token could not be created with the given String.
-
-
Method Detail
-
complexValue
public Complex complexValue()
Return the value of this token as a Complex. The real part of the Complex is the value of this token, the imaginary part is set to 0.- Overrides:
complexValue
in classScalarToken
- Returns:
- A Complex.
-
convert
public static ShortToken convert(Token token) throws IllegalActionException
Convert the specified token into an instance of ShortToken. 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 ShortToken, it is returned without any change. If the argument is a nil token, thenNIL
is returned. Otherwise, if the argument is below ShortToken in the type hierarchy, it is converted to an instance of ShortToken or one of the subclasses of ShortToken and returned. If none of the above condition is met, an exception is thrown.- Parameters:
token
- The token to be converted to a ShortToken.- Returns:
- A ShortToken.
- Throws:
IllegalActionException
- If the conversion cannot be carried out.
-
doubleValue
public double doubleValue()
Return the value in the token as a double.- Overrides:
doubleValue
in classScalarToken
- Returns:
- The value contained in this token as a double.
-
equals
public boolean equals(java.lang.Object object)
Return true if the argument's class is ShortToken and it has the same values as this token.- Overrides:
equals
in classjava.lang.Object
- Parameters:
object
- An instance of Object.- Returns:
- True if the argument is an ShortToken with the same value. If either this object or the argument is a nil Token, return false.
-
fixValue
public FixPoint fixValue()
Return the value in the token as a fixpoint.- Overrides:
fixValue
in classScalarToken
- Returns:
- The value contained in this token as a fixpoint.
-
floatValue
public float floatValue()
Return the value in the token as a float.- Overrides:
floatValue
in classScalarToken
- Returns:
- The value contained in this token as a float.
-
getType
public Type getType()
Return the type of this token.- Specified by:
getType
in classScalarToken
- Returns:
- BaseType.SHORT
-
hashCode
public int hashCode()
Return a hash code value for this token. This method just returns the contained short casted to integer.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- A hash code value for this token.
-
intValue
public int intValue()
Return the value in the token as an int.- Overrides:
intValue
in classScalarToken
- Returns:
- The int value contained in this token.
-
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.
-
leftShift
public 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.- Overrides:
leftShift
in classScalarToken
- Parameters:
bits
- The number of bits to shift.- Returns:
- The left shift.
If this token is nil, then
NIL
is returned.
-
logicalRightShift
public 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. This treats the value as an unsigned number, which may have the effect of destroying the sign of the value.- Overrides:
logicalRightShift
in classScalarToken
- Parameters:
bits
- The number of bits to shift.- Returns:
- The logical right shift.
If this token is nil, then
NIL
is returned.
-
longValue
public long longValue()
Return the value in the token as a long.- Overrides:
longValue
in classScalarToken
- Returns:
- The short value contained in this token as a long.
-
one
public Token one()
Returns an ShortToken with value 1.
-
rightShift
public 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. This preserves the sign of the result.- Overrides:
rightShift
in classScalarToken
- Parameters:
bits
- The number of bits to shift.- Returns:
- The right shift.
If this token is nil, then
NIL
is returned.
-
shortValue
public short shortValue()
Return the value in the token as a short.- Overrides:
shortValue
in classScalarToken
- Returns:
- The value contained in this token as a short.
-
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. If this token has a unit, the return string also includes a unit string produced by the unitsString() method in the super class.- Overrides:
toString
in classToken
- Returns:
- A String representing the int value and the units (if any) of this token.
- See Also:
ScalarToken.unitsString()
-
zero
public Token zero()
Returns an ShortToken with value 0.
-
_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 returned. Note that it is explicitly allowable to return this token, since the units are the same.- Specified by:
_absolute
in classScalarToken
- Returns:
- An ShortToken.
-
_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 ShortToken.- Specified by:
_add
in classScalarToken
- Parameters:
rightArgument
- The token to add to this token.- Returns:
- A new ShortToken containing the result.
-
_bitwiseAnd
protected ScalarToken _bitwiseAnd(ScalarToken rightArgument)
Returns a token representing the bitwise AND of this token and the given token. It is assumed that the type of the argument is an ShortToken.- Specified by:
_bitwiseAnd
in classScalarToken
- Parameters:
rightArgument
- The ShortToken to bitwise AND with this one.- Returns:
- The bitwise AND.
-
_bitwiseNot
protected ScalarToken _bitwiseNot()
Returns a token representing the bitwise NOT of this token.- Specified by:
_bitwiseNot
in classScalarToken
- Returns:
- The bitwise NOT of this token.
-
_bitwiseOr
protected ScalarToken _bitwiseOr(ScalarToken rightArgument)
Returns a token representing the bitwise OR of this token and the given token. It is assumed that the type of the argument is an ShortToken.- Specified by:
_bitwiseOr
in classScalarToken
- Parameters:
rightArgument
- The ShortToken to bitwise OR with this one.- Returns:
- The bitwise OR.
-
_bitwiseXor
protected ScalarToken _bitwiseXor(ScalarToken rightArgument)
Returns a token representing the bitwise XOR of this token and the given token. It is assumed that the type of the argument is an ShortToken.- Specified by:
_bitwiseXor
in classScalarToken
- Parameters:
rightArgument
- The ShortToken to bitwise XOR with this one.- Returns:
- The bitwise XOR.
-
_divide
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. It is assumed that the type of the argument is an ShortToken.- Specified by:
_divide
in classScalarToken
- Parameters:
rightArgument
- The token to divide this token by.- Returns:
- A new ShortToken containing the result.
-
_isCloseTo
protected 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 their values is less than or equal to the second argument. It is assumed that the type of the first argument is ShortToken.- Specified by:
_isCloseTo
in classScalarToken
- Parameters:
rightArgument
- The token to compare to this token.epsilon
- The distance.- Returns:
- A token containing true if the value of the first argument is close to the value of this token.
-
_isLessThan
protected BooleanToken _isLessThan(ScalarToken rightArgument) throws IllegalActionException
Test for ordering of the values of this Token and the argument Token. It is assumed that the type of the argument is ShortToken.- Specified by:
_isLessThan
in classScalarToken
- Parameters:
rightArgument
- The token to add to this token.- Returns:
- A new Token containing the result.
- Throws:
IllegalActionException
- If this method is not supported by the derived class.
-
_modulo
protected ScalarToken _modulo(ScalarToken rightArgument)
Return a new token whose value is the value of this token modulo the value of the argument token. It is assumed that the type of the argument is an ShortToken.- Specified by:
_modulo
in classScalarToken
- Parameters:
rightArgument
- The token to modulo this token by.- Returns:
- A new ShortToken containing the result.
-
_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 ShortToken.- Specified by:
_multiply
in classScalarToken
- Parameters:
rightArgument
- The token to multiply this token by.- Returns:
- A new ShortToken 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 ShortToken.- Specified by:
_subtract
in classScalarToken
- Parameters:
rightArgument
- The token to subtract from this token.- Returns:
- A new ShortToken containing the result.
-
-