ptolemy.data
Class AbstractNotConvertibleToken

java.lang.Object
  extended by ptolemy.data.Token
      extended by ptolemy.data.AbstractNotConvertibleToken
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ArrayToken, RecordToken, UnionToken

public abstract class AbstractNotConvertibleToken
extends Token

The Token base class provides a very general interface for building new data types. However, in many ways, the interface is rather complex in order to allow operations between tokens that are defined in different classes. In particular, this requires the duplicate operation() and operationReverse() methods.

This base class is intended to make it easy to implement tokens where operations are only defined for other tokens that are defined in the same class. In these cases, the operation() and operationReverse() method can share the same code. This class implements these methods to ensure that the argument of each operation is actually an instance of the correct class. The implementation then defers to a protected _operation() method. These protected methods should be overridden in derived classes to provide type-specific operations.

This class is used a base class for ArrayToken and RecordToken. Note that these classes actually represent tokens having different types in the type lattice.

Since:
Ptolemy II 2.1
Version:
$Id: AbstractNotConvertibleToken.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Steve Neuendorffer
See Also:
Serialized Form
Accepted Rating:
Green (cxh)
Proposed Rating:
Green (neuendor)

Field Summary
 
Fields inherited from class ptolemy.data.Token
NIL
 
Constructor Summary
AbstractNotConvertibleToken()
           
 
Method Summary
protected abstract  Token _add(Token rightArgument)
          Return a new token whose value is the value of the argument token added to the value of this token.
protected abstract  Token _divide(Token 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(Token rightArgument, double epsilon)
          Test that 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(Token token)
          Test for equality of the values of this token and the argument.
protected abstract  Token _modulo(Token rightArgument)
          Return a new token whose value is the value of this token modulo the value of the argument token.
protected abstract  Token _multiply(Token rightArgument)
          Return a new token whose value is the value of this token multiplied by the value of the argument token.
protected abstract  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 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.
 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 the argument token divided by the value of this token.
 BooleanToken isCloseTo(Token token, double epsilon)
          Test that 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.
 BooleanToken isEqualTo(Token rightArgument)
          Test for equality of the values of this token and the argument token.
 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 the argument token modulo the value of this 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 the argument token multiplied by the value of this token.
static java.lang.String notSupportedDifferentClassesMessage(java.lang.String operation, Token firstToken, Token secondToken)
          Return a string with an error message that states that the given operation is not supported between two tokens, because they have incomparable types and cannot be converted to the same type.
 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 this token subtracted from the value of the argument token.
 
Methods inherited from class ptolemy.data.Token
getType, isCloseTo, isNil, notSupportedConversionMessage, notSupportedIncomparableConversionMessage, notSupportedIncomparableMessage, notSupportedMessage, notSupportedNullNilStringMessage, one, pow, toString, zero, zeroReturnType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractNotConvertibleToken

public AbstractNotConvertibleToken()
Method Detail

add

public Token add(Token rightArgument)
          throws IllegalActionException
Return a new token whose value is the sum of this token and the argument. This base class ensures that the arguments are implemented in the same class, and then defers to the _add() method. Subclasses should override that method to perform type-specific operation

Overrides:
add in class Token
Parameters:
rightArgument - The token to add to this token.
Returns:
A new token containing the result.
Throws:
IllegalActionException - If the argument token and this token are implemented in different classes, or the operation does not make sense for the given types.

addReverse

public Token addReverse(Token leftArgument)
                 throws IllegalActionException
Return a new token whose value is the sum of this token and the argument. This base class ensures that the arguments are implemented in the same class, and then defers to the _add() method. Subclasses should override that method to perform type-specific operation.

Overrides:
addReverse in class Token
Parameters:
leftArgument - The token to add this token to.
Returns:
A new token containing the result.
Throws:
IllegalActionException - If the argument token and this token are implemented in different classes, or the operation does not make sense for the given types.

divide

public Token divide(Token rightArgument)
             throws IllegalActionException
Return a new token whose value is the value of this token divided by the value of the argument token. This base class ensures that the arguments are implemented in the same class, and then defers to the _divide() method. Subclasses should override that method to perform type-specific operation.

Overrides:
divide in class Token
Parameters:
rightArgument - The token to divide into this token.
Returns:
A new token containing the result.
Throws:
IllegalActionException - If the argument token and this token are implemented in different classes, or the operation does not make sense for the given types.

divideReverse

public Token divideReverse(Token leftArgument)
                    throws IllegalActionException
Return a new token whose value is the value of the argument token divided by the value of this token. This base class ensures that the arguments are implemented in the same class, and then defers to the _divide() method. Subclasses should override that method to perform type-specific operation.

Overrides:
divideReverse in class Token
Parameters:
leftArgument - The token to be divided by the value of this token.
Returns:
A new token containing the result.
Throws:
IllegalActionException - If the argument token and this token are implemented in different classes, or the operation does not make sense for the given types.

isCloseTo

public BooleanToken isCloseTo(Token token,
                              double epsilon)
                       throws IllegalActionException
Test that 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. This method only makes sense for tokens where the distance between them is reasonably represented as a double. This base class ensures that the arguments are implemented in the same class, and then defers to the _isCloseTo() method. Subclasses should override that method to perform type-specific operation.

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 value of this token is close to that of the argument token.
Throws:
IllegalActionException - If the argument token and this token are implemented in different classes.

isEqualTo

public BooleanToken isEqualTo(Token rightArgument)
                       throws IllegalActionException
Test for equality of the values of this token and the argument token. This base class ensures that the arguments are implemented in the same class, and then defers to the _isEqualTo() method. Subclasses should override that method to perform type-specific operation.

Overrides:
isEqualTo in class Token
Parameters:
rightArgument - The token with which to test equality.
Returns:
A boolean token that contains the value true if the value of this token is equal to that of the argument token.
Throws:
IllegalActionException - If the argument token and this token are implemented in different classes.

modulo

public Token modulo(Token rightArgument)
             throws IllegalActionException
Return a new token whose value is the value of this token modulo the value of the argument token. This base class ensures that the arguments are implemented in the same class, and then defers to the _modulo() method. Subclasses should override that method to perform type-specific operation.

Overrides:
modulo in class Token
Parameters:
rightArgument - The token to divide into this token.
Returns:
A new token containing the result.
Throws:
IllegalActionException - If the argument token and this token are implemented in different classes, or the operation does not make sense for the given types.

moduloReverse

public Token moduloReverse(Token leftArgument)
                    throws IllegalActionException
Return a new token whose value is the value of the argument token modulo the value of this token. This base class ensures that the arguments are implemented in the same class, and then defers to the _modulo() method. Subclasses should override that method to perform type-specific operation.

Overrides:
moduloReverse in class Token
Parameters:
leftArgument - The token to apply modulo to by the value of this token.
Returns:
A new token containing the result.
Throws:
IllegalActionException - If the argument token and this token are implemented in different classes, or the operation does not make sense for the given types.

multiply

public Token multiply(Token rightArgument)
               throws IllegalActionException
Return a new token whose value is the value of this token multiplied by the value of the argument token. This base class ensures that the arguments are implemented in the same class, and then defers to the _multiply() method. Subclasses should override that method to perform type-specific operation.

Overrides:
multiply in class Token
Parameters:
rightArgument - The token to multiply this token by.
Returns:
A new token containing the result.
Throws:
IllegalActionException - If the argument token and this token are implemented in different classes, or the operation does not make sense for the given types.

multiplyReverse

public Token multiplyReverse(Token leftArgument)
                      throws IllegalActionException
Return a new token whose value is the value of the argument token multiplied by the value of this token. This base class ensures that the arguments are implemented in the same class, and then defers to the _multiply() method. Subclasses should override that method to perform type-specific operation.

Overrides:
multiplyReverse in class Token
Parameters:
leftArgument - The token to be multiplied by the value of this token.
Returns:
A new token containing the result.
Throws:
IllegalActionException - If the argument token and this token are implemented in different classes, or the operation does not make sense for the given types.

notSupportedDifferentClassesMessage

public static java.lang.String notSupportedDifferentClassesMessage(java.lang.String operation,
                                                                   Token firstToken,
                                                                   Token secondToken)
Return a string with an error message that states that the given operation is not supported between two tokens, because they have incomparable types and cannot be converted to the same type.

Parameters:
operation - A string naming the unsupported token operation.
firstToken - The first token in the message.
secondToken - The second token in the message.
Returns:
A string error message.

subtract

public Token subtract(Token rightArgument)
               throws IllegalActionException
Return a new token whose value is the value of the argument token subtracted from the value of this token. This base class ensures that the arguments are implemented in the same class, and then defers to the _subtract() method. Subclasses should override that method to perform type-specific operation.

Overrides:
subtract in class Token
Parameters:
rightArgument - The token to subtract from this token.
Returns:
A new token containing the result.
Throws:
IllegalActionException - If the argument token and this token are implemented in different classes, or the operation does not make sense for the given types.

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. This base class ensures that the arguments are implemented in the same class, and then defers to the _subtract() method. Subclasses should override that method to perform type-specific operation.

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 argument token and this token are implemented in different classes, or the operation does not make sense for the given types.

_add

protected abstract Token _add(Token rightArgument)
                       throws IllegalActionException
Return a new token whose value is the value of the argument token added to the value of this token. It is guaranteed by the caller that the type of the argument is the same as the type of this class. This method should be overridden in derived classes to provide type specific actions for add.

Parameters:
rightArgument - The token whose value we add to the value of this token.
Returns:
A new token containing the result that is of the same class as this token.
Throws:
IllegalActionException - If this method is not supported by the derived class.

_divide

protected abstract Token _divide(Token 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 guaranteed by the caller that the type of the argument is the same as the type of this class. This method should be overridden in derived classes to provide type specific actions for divide.

Parameters:
rightArgument - The token to divide this token by.
Returns:
A new token containing the result that is of the same class as this token.
Throws:
IllegalActionException - If this method is not supported by the derived class.

_isCloseTo

protected abstract BooleanToken _isCloseTo(Token rightArgument,
                                           double epsilon)
                                    throws IllegalActionException
Test that 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. It is guaranteed by the caller that the type of the argument is the same as the type of this class. This method should be overridden in derived classes to provide type specific actions for divide.

Parameters:
rightArgument - The token with which to test closeness.
epsilon - The value that we use to determine whether two tokens are close.
Returns:
A token that contains the result of the test.
Throws:
IllegalActionException - If this method is not supported by the derived class.

_isEqualTo

protected BooleanToken _isEqualTo(Token token)
                           throws IllegalActionException
Test for equality of the values of this token and the argument. This base class delegates to the equals() method.

Parameters:
token - The token to compare to this token.
Returns:
A token containing true if the value element of the first argument is equal to the value of this token.
Throws:
IllegalActionException - Not thrown in this base class.

_modulo

protected abstract Token _modulo(Token rightArgument)
                          throws IllegalActionException
Return a new token whose value is the value of this token modulo the value of the argument token. It is guaranteed by the caller that the type of the argument is the same as the type of this class. This method should be overridden in derived classes to provide type specific actions for modulo.

Parameters:
rightArgument - The token to modulo this token by.
Returns:
A new token containing the result that is of the same class as this token.
Throws:
IllegalActionException - If this method is not supported by the derived class.

_multiply

protected abstract Token _multiply(Token rightArgument)
                            throws IllegalActionException
Return a new token whose value is the value of this token multiplied by the value of the argument token. It is guaranteed by the caller that the type of the argument is the same as the type of this class. This method should be overridden in derived classes to provide type specific actions for multiply.

Parameters:
rightArgument - The token to multiply this token by.
Returns:
A new token containing the result that is of the same class as this token.
Throws:
IllegalActionException - If this method is not supported by the derived class.

_subtract

protected abstract Token _subtract(Token rightArgument)
                            throws IllegalActionException
Return a new token whose value is the value of the argument token subtracted from the value of this token. It is guaranteed by the caller that the type of the argument is the same as the type of this class. This method should be overridden in derived classes to provide type specific actions for subtract.

Parameters:
rightArgument - The token to subtract from this token.
Returns:
A new token containing the result that is of the same class as this token.
Throws:
IllegalActionException - If this method is not supported by the derived class.