Class ObjectType
- java.lang.Object
-
- ptolemy.data.type.StructuredType
-
- ptolemy.data.type.ObjectType
-
- All Implemented Interfaces:
java.lang.Cloneable
,Type
public class ObjectType extends StructuredType implements java.lang.Cloneable
A type of tokens that contain arbitrary Java objects. An instance of this class specifies the Java class that the contents of the ObjectTokens of that type must be instances of.A special type lattice is defined for variants of ObjectType. The top element of the elements in the type lattice is an ObjectType that does not specify any Java class as the class for the contents of its tokens. In the expression language, that element can be referred to with "object" or "object()". Any ObjectToken conforms to this type. A subtype of this type specifies a Java class. In the expression language, such a subtype can be defined with "object(string)", where string is a string (starting and ending with a quote). For example, the following expression refers to a variant of ObjectType to which only ObjectTokens containing atomic actors as their contents conform:
object("ptolemy.actor.AtomicActor")
This ObjectType is a subtype of the most general ObjectType, "object". Furthermore, it is also a subtype of "object(\"ptolemy.kernel.Entity\")", and at the same time a supertype of "object(\"ptolemy.actor.lib.Const\")".The bottom element of the type lattice is an artificial ObjectType with
ObjectType.BottomClass
as its specified Java class. In Java, the class hierarchy does not form a lattice, so this artificial type is needed to be the greatest lower bound for any two classes if one is not a subclass of the other.- Since:
- Ptolemy II 8.0
- Version:
- $Id$
- Author:
- Thomas Huining Feng
- See Also:
ObjectToken
- Pt.AcceptedRating:
- Red (tfeng)
- Pt.ProposedRating:
- Red (tfeng)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ObjectType.BottomClass
An artificial Java class that serves as the bottom element.
-
Field Summary
Fields Modifier and Type Field Description static ObjectType
BOTTOM
The bottom element among all ObjectTypes.static ObjectType
TOP
The top element among all ObjectTypes.-
Fields inherited from class ptolemy.data.type.StructuredType
MAXDEPTHBOUND
-
Fields inherited from interface ptolemy.data.type.Type
HASH_INVALID
-
-
Constructor Summary
Constructors Constructor Description ObjectType()
Construct an ObjectType with null as the Java class specified in it.ObjectType(java.lang.Class<?> valueClass)
Construct an ObjectType with the given Java class as the class specified in it.ObjectType(java.lang.Object value, java.lang.Class<?> valueClass)
Construct an ObjectType with the given Java class as the class specified in it.
-
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 this object type.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 clone of this type.Token
convert(Token token)
Convert the specified token into a token having the type represented by this object.boolean
equals(java.lang.Object object)
Determine if the argument represents the same type as this object.java.lang.Class<?>
getTokenClass()
Return the class for tokens that this type represents.java.lang.Object
getValue()
Get the actual value.java.lang.Class<?>
getValueClass()
Get the Java class specified in this type, of which the contents of ObjectTokens conforming to this type must be instances.int
hashCode()
Return the hash code for this object.void
initialize(Type type)
Ignore, as this type does not have elements.boolean
isAbstract()
Return true if this type does not correspond to a single token class.boolean
isCompatible(Type type)
Return true if the specified type is less than or equal to this type.boolean
isConstant()
Test if the argument type is compatible with this type.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 a string describing this object.-
Methods inherited from class ptolemy.data.type.StructuredType
add, depth, divide, getTypeHash, modulo, multiply, one, subtract, updateType, zero
-
-
-
-
Field Detail
-
BOTTOM
public static final ObjectType BOTTOM
The bottom element among all ObjectTypes.
-
TOP
public static final ObjectType TOP
The top element among all ObjectTypes. The value of this variable is == to theBaseType.OBJECT
so that code generation can use "xxx == BaseType.OBJECT".
-
-
Constructor Detail
-
ObjectType
public ObjectType()
Construct an ObjectType with null as the Java class specified in it. This type is the most general type (top element) among all the ObjectTypes.
-
ObjectType
public ObjectType(java.lang.Class<?> valueClass)
Construct an ObjectType with the given Java class as the class specified in it.- Parameters:
valueClass
- The Java class.
-
ObjectType
public ObjectType(java.lang.Object value, java.lang.Class<?> valueClass) throws IllegalActionException
Construct an ObjectType with the given Java class as the class specified in it.- Parameters:
value
- The actual object value, or null if the value is unknown.valueClass
- The Java class.- Throws:
IllegalActionException
- If the value is not an instance of valueClass.
-
-
Method Detail
-
clone
public java.lang.Object clone()
Return a deep clone of this type.- Specified by:
clone
in interfaceType
- Specified by:
clone
in classStructuredType
- Returns:
- A Type.
-
convert
public Token convert(Token token) throws IllegalActionException
Convert the specified token into a token having the type represented by this object.- Specified by:
convert
in interfaceType
- Parameters:
token
- a token.- Returns:
- a token.
- Throws:
IllegalActionException
- If lossless conversion cannot be done.
-
equals
public boolean equals(java.lang.Object object)
Determine if the argument represents the same type as this object.
-
getTokenClass
public java.lang.Class<?> getTokenClass()
Return the class for tokens that this type represents. The returned class is alwaysObjectToken
.- Specified by:
getTokenClass
in interfaceType
- Returns:
- The class for tokens that this type represents.
-
getValue
public java.lang.Object getValue()
Get the actual value.- Returns:
- The actual value, or null if it is unknown.
-
getValueClass
public java.lang.Class<?> getValueClass()
Get the Java class specified in this type, of which the contents of ObjectTokens conforming to this type must be instances.- Returns:
- The Java class specified in this type.
-
hashCode
public int hashCode()
Return the hash code for this object.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- The hash code.
-
initialize
public void initialize(Type type)
Ignore, as this type does not have elements.- Specified by:
initialize
in classStructuredType
- Parameters:
type
- The type to initialize unknown elements to.
-
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 this type does not correspond to a single token class.
-
isCompatible
public boolean isCompatible(Type type)
Return true if the specified type is less than or equal to this type.- Specified by:
isCompatible
in interfaceType
- Parameters:
type
- The type to be checked- Returns:
- True if the specified type is less than or equal to this type.
-
isConstant
public boolean isConstant()
Test if the argument type is compatible with this type. Compatible is defined as follows: If this type is a constant, the argument is compatible if it is the same or less than 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:
isConstant
in interfaceType
- Returns:
- True if the argument is compatible with this type.
-
isInstantiable
public boolean isInstantiable()
Determine if this Type corresponds to an instantiable token class.- Specified by:
isInstantiable
in interfaceType
- Returns:
- True if this type corresponds to an instantiable token class.
-
isSubstitutionInstance
public boolean isSubstitutionInstance(Type type)
Return true if the specified type is a substitution instance of this type. For the argument to be a substitution instance, it must be either the same as this type, or it must be a type that can be obtained by replacing the BaseType.UNKNOWN component of this type by another type.- Specified by:
isSubstitutionInstance
in interfaceType
- Parameters:
type
- A Type.- Returns:
- True if the argument is a substitution instance of this type.
-
toString
public java.lang.String toString()
Return a string describing this object.
-
_compare
protected int _compare(StructuredType type)
Compare this type with the specified type. The specified type must be of the same structured type, 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
- a StructuredType.- Returns:
- An integer.
- Throws:
java.lang.IllegalArgumentException
- If the specified type is not the same structured type as this one.
-
_getRepresentative
protected StructuredType _getRepresentative()
Return a static instance of this object type. The return value is used by TypeLattice to represent this type.- Specified by:
_getRepresentative
in classStructuredType
- Returns:
- The bottom object type.
-
_greatestLowerBound
protected StructuredType _greatestLowerBound(StructuredType type)
Return the greatest lower bound of this type with the specified type. The specified type must be of the same structured type, otherwise an exception will be thrown.- Specified by:
_greatestLowerBound
in classStructuredType
- Parameters:
type
- a StructuredType.- Returns:
- a StructuredType.
- Throws:
java.lang.IllegalArgumentException
- If the specified type is not the same structured type as this one.
-
_leastUpperBound
protected StructuredType _leastUpperBound(StructuredType type)
Return the least upper bound of this type with the specified type. The specified type must be of the same structured type, otherwise an exception will be thrown.- Specified by:
_leastUpperBound
in classStructuredType
- Parameters:
type
- a StructuredType.- Returns:
- a StructuredType.
- Throws:
java.lang.IllegalArgumentException
- If the specified type is not the same structured type as this one.
-
-