Package ptolemy.data.type
Class ArrayType
- java.lang.Object
-
- ptolemy.data.type.StructuredType
-
- ptolemy.data.type.ArrayType
-
- All Implemented Interfaces:
java.lang.Cloneable
,Type
public class ArrayType extends StructuredType implements java.lang.Cloneable
A class representing the type of an ArrayToken.- Since:
- Ptolemy II 4.0
- Version:
- $Id$
- Author:
- Steve Neuendorffer, Yuhong Xiong
- Pt.AcceptedRating:
- Red (cxh)
- Pt.ProposedRating:
- Red (cxh)
-
-
Field Summary
Fields Modifier and Type Field Description static InequalityTerm
ARRAY_BOTTOM
A term to use when declaring the type of some parameter or port to be an array.static InequalityTerm
ARRAY_UNSIZED_BOTTOM
A term to use when declaring the type of some parameter or port to be an array, with unknown length.-
Fields inherited from class ptolemy.data.type.StructuredType
MAXDEPTHBOUND
-
Fields inherited from interface ptolemy.data.type.Type
HASH_INVALID
-
-
Method Summary
All Methods Static 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 ArrayType.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.static InequalityTerm
arrayOf(Typeable typeable)
Return a type constraint that can be used to constrain another typeable object to have a type related to an array whose element type is the type of the specified typeable.static InequalityTerm
arrayOf(Typeable typeable, int length)
Return a type constraint that can be used to constrain another typeable object to have a type related to an array whose element type is the type of the specified typeable.java.lang.Object
clone()
Return a deep copy of this ArrayType if it is a variable, or itself if it is a constant.Token
convert(Token token)
Convert the argument token into an ArrayToken having this type, if lossless conversion can be done.int
depth()
Return the depth of an array type.static InequalityTerm
elementType(Typeable typeable)
Return a type constraint that can be used to constrain another typeable object to have a type related to the element type of the specified typeable.boolean
equals(java.lang.Object object)
Determine if the argument represents the same ArrayType as this object.Type
getDeclaredElementType()
Return the declared type of the array elements.Type
getElementType()
Return the type of the array elements.InequalityTerm
getElementTypeTerm()
Return the InequalityTerm representing the element type.java.lang.Class
getTokenClass()
Return the class for tokens that this type represents.int
hashCode()
Return a hash code value for this object.boolean
hasKnownLength()
Return true if the length of this array type has been determined.void
initialize(Type t)
Set the elements that have declared type BaseType.UNKNOWN (the leaf type variable) to the specified type.boolean
isAbstract()
Return true if this type does not correspond to a single token class.boolean
isCompatible(Type type)
Test if the argument type is compatible with this type.boolean
isConstant()
Test if this ArrayType 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.int
length()
Return the length of this array type.void
setType(Type type)
Set the type to the specified type, which is required to be an array type.java.lang.String
toString()
Return the string representation of this type.void
updateType(StructuredType newType)
Update this Type to the specified ArrayType.-
Methods inherited from class ptolemy.data.type.StructuredType
add, divide, getTypeHash, modulo, multiply, one, subtract, zero
-
-
-
-
Field Detail
-
ARRAY_BOTTOM
public static final InequalityTerm ARRAY_BOTTOM
A term to use when declaring the type of some parameter or port to be an array. The way to use this is to declare:param.setTypeAtLeast(ArrayType.ARRAY_BOTTOM);
for a parameter "param".
-
ARRAY_UNSIZED_BOTTOM
public static final InequalityTerm ARRAY_UNSIZED_BOTTOM
A term to use when declaring the type of some parameter or port to be an array, with unknown length. The way to use this is to declare:param.setTypeAtLeast(ArrayType.ARRAY_UNSIZED_BOTTOM);
for a parameter "param".
-
-
Constructor Detail
-
ArrayType
public ArrayType(Type elementType)
Construct a new ArrayType with the specified type for the array elements. To leave the element type undeclared, use BaseType.UNKNOWN.- Parameters:
elementType
- The type of the array elements.- Throws:
java.lang.IllegalArgumentException
- If the argument is null.
-
ArrayType
public ArrayType(Type elementType, int length)
Construct a new ArrayType with the specified type for the array elements. To leave the element type undeclared, use BaseType.UNKNOWN.- Parameters:
elementType
- The type of the array elements.length
- Then length of the array.- Throws:
java.lang.IllegalArgumentException
- If the argument is null.
-
-
Method Detail
-
arrayOf
public static InequalityTerm arrayOf(Typeable typeable) throws IllegalActionException
Return a type constraint that can be used to constrain another typeable object to have a type related to an array whose element type is the type of the specified typeable. A typical usage of this is as follows:output.setTypeAtLeast(ArrayType.arrayOf(input));
where input and output are ports (this is the type constraint of SequenceToArray, for example).- Parameters:
typeable
- A typeable.- Returns:
- An InequalityTerm that can be passed to methods like setTypeAtLeast() of the Typeable interface.
- Throws:
IllegalActionException
- If the specified typeable cannot be set to an array type.
-
arrayOf
public static InequalityTerm arrayOf(Typeable typeable, int length) throws IllegalActionException
Return a type constraint that can be used to constrain another typeable object to have a type related to an array whose element type is the type of the specified typeable. A typical usage of this is as follows:output.setTypeAtLeast(ArrayType.arrayOf(input, length));
where input and output are ports (this is the type constraint of SequenceToArray, for example).- Parameters:
typeable
- A typeable.length
- The length of array.- Returns:
- An InequalityTerm that can be passed to methods like setTypeAtLeast() of the Typeable interface.
- Throws:
IllegalActionException
- If the specified typeable cannot be set to an array type.
-
clone
public java.lang.Object clone()
Return a deep copy of this ArrayType if it is a variable, or itself if it is a constant.- Specified by:
clone
in interfaceType
- Specified by:
clone
in classStructuredType
- Returns:
- An ArrayType.
-
convert
public Token convert(Token token) throws IllegalActionException
Convert the argument token into an ArrayToken having this type, if lossless conversion can be done. If the argument is not an ArrayToken, then the result is an array token with one entry, the argument.- Specified by:
convert
in interfaceType
- Parameters:
token
- A token.- Returns:
- An ArrayToken.
- Throws:
IllegalActionException
- If lossless conversion cannot be done.
-
depth
public int depth()
Return the depth of an array type. The depth of an array type is the number of times it contains other structured types. For example, an array of arrays has depth 2, and an array of arrays of records has depth 3.- Overrides:
depth
in classStructuredType
- Returns:
- the depth of a structured type.
-
equals
public boolean equals(java.lang.Object object)
Determine if the argument represents the same ArrayType as this object.
-
elementType
public static InequalityTerm elementType(Typeable typeable) throws IllegalActionException
Return a type constraint that can be used to constrain another typeable object to have a type related to the element type of the specified typeable. As a side effect, the specified typeable is constrained to have an array type. A typical usage of this is as follows:output.setTypeAtLeast(ArrayType.elementType(input));
where input and output are ports. This forces the input port to have an array type and the output port to have a type at least that of the elements of input arrays.- Parameters:
typeable
- An array-valued typeable.- Returns:
- An InequalityTerm that can be passed to methods like setTypeAtLeast() of the Typeable interface.
- Throws:
IllegalActionException
- If the specified typeable cannot be set to an array type.
-
getDeclaredElementType
public Type getDeclaredElementType()
Return the declared type of the array elements.- Returns:
- a Type.
-
getElementType
public Type getElementType()
Return the type of the array elements.- Returns:
- a Type.
-
getElementTypeTerm
public InequalityTerm getElementTypeTerm()
Return the InequalityTerm representing the element type.- Returns:
- An InequalityTerm.
- See Also:
InequalityTerm
-
getTokenClass
public java.lang.Class getTokenClass()
Return the class for tokens that this type represents.- Specified by:
getTokenClass
in interfaceType
- Returns:
- The class for tokens that this type represents.
-
hashCode
public int hashCode()
Return a hash code value for this object.- Overrides:
hashCode
in classjava.lang.Object
-
hasKnownLength
public boolean hasKnownLength()
Return true if the length of this array type has been determined.- Returns:
- true if the length has been determined.
-
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:
isAbstract
in interfaceType
- Overrides:
isAbstract
in classStructuredType
- Returns:
- true if the element type is abstract.
-
initialize
public void initialize(Type t)
Set the elements that have declared type BaseType.UNKNOWN (the leaf type variable) to the specified type.- Specified by:
initialize
in classStructuredType
- Parameters:
t
- 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. If this type is a constant, the argument is compatible if it is less than or equal to 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.- Specified by:
isCompatible
in interfaceType
- Parameters:
type
- A Type.- Returns:
- True if the argument is compatible with this type.
- See Also:
convert(ptolemy.data.Token)
-
isConstant
public boolean isConstant()
Test if this ArrayType is a constant. An ArrayType is a constant if it does not contain BaseType.UNKNOWN in any level.- Specified by:
isConstant
in interfaceType
- Returns:
- True if this type is a constant.
-
isInstantiable
public boolean isInstantiable()
Determine if this type corresponds to an instantiable token class. An ArrayType is instantiable if its element type is instantiable.- Specified by:
isInstantiable
in interfaceType
- Returns:
- True if this type is instantiable.
-
isSubstitutionInstance
public boolean isSubstitutionInstance(Type type)
Return true if the specified type is a substitution instance of this type.- Specified by:
isSubstitutionInstance
in 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)
-
length
public int length()
Return the length of this array type.- Returns:
- The length of this type.
- Throws:
java.lang.RuntimeException
- If the length is not known.
-
setType
public void setType(Type type) throws IllegalActionException
Set the type to the specified type, which is required to be an array type.- Parameters:
type
- The new type.- Throws:
IllegalActionException
- If the specified type is not an instance of ArrayType.
-
toString
public java.lang.String toString()
Return the string representation of this type. The format is {type}, where type is the element type.
-
updateType
public void updateType(StructuredType newType) throws IllegalActionException
Update this Type to the specified ArrayType. The specified type must be an ArrayType with the same structure as this type, and have depth less than the MAXDEPTHBOUND. This method will only update the component whose declared type is BaseType.UNKNOWN, and leave the constant part of this type intact.- Overrides:
updateType
in classStructuredType
- Parameters:
newType
- A StructuredType.- Throws:
IllegalActionException
- If the specified type is not an ArrayType 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 an ArrayType, 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:
_compare
in classStructuredType
- Parameters:
type
- an ArrayType.- Returns:
- An integer.
- Throws:
java.lang.IllegalArgumentException
- If the specified type is not an ArrayType.
-
_getRepresentative
protected StructuredType _getRepresentative()
Return a static instance of ArrayType.- Specified by:
_getRepresentative
in classStructuredType
- Returns:
- an ArrayType.
-
_greatestLowerBound
protected StructuredType _greatestLowerBound(StructuredType type)
Return the greatest lower bound of this type with the specified type. The specified type must be an ArrayType, otherwise an exception will be thrown.- Specified by:
_greatestLowerBound
in classStructuredType
- Parameters:
type
- an ArrayType.- Returns:
- an ArrayType.
- Throws:
java.lang.IllegalArgumentException
- If the specified type is not an ArrayType.
-
_leastUpperBound
protected StructuredType _leastUpperBound(StructuredType type)
Return the least Upper bound of this type with the specified type. The specified type must be an ArrayType, otherwise an exception will be thrown.- Specified by:
_leastUpperBound
in classStructuredType
- Parameters:
type
- an ArrayType.- Returns:
- an ArrayType.
- Throws:
java.lang.IllegalArgumentException
- If the specified type is not an ArrayType.
-
-