ptolemy.data.type
Interface Type

All Known Implementing Classes:
ActorToken.ActorType, BaseType, KeyToken.KeyType, StructuredType

public interface Type

An interface representing the type of a Token.

Since:
Ptolemy II 0.4
Version:
$Id: Type.java,v 1.42 2004/04/13 21:35:34 cxh Exp $
Author:
Yuhong Xiong, Steve Neuendorffer
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (neuendor)

Field Summary
static int HASH_INVALID
          Used to indicate that the type comparison cache is invalid
static int HASH_MAX
           
 
Method Summary
 java.lang.Object clone()
          Return a deep clone of this type.
 Token convert(Token token)
          Convert the specified token into a token having the type represented by this object.
 boolean equals(java.lang.Object object)
          Determine if the argument represents the same type as this object.
 java.lang.Class getTokenClass()
          Return the class for tokens that this type represents.
 int getTypeHash()
          Return a perfect hash for this type.
 boolean isCompatible(Type type)
          Test if the argument type is compatible with this type.
 boolean isConstant()
          Test if this Type is a constant.
 boolean isInstantiable()
          Determine if this Type corresponds to an instantiable token class.
 boolean isSubstitutionInstance(Type type)
          Return true if the specified type is a substitution instance of this type.
 java.lang.String toString()
          Return the string representation of this type.
 

Field Detail

HASH_INVALID

public static final int HASH_INVALID
Used to indicate that the type comparison cache is invalid

Since:
Ptolemy II 2.1
See Also:
Constant Field Values

HASH_MAX

public static final int HASH_MAX
See Also:
Constant Field Values
Method Detail

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Return a deep clone of this type.

Returns:
A Type.
Throws:
java.lang.CloneNotSupportedException - If an instance cannot be cloned.

convert

public Token convert(Token token)
              throws IllegalActionException
Convert the specified token into a token having the type represented by this object.

Parameters:
token - a token.
Returns:
a token.
Throws:
IllegalActionException - If lossless conversion cannot be done.

equals

public boolean equals(java.lang.Object object)
Determine if the argument represents the same type as this object.

Parameters:
object - A Type.
Returns:
True if the argument represents the same type as this object; false otherwise.

getTypeHash

public int getTypeHash()
Return a perfect hash for this type. This number corresponds uniquely to a particular type, and is used to improve performance of certain operations in the TypeLattice class. All instances of a particular type (e.g. integer array) must return the same number. Types that return HASH_INVALID will not have results in TypeLattice cached. Note that it is safer to return HASH_INVALID, than to return a number that is not unique, or different number for the same type from different instances.

Returns:
A number between 0 and HASH_MAX, or HASH_INVALID.

getTokenClass

public java.lang.Class getTokenClass()
Return the class for tokens that this type represents.


isCompatible

public boolean isCompatible(Type type)
Test if the argument type is compatible with this type. Compatible is defined as follows: If this type is a constant, the argument is compatible if it is the same or less than this type in the type lattice; If this type is a variable, the argument is compatible if it is a substitution instance of this type.

Parameters:
type - An instance of Type.
Returns:
True if the argument is compatible with this type.

isConstant

public boolean isConstant()
Test if this Type is a constant. A Type is a constant if it does not contain BaseType.UNKNOWN in any level within it.

Returns:
True if this type is a constant.

isInstantiable

public boolean isInstantiable()
Determine if this Type corresponds to an instantiable token class.

Returns:
True if this type corresponds to an instantiable token class.

isSubstitutionInstance

public boolean isSubstitutionInstance(Type type)
Return true if the specified type is a substitution instance of this type. For the argument to be a substitution instance, it must be either the same as this type, or it must be a type that can be obtained by replacing the BaseType.UNKNOWN component of this type by another type.

Parameters:
type - A Type.
Returns:
True if the argument is a substitution instance of this type.

toString

public java.lang.String toString()
Return the string representation of this type.

Returns:
A String.