ptolemy.data.type
Class FunctionType

java.lang.Object
  extended by ptolemy.data.type.StructuredType
      extended by ptolemy.data.type.FunctionType
All Implemented Interfaces:
java.lang.Cloneable, Type

public class FunctionType
extends StructuredType
implements java.lang.Cloneable

A class representing the type of a FunctionToken.

Since:
Ptolemy II 3.0
Version:
$Id: FunctionType.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Steve Neuendorffer
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (neuendor)

Nested Class Summary
private  class FunctionType.FieldTypeTerm
           
 
Field Summary
private  FunctionType.FieldTypeTerm[] _argTypeTerms
           
private static FunctionType _representative
           
private  FunctionType.FieldTypeTerm _returnTypeTerm
           
 
Fields inherited from class ptolemy.data.type.StructuredType
MAXDEPTHBOUND
 
Fields inherited from interface ptolemy.data.type.Type
HASH_INVALID, HASH_MAX
 
Constructor Summary
FunctionType(Type[] types, Type returnType)
          Construct a new FunctionType with the specified argument types and the given return type.
 
Method Summary
protected  int _compare(StructuredType type)
          Compare this type with the specified type.
protected  StructuredType _getRepresentative()
          Return a static instance of FunctionType.
protected  StructuredType _greatestLowerBound(StructuredType type)
          Return the greatest lower bound of this type with the specified type.
private  boolean _isLessThanOrEqualTo(FunctionType t1, FunctionType t2)
           
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 FunctionType if it is a variable, or itself if it is a constant.
 Token convert(Token token)
          Convert the argument token into a FunctionToken having this type, if lossless conversion can be done.
 boolean equals(java.lang.Object object)
          Determine if the argument represents the same FunctionType as this object.
 int getArgCount()
          Return the number of arguments in this type.
 Type getArgType(int i)
          Return the type of the given argument.
 FunctionType.FieldTypeTerm getArgTypeTerm(int i)
          Return the InequalityTerm representing the type of the given argument.
 Type getReturnType()
          Return the type of the specified label.
 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 type)
          Set the elements that have declared type BaseType.UNKNOWN (the leaf type variable) to the specified type.
 boolean isAbstract()
          Test if this type corresponds to an abstract token class.
 boolean isCompatible(Type type)
          Test if the argument type is compatible with this type.
 boolean isConstant()
          Test if this FunctionType is a constant.
 boolean isInstantiable()
          Test if this type corresponds to an instantiable token class.
 boolean isSubstitutionInstance(Type type)
          Test 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 FunctionType.
 
Methods inherited from class ptolemy.data.type.StructuredType
add, depth, divide, getTypeHash, modulo, multiply, one, subtract, zero
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_argTypeTerms

private FunctionType.FieldTypeTerm[] _argTypeTerms

_returnTypeTerm

private FunctionType.FieldTypeTerm _returnTypeTerm

_representative

private static FunctionType _representative
Constructor Detail

FunctionType

public FunctionType(Type[] types,
                    Type returnType)
Construct a new FunctionType 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.
returnType - An 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 FunctionType 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:
A FunctionType.

convert

public Token convert(Token token)
              throws IllegalActionException
Convert the argument token into a FunctionToken having this type, if lossless conversion can be done. The argument must be an FunctionToken, and its type must be a subtype of this record type.

Specified by:
convert in interface Type
Parameters:
token - A token.
Returns:
An FunctionToken.
Throws:
IllegalActionException - If lossless conversion cannot be done.

equals

public boolean equals(java.lang.Object object)
Determine if the argument represents the same FunctionType 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.

Specified by:
equals in interface Type
Overrides:
equals in class java.lang.Object
Parameters:
object - Another object.
Returns:
True if the argument represents the same FunctionType as this object.

getArgCount

public int getArgCount()
Return the number of arguments in this type.

Returns:
The number of arguments.

getArgType

public Type getArgType(int i)
Return the type of the given argument.

Parameters:
i - The index of the type.
Returns:
a Type.

getReturnType

public Type getReturnType()
Return the type of the specified label.

Returns:
a Type.

getTokenClass

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

Specified by:
getTokenClass in interface Type
Returns:
The class for tokens that this type represents.

getArgTypeTerm

public FunctionType.FieldTypeTerm getArgTypeTerm(int i)
Return the InequalityTerm representing the type of the given argument.

Parameters:
i - The index of the type.
Returns:
An InequalityTerm.
See Also:
InequalityTerm

hashCode

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

Overrides:
hashCode in class java.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:
initialize in class StructuredType
Parameters:
type - the type to set the leaf type variable to.

isAbstract

public boolean isAbstract()
Test if this type corresponds to an abstract token class. A FunctionType is abstract only if it is not instantiable.

Specified by:
isAbstract in interface Type
Overrides:
isAbstract in class StructuredType
Returns:
True if this type is abstract.

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:
isCompatible in interface Type
Parameters:
type - An instance of Type.
Returns:
True if the argument is compatible with this type.

isConstant

public boolean isConstant()
Test if this FunctionType is a constant. A FunctionType is a constant if the declared type of all of its fields are constant.

Specified by:
isConstant in interface Type
Returns:
True if this type is a constant.

isInstantiable

public boolean isInstantiable()
Test if this type corresponds to an instantiable token class. A FunctionType is instantiable if all of its fields are instantiable.

Specified by:
isInstantiable in interface Type
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:
isSubstitutionInstance in interface 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 function(a0:<type>, a1:<type>, ...) <type> Note that the function argument names are not semantically significant.

Specified by:
toString in interface Type
Overrides:
toString in class java.lang.Object
Returns:
A String.

updateType

public void updateType(StructuredType newType)
                throws IllegalActionException
Update this type to the specified FunctionType. The specified type must be a FunctionType 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:
updateType in class StructuredType
Parameters:
newType - A StructuredType.
Throws:
IllegalActionException - If the specified type is not a FunctionType 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 FunctionType, 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 - a FunctionType.
Returns:
An integer.
Throws:
java.lang.IllegalArgumentException - If the specified type is not a FunctionType.

_getRepresentative

protected StructuredType _getRepresentative()
Return a static instance of FunctionType.

Specified by:
_getRepresentative in class StructuredType
Returns:
a FunctionType.

_greatestLowerBound

protected StructuredType _greatestLowerBound(StructuredType type)
Return the greatest lower bound of this type with the specified type. The specified type must be a FunctionType, otherwise an exception will be thrown.

Specified by:
_greatestLowerBound in class StructuredType
Parameters:
type - a FunctionType.
Returns:
a FunctionType.
Throws:
java.lang.IllegalArgumentException - If the specified type is not a FunctionType.

_leastUpperBound

protected StructuredType _leastUpperBound(StructuredType type)
Return the least upper bound of this type with the specified type. The specified type must be a FunctionType, otherwise an exception will be thrown.

Specified by:
_leastUpperBound in class StructuredType
Parameters:
type - a FunctionType.
Returns:
a FunctionType.
Throws:
java.lang.IllegalArgumentException - If the specified type is not a FunctionType.

_isLessThanOrEqualTo

private boolean _isLessThanOrEqualTo(FunctionType t1,
                                     FunctionType t2)