ptolemy.data
Class LongToken

java.lang.Object
  extended byptolemy.data.Token
      extended byptolemy.data.ScalarToken
          extended byptolemy.data.LongToken
All Implemented Interfaces:
BitwiseOperationToken, java.io.Serializable

public class LongToken
extends ScalarToken

A token that contains a signed 64-bit long integer. Generally, this class handles overflow the same way that overflow for Java native types are handled. In other words, overflow just past java.lang.Long.MAX_VALUE results in negative values close to java.lang.Long.MIN_VALUE.

Since:
Ptolemy II 0.2
Version:
$Id: LongToken.java,v 1.83 2004/04/13 03:21:45 cxh Exp $
Author:
Neil Smyth, Yuhong Xiong, Steve Neuendorffer
See Also:
Serialized Form
Accepted Rating:
Yellow (neuendor)
Proposed Rating:
Green (neuendor)

Field Summary
 
Fields inherited from class ptolemy.data.ScalarToken
_unitCategoryExponents
 
Constructor Summary
LongToken()
          Construct a token with long integer 0.
LongToken(long value)
          Construct a token with the specified value.
LongToken(java.lang.String init)
          Construct a token from the given 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)
          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.
static LongToken convert(Token token)
          Convert the specified token into an instance of LongToken.
 boolean equals(java.lang.Object object)
          Return true if the argument's class is LongToken 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.
 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 a new LongToken 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.
 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.
 UnsignedByteToken truncatedUnsignedByteValue()
          Return the value in the token truncated to an unsignedByte.
 Token zero()
          Returns a new LongToken with value 0.
 
Methods inherited from class ptolemy.data.ScalarToken
_addCategoryExponents, _areUnitsEqual, _copyOfCategoryExponents, _isEqualTo, _isUnitless, _subtractCategoryExponents, absolute, add, addReverse, bitwiseAnd, bitwiseNot, bitwiseOr, bitwiseXor, byteValue, complexValue, divide, divideReverse, doubleValue, fixValue, intValue, inUnitsOf, isCloseTo, isEqualTo, isGreaterThan, isLessThan, modulo, moduloReverse, multiply, multiplyReverse, setUnitCategory, subtract, subtractReverse, unitsString
 
Methods inherited from class ptolemy.data.Token
isCloseTo, notSupportedConversionMessage, notSupportedIncomparableConversionMessage, notSupportedIncomparableMessage, notSupportedMessage, pow, zeroReturnType
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LongToken

public LongToken()
Construct a token with long integer 0.


LongToken

public LongToken(long value)
Construct a token with the specified value.


LongToken

public LongToken(java.lang.String init)
          throws IllegalActionException
Construct a token from the given String.

Throws:
IllegalActionException - If the Token could not be created with the given String.
Method Detail

convert

public static LongToken convert(Token token)
                         throws IllegalActionException
Convert the specified token into an instance of LongToken. 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 LongToken, it is returned without any change. Otherwise, if the argument is below LongToken in the type hierarchy, it is converted to an instance of LongToken or one of the subclasses of LongToken and returned. If none of the above condition is met, an exception is thrown.

Parameters:
token - The token to be converted to a LongToken.
Returns:
A LongToken.
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 LongToken and it has the same values as this token.

Parameters:
object - An instance of Object.
Returns:
True if the argument is a LongToken with the same value.

getType

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

Specified by:
getType in class ScalarToken
Returns:
BaseType.LONG_MATRIX

hashCode

public int hashCode()
Return a hash code value for this token. This method returns the value of this token, casted to integer.

Returns:
A hash code value for this token.

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 class ScalarToken
Parameters:
bits - The number of bits to shift.
Returns:
The left shift.

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 class ScalarToken
Parameters:
bits - The number of bits to shift.
Returns:
The logical right shift.

longValue

public long longValue()
Return the value in the token as a long.

Overrides:
longValue in class ScalarToken
Returns:
The value of this token as a long.

one

public Token one()
Returns a new LongToken with value 1.

Overrides:
one in class Token
Returns:
A new LongToken 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 class ScalarToken
Parameters:
bits - The number of bits to shift.
Returns:
The right shift.

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.Long.toString().

truncatedUnsignedByteValue

public UnsignedByteToken truncatedUnsignedByteValue()
                                             throws IllegalActionException
Return the value in the token truncated to an unsignedByte.

Throws:
IllegalActionException - If the value is not in the range of an unsigned byte.

zero

public Token zero()
Returns a new LongToken with value 0.

Overrides:
zero in class Token
Returns:
A new LongToken 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 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:
An LongToken.

_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 LongToken.

Specified by:
_add in class ScalarToken
Parameters:
rightArgument - The token to add to this token.
Returns:
A new LongToken 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 LongToken.

Specified by:
_bitwiseAnd in class ScalarToken
Returns:
The bitwise AND.

_bitwiseNot

protected ScalarToken _bitwiseNot()
Returns a token representing the bitwise NOT of this token. It is assumed that the type of the argument is an LongToken.

Specified by:
_bitwiseNot in class ScalarToken
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 LongToken.

Specified by:
_bitwiseOr in class ScalarToken
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 LongToken.

Specified by:
_bitwiseXor in class ScalarToken
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 LongToken

Specified by:
_divide in class ScalarToken
Parameters:
rightArgument - The token to divide this token by.
Returns:
A new LongToken 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 LongToken.

Specified by:
_isCloseTo in class ScalarToken
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.

_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 LongToken.

Specified by:
_isLessThan in class ScalarToken
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 LongToken.

Specified by:
_modulo in class ScalarToken
Parameters:
rightArgument - The token to modulo this token by.
Returns:
A new LongToken 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 LongToken.

Specified by:
_multiply in class ScalarToken
Parameters:
rightArgument - The token to multiply this token by.
Returns:
A new LongToken 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 LongToken.

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