ptolemy.data.type
Class ArrayType

java.lang.Object
  extended byptolemy.data.type.StructuredType
      extended byptolemy.data.type.ArrayType
All Implemented Interfaces:
Type

public class ArrayType
extends StructuredType

A class representing the type of an ArrayToken.

Since:
Ptolemy II 4.0
Version:
$Id: ArrayType.java,v 1.72 2004/04/13 17:38:59 cxh Exp $
Author:
Steve Neuendorffer, Yuhong Xiong
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (cxh)

Field Summary
 
Fields inherited from interface ptolemy.data.type.Type
HASH_INVALID, HASH_MAX
 
Constructor Summary
ArrayType(Type elementType)
          Construct a new ArrayType with the specified type for the array elements.
 
Method Summary
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.
 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 losslessly conversion can be done.
 boolean equals(java.lang.Object object)
          Determine if the argument represents the same ArrayType as this object.
 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.
 void initialize(Type t)
          Set the elements that have declared type BaseType.UNKNOWN (the leaf type variable) to the specified type.
 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.
 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
getTypeHash
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

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.

Throws:
java.lang.IllegalArgumentException - If the argument is null.
Method Detail

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 interface Type
Specified by:
clone in class StructuredType
Returns:
An ArrayType.

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.

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 ArrayType as this object.

Parameters:
object - Another object.
Returns:
True if the argument represents the same ArrayType as this object; false otherwise.

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.


hashCode

public int hashCode()
Return a hash code value for this object.


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 class StructuredType
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.

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.

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.

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.

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 {}, where is the element type.

Returns:
A String.

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. This method will only update the component whose declared type is BaseType.UNKNOWN, and leave the constant part of this type intact.

Specified by:
updateType in class StructuredType
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 class StructuredType
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 class StructuredType
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 class StructuredType
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 class StructuredType
Parameters:
type - an ArrayType.
Returns:
an ArrayType.
Throws:
java.lang.IllegalArgumentException - If the specified type is not an ArrayType.