Package ptolemy.data.type
Class BaseType
- java.lang.Object
-
- ptolemy.data.type.BaseType
-
- All Implemented Interfaces:
Type
- Direct Known Subclasses:
BaseType.ArrayBottomType,BaseType.BooleanType,BaseType.ComplexType,BaseType.DateType,BaseType.DoubleType,BaseType.EventType,BaseType.FloatType,BaseType.GeneralType,BaseType.IntType,BaseType.LongType,BaseType.NilType,BaseType.PetiteType,BaseType.ScalarType,BaseType.ShortType,BaseType.StringType,BaseType.UnknownType,BaseType.UnsignedByteType,BaseType.UnsizedFixType,BaseType.XmlTokenType
public abstract class BaseType extends java.lang.Object implements Type
The type of base token classes. This class provides a type safe enumeration of base types.- Since:
- Ptolemy II 0.4
- Version:
- $Id$
- Author:
- Yuhong Xiong, Steve Neuendorffer
- Pt.AcceptedRating:
- Red
- Pt.ProposedRating:
- Red (yuhong)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBaseType.ArrayBottomTypeThe bottom element of the array type lattice.static classBaseType.BooleanTypeThe boolean data type.static classBaseType.ComplexTypeThe complex data type.static classBaseType.DateTypeThe date data type.static classBaseType.DoubleTypeThe double data type.static classBaseType.EventTypeThe event data type.static classBaseType.FloatTypeThe float data type.static classBaseType.GeneralTypeThe general data type: The top of the lattice.static classBaseType.IntTypeThe integer data type.static classBaseType.LongTypeThe long integer data type.static classBaseType.NilTypeThe nil data type.static classBaseType.PetiteTypeThe petite data type.static classBaseType.ScalarTypeThe scalar data type: The least upper bound of all the scalar types.static classBaseType.ShortTypeThe short integer data type.static classBaseType.StringTypeThe string data type.static classBaseType.UnknownTypeThe bottom element of the data type lattice.static classBaseType.UnsignedByteTypeThe unsigned byte data type.static classBaseType.UnsizedFixTypeThe fix data type.static classBaseType.XmlTokenTypeThe XmlToken data type.
-
Field Summary
Fields Modifier and Type Field Description static TypeACTORThe actor data type.static BaseType.ArrayBottomTypeARRAY_BOTTOMThe bottom element of the array type lattice.static BaseType.BooleanTypeBOOLEANThe boolean data type.static MatrixType.BooleanMatrixTypeBOOLEAN_MATRIXThe boolean matrix data type.static BaseType.ComplexTypeCOMPLEXThe complex data type.static MatrixType.ComplexMatrixTypeCOMPLEX_MATRIXThe complex matrix data type.static BaseType.DateTypeDATEThe DateToken data type.static BaseType.DoubleTypeDOUBLEThe double data type.static MatrixType.DoubleMatrixTypeDOUBLE_MATRIXThe double matrix data type.static BaseType.EventTypeEVENTThe event data type.static BaseType.UnsizedFixTypeFIXAn alias for the unsized fix data type, provided for backward compatibility with the previous versions of Ptolemy.static MatrixType.FixMatrixTypeFIX_MATRIXThe fix matrix data type.static BaseType.FloatTypeFLOATThe float data type.static BaseType.GeneralTypeGENERALThe general data type: The top of the lattice.static BaseType.IntTypeINTThe integer data type.static MatrixType.IntMatrixTypeINT_MATRIXThe integer matrix data type.static BaseType.LongTypeLONGThe long integer data type.static MatrixType.LongMatrixTypeLONG_MATRIXThe long integer matrix data type.static MatrixTypeMATRIXThe matrix data type: The least upper bound of all the matrix types.static BaseType.NilTypeNILThe nil data type.static ObjectTypeOBJECTThe object data type.static BaseType.PetiteTypePETITEThe petite data type.static RecordTypeRECORDSetting the type of something to RECORD allows it to take on a value that is any record with any fields.static BaseType.ScalarTypeSCALARThe scalar data type: The least upper bound of all the scalar types.static BaseType.ShortTypeSHORTThe short integer data type.static FixTypeSIZED_FIXThe fix data type, with a precision specified.static BaseType.StringTypeSTRINGThe string data type.static BaseType.UnknownTypeUNKNOWNThe bottom element of the data type lattice.static BaseType.UnsignedByteTypeUNSIGNED_BYTEThe unsigned byte data type.static BaseType.UnsizedFixTypeUNSIZED_FIXThe unsized fix data type.static BaseType.XmlTokenTypeXMLTOKENThe XmlToken data type.-
Fields inherited from interface ptolemy.data.type.Type
HASH_INVALID
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Typeadd(Type rightArgumentType)Return a new type which represents the type that results from adding a token of this type and a token of the given argument type.static voidaddType(Type type, java.lang.String name, java.lang.Class theClass)Specify that the given type, with the given name, is implemented by the specified token class.java.lang.Objectclone()Return this, that is, return the reference to this object.abstract Tokenconvert(Token t)Convert the specified token to a token having the type represented by this object.Typedivide(Type rightArgumentType)Return a new type which represents the type that results from dividing a token of this type and a token of the given argument type.booleanequals(java.lang.Object object)Determine if the argument represents the same BaseType as this object.static TypeforClassName(java.lang.String className)Return an instance of Type of that corresponds to tokens of a class with the given name, or null if none exists.static TypeforName(java.lang.String name)Return an instance of this class with the specified name, or null if none exists.java.lang.ClassgetTokenClass()Return the class for tokens that this basetype represents.intgetTypeHash()Return a perfect hash for this type.inthashCode()Return a hash code value for this object.booleanisAbstract()Return true if this type does not correspond to a single token class.booleanisCompatible(Type type)Test if the argument type is compatible with this type.booleanisConstant()Test if this Type is UNKNOWN.booleanisInstantiable()Determine if this type corresponds to an instantiable token classes.booleanisSubstitutionInstance(Type type)Return true if the argument is a substitution instance of this type.Typemodulo(Type rightArgumentType)Return a new type which represents the type that results from moduloing a token of this type and a token of the given argument type.Typemultiply(Type rightArgumentType)Return a new type which represents the type that results from multiplying a token of this type and a token of the given argument type.Typeone()Return the type of the multiplicative identity for elements of this type.Typesubtract(Type rightArgumentType)Return a new type which represents the type that results from subtracting a token of this type and a token of the given argument type.java.lang.StringtoString()Return the string representation of this type.Typezero()Return the type of the additive identity for elements of this type.
-
-
-
Field Detail
-
UNKNOWN
public static final BaseType.UnknownType UNKNOWN
The bottom element of the data type lattice.
-
ARRAY_BOTTOM
public static final BaseType.ArrayBottomType ARRAY_BOTTOM
The bottom element of the array type lattice.
-
BOOLEAN
public static final BaseType.BooleanType BOOLEAN
The boolean data type.
-
BOOLEAN_MATRIX
public static final MatrixType.BooleanMatrixType BOOLEAN_MATRIX
The boolean matrix data type.
-
UNSIGNED_BYTE
public static final BaseType.UnsignedByteType UNSIGNED_BYTE
The unsigned byte data type.
-
COMPLEX
public static final BaseType.ComplexType COMPLEX
The complex data type.
-
COMPLEX_MATRIX
public static final MatrixType.ComplexMatrixType COMPLEX_MATRIX
The complex matrix data type.
-
FLOAT
public static final BaseType.FloatType FLOAT
The float data type.
-
DOUBLE
public static final BaseType.DoubleType DOUBLE
The double data type.
-
DOUBLE_MATRIX
public static final MatrixType.DoubleMatrixType DOUBLE_MATRIX
The double matrix data type.
-
FIX
public static final BaseType.UnsizedFixType FIX
An alias for the unsized fix data type, provided for backward compatibility with the previous versions of Ptolemy.
-
UNSIZED_FIX
public static final BaseType.UnsizedFixType UNSIZED_FIX
The unsized fix data type.
-
SIZED_FIX
public static final FixType SIZED_FIX
The fix data type, with a precision specified.
-
FIX_MATRIX
public static final MatrixType.FixMatrixType FIX_MATRIX
The fix matrix data type.
-
SHORT
public static final BaseType.ShortType SHORT
The short integer data type.
-
INT
public static final BaseType.IntType INT
The integer data type.
-
INT_MATRIX
public static final MatrixType.IntMatrixType INT_MATRIX
The integer matrix data type.
-
LONG
public static final BaseType.LongType LONG
The long integer data type.
-
LONG_MATRIX
public static final MatrixType.LongMatrixType LONG_MATRIX
The long integer matrix data type.
-
OBJECT
public static final ObjectType OBJECT
The object data type.
-
ACTOR
public static final Type ACTOR
The actor data type.
-
XMLTOKEN
public static final BaseType.XmlTokenType XMLTOKEN
The XmlToken data type.
-
SCALAR
public static final BaseType.ScalarType SCALAR
The scalar data type: The least upper bound of all the scalar types.
-
MATRIX
public static final MatrixType MATRIX
The matrix data type: The least upper bound of all the matrix types.
-
STRING
public static final BaseType.StringType STRING
The string data type.
-
GENERAL
public static final BaseType.GeneralType GENERAL
The general data type: The top of the lattice.
-
EVENT
public static final BaseType.EventType EVENT
The event data type.
-
PETITE
public static final BaseType.PetiteType PETITE
The petite data type.
-
NIL
public static final BaseType.NilType NIL
The nil data type.
-
DATE
public static final BaseType.DateType DATE
The DateToken data type.
-
RECORD
public static final RecordType RECORD
Setting the type of something to RECORD allows it to take on a value that is any record with any fields. This is because a lossless conversion any such record to an empty record just returns the original record. So to force something to have a record type without specifying what fields it should have, dosomething.setTypeEquals(BaseType.RECORD);To allow the type to resolve to a specific record type (with particular fields), do insteadsomething.setTypeAtMost(BaseType.RECORD);This will work for example to require a parameter to have a record value, but to allow its type to resolve to the specific record specified.
-
-
Method Detail
-
add
public Type add(Type rightArgumentType)
Return a new type which represents the type that results from adding a token of this type and a token of the given argument type.
-
addType
public static void addType(Type type, java.lang.String name, java.lang.Class theClass)
Specify that the given type, with the given name, is implemented by the specified token class. Normally, an end user won't need this method, but there is a particular use that can sometimes come in handy. Occasionally it is useful for a token that subclasses a standard token to be used in place of that standard token. For example, you could create a subclass of DoubleToken called DoublePlusPlus that includes some extra fields. For that class to be acceptable to the expression language, for example as a return type from a function, then you must call this method to register that class. In this case, you call it with arguments BaseType.DOUBLE, "doublePlusPlus" (or whatever name you choose), and DoublePlusPlus.class.- Parameters:
type- The type.name- The name of the type.theClass- The implementation (token class) for the type.
-
clone
public java.lang.Object clone()
Return this, that is, return the reference to this object.
-
convert
public abstract Token convert(Token t) throws IllegalActionException
Convert the specified token to a token having the type represented by this object.- Specified by:
convertin interfaceType- Parameters:
t- A token.- Returns:
- A token.
- Throws:
IllegalActionException- If lossless conversion cannot be done.
-
divide
public Type divide(Type rightArgumentType)
Return a new type which represents the type that results from dividing a token of this type and a token of the given argument type.
-
equals
public boolean equals(java.lang.Object object)
Determine if the argument represents the same BaseType as this object.
-
forClassName
public static Type forClassName(java.lang.String className)
Return an instance of Type of that corresponds to tokens of a class with the given name, or null if none exists.- Parameters:
className- The name of the class.- Returns:
- An instance of BaseType.
-
forName
public static Type forName(java.lang.String name)
Return an instance of this class with the specified name, or null if none exists. Note that this does not recognize all the types that have symbolic names. It is better to use ptolemy.data.expr.Constants.types() to map a name to a type.- Parameters:
name- The name of the type.- Returns:
- An instance of BaseType.
-
getTokenClass
public java.lang.Class getTokenClass()
Return the class for tokens that this basetype represents.- Specified by:
getTokenClassin interfaceType- Returns:
- The class for tokens that this type represents.
-
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. This base class returns HASH_INVALID.- Specified by:
getTypeHashin interfaceType- Returns:
- A number greater than or equal to 0, or HASH_INVALID.
-
hashCode
public int hashCode()
Return a hash code value for this object.- Overrides:
hashCodein classjava.lang.Object
-
modulo
public Type modulo(Type rightArgumentType)
Return a new type which represents the type that results from moduloing a token of this type and a token of the given argument type.
-
multiply
public Type multiply(Type rightArgumentType)
Return a new type which represents the type that results from multiplying a token of this type and a token of the given argument type.
-
isAbstract
public boolean isAbstract()
Return true if this type does not correspond to a single token class. This occurs if the type is not instantiable, or it represents either an abstract base class or an interface.- Specified by:
isAbstractin interfaceType- Returns:
- True if this type does not correspond to a single token class.
-
isCompatible
public boolean isCompatible(Type type)
Test if the argument type is compatible with this type. The method returns true if this type is UNKNOWN, since any type is a substitution instance of it. If this type is not UNKNOWN, this method returns true if the argument type is less than or equal to this type in the type lattice, and false otherwise.- Specified by:
isCompatiblein interfaceType- 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 UNKNOWN.- Specified by:
isConstantin interfaceType- Returns:
- True if this Type is not UNKNOWN; false otherwise.
-
isInstantiable
public boolean isInstantiable()
Determine if this type corresponds to an instantiable token classes. A BaseType is instantiable if it does not correspond to an abstract token class, or an interface, or UNKNOWN.- Specified by:
isInstantiablein interfaceType- Returns:
- True if this type is instantiable.
-
isSubstitutionInstance
public boolean isSubstitutionInstance(Type type)
Return true if the argument is a substitution instance of this type.- Specified by:
isSubstitutionInstancein interfaceType- Parameters:
type- A Type.- Returns:
- True if this type is UNKNOWN; false otherwise.
-
one
public Type one()
Return the type of the multiplicative identity for elements of this type.
-
subtract
public Type subtract(Type rightArgumentType)
Return a new type which represents the type that results from subtracting a token of this type and a token of the given argument type.
-
toString
public java.lang.String toString()
Return the string representation of this type.
-
-