Package ptolemy.data.type
Class TupleType
- java.lang.Object
-
- ptolemy.data.type.StructuredType
-
- ptolemy.data.type.TupleType
-
- All Implemented Interfaces:
java.lang.Cloneable,Type
public class TupleType extends StructuredType implements java.lang.Cloneable
A class representing the type of a FunctionToken.- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Steve Neuendorffer
- Pt.AcceptedRating:
- Red (cxh)
- Pt.ProposedRating:
- Red (neuendor)
-
-
Field Summary
-
Fields inherited from class ptolemy.data.type.StructuredType
MAXDEPTHBOUND
-
Fields inherited from interface ptolemy.data.type.Type
HASH_INVALID
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int_compare(StructuredType type)Compare this type with the specified type.protected StructuredType_getRepresentative()Return a static instance of TupleType.protected StructuredType_greatestLowerBound(StructuredType type)Return the greatest lower bound of this type with the specified type.protected StructuredType_leastUpperBound(StructuredType type)Return the least upper bound of this type with the specified type.java.lang.Objectclone()Return a deep copy of this TupleType if it is a variable, or itself if it is a constant.Tokenconvert(Token token)Convert the argument token into an ArrayToken having this type, if losslessly conversion can be done.booleanequals(java.lang.Object object)Determine if the argument represents the same TupleType as this object.ptolemy.data.type.TupleType.FieldTypeTermgetArgTypeTerm(int i)Return the InequalityTerm representing the type of the given argument.intgetElementCount()Return the number of arguments in this type.TypegetElementType(int i)Return the type of the given argument.java.lang.ClassgetTokenClass()Return the class for tokens that this type represents.inthashCode()Return a hash code value for this object.voidinitialize(Type type)Set the elements that have declared type BaseType.UNKNOWN (the leaf type variable) to the specified type.booleanisCompatible(Type type)Test if the argument type is compatible with this type.booleanisConstant()Test if this TupleType is a constant.booleanisInstantiable()Test if this type corresponds to an instantiable token class.booleanisSubstitutionInstance(Type type)Test if the specified type is a substitution instance of this type.java.lang.StringtoString()Return the string representation of this type.voidupdateType(StructuredType newType)Update this type to the specified TupleType.-
Methods inherited from class ptolemy.data.type.StructuredType
add, depth, divide, getTypeHash, isAbstract, modulo, multiply, one, subtract, zero
-
-
-
-
Constructor Detail
-
TupleType
public TupleType(Type[] types)
Construct a new TupleType with the specified argument types and the given return type. To leave the types of some fields undeclared, use BaseType.UNKNOWN. To construct the type for a function of no arguments, set the length of the argument array to 0.- Parameters:
types- An array of Type.- Throws:
java.lang.IllegalArgumentException- If the labels and types do not have the same size.java.lang.NullPointerException- If one of the arguments is null.
-
-
Method Detail
-
clone
public java.lang.Object clone()
Return a deep copy of this TupleType if it is a variable, or itself if it is a constant.- Specified by:
clonein interfaceType- Specified by:
clonein classStructuredType- Returns:
- A TupleType.
-
convert
public Token convert(Token token) throws IllegalActionException
Convert the argument token into an ArrayToken having this type, if losslessly conversion can be done. The argument must be an ArrayToken.- Specified by:
convertin interfaceType- Parameters:
token- A token.- Returns:
- An ArrayToken.
- Throws:
IllegalActionException- If lossless conversion cannot be done.
-
equals
public boolean equals(java.lang.Object object)
Determine if the argument represents the same TupleType as this object. Two function types are equal if they have the same field names and the type of each field is the same, and they have the same return type.
-
getElementCount
public int getElementCount()
Return the number of arguments in this type.- Returns:
- The number of arguments in this type.
-
getElementType
public Type getElementType(int i)
Return the type of the given argument.- Parameters:
i- The given argument.- Returns:
- a Type.
-
getTokenClass
public java.lang.Class getTokenClass()
Return the class for tokens that this type represents.- Specified by:
getTokenClassin interfaceType- Returns:
- The class for tokens that this type represents.
-
getArgTypeTerm
public ptolemy.data.type.TupleType.FieldTypeTerm getArgTypeTerm(int i)
Return the InequalityTerm representing the type of the given argument.- Parameters:
i- The given argument.- Returns:
- An InequalityTerm.
- See Also:
InequalityTerm
-
hashCode
public int hashCode()
Return a hash code value for this object.- Overrides:
hashCodein classjava.lang.Object
-
initialize
public void initialize(Type type)
Set the elements that have declared type BaseType.UNKNOWN (the leaf type variable) to the specified type.- Specified by:
initializein classStructuredType- Parameters:
type- the type to set the leaf type variable to.
-
isCompatible
public boolean isCompatible(Type type)
Test if the argument type is compatible with this type. The given type will be compatible with this type if it is BaseType.UNKNOWN, or...- 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 TupleType is a constant. A TupleType is a constant if the declared type of all of its fields are constant.- Specified by:
isConstantin interfaceType- Returns:
- True if this type is a constant.
-
isInstantiable
public boolean isInstantiable()
Test if this type corresponds to an instantiable token class. A TupleType is instantiable if all of its fields are instantiable.- Specified by:
isInstantiablein interfaceType- Returns:
- True if this type is instantiable.
-
isSubstitutionInstance
public boolean isSubstitutionInstance(Type type)
Test if the specified type is a substitution instance of this type. One function is a substitution instance of another if they have arguments with the same types and each field of the given type is a substitution instance of the corresponding field in this type.- Specified by:
isSubstitutionInstancein interfaceType- Parameters:
type- A Type.- Returns:
- True if the argument is a substitution instance of this type.
- See Also:
Type.isSubstitutionInstance(ptolemy.data.type.Type)
-
toString
public java.lang.String toString()
Return the string representation of this type. The format is function(a0:>type<, a1:>type<, ...) >type<. Note that the function argument names are not semantically significant.
-
updateType
public void updateType(StructuredType newType) throws IllegalActionException
Update this type to the specified TupleType. The specified type must be a TupleType and have the same structure as this one. This method will only update the component whose declared type is BaseType.UNKNOWN, and leave the constant part of this type intact.- Overrides:
updateTypein classStructuredType- Parameters:
newType- A StructuredType.- Throws:
IllegalActionException- If the specified type is not a TupleType or it does not have the same structure as this one.
-
_compare
protected int _compare(StructuredType type)
Compare this type with the specified type. The specified type must be a TupleType, otherwise an exception will be thrown. This method returns one of ptolemy.graph.CPO.LOWER, ptolemy.graph.CPO.SAME, ptolemy.graph.CPO.HIGHER, ptolemy.graph.CPO.INCOMPARABLE, indicating this type is lower than, equal to, higher than, or incomparable with the specified type in the type hierarchy, respectively.- Specified by:
_comparein classStructuredType- Parameters:
type- a TupleType.- Returns:
- An integer.
- Throws:
java.lang.IllegalArgumentException- If the specified type is not a TupleType.
-
_getRepresentative
protected StructuredType _getRepresentative()
Return a static instance of TupleType.- Specified by:
_getRepresentativein classStructuredType- Returns:
- a TupleType.
-
_greatestLowerBound
protected StructuredType _greatestLowerBound(StructuredType type)
Return the greatest lower bound of this type with the specified type. The specified type must be a TupleType, otherwise an exception will be thrown.- Specified by:
_greatestLowerBoundin classStructuredType- Parameters:
type- a TupleType.- Returns:
- a TupleType.
- Throws:
java.lang.IllegalArgumentException- If the specified type is not a TupleType.
-
_leastUpperBound
protected StructuredType _leastUpperBound(StructuredType type)
Return the least upper bound of this type with the specified type. The specified type must be a TupleType, otherwise an exception will be thrown.- Specified by:
_leastUpperBoundin classStructuredType- Parameters:
type- a TupleType.- Returns:
- a TupleType.
- Throws:
java.lang.IllegalArgumentException- If the specified type is not a TupleType.
-
-