Class 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.
    • 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.
    • 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 the BaseType.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 interface Type
        Specified by:
        clone in class StructuredType
        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 interface Type
        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.
        Specified by:
        equals in interface Type
        Overrides:
        equals in class java.lang.Object
        Parameters:
        object - A Type.
        Returns:
        True if the argument represents the same type as this object; false otherwise.
      • getTokenClass

        public java.lang.Class<?> getTokenClass()
        Return the class for tokens that this type represents. The returned class is always ObjectToken.
        Specified by:
        getTokenClass in interface Type
        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 class java.lang.Object
        Returns:
        The hash code.
      • initialize

        public void initialize​(Type type)
        Ignore, as this type does not have elements.
        Specified by:
        initialize in class StructuredType
        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 interface Type
        Overrides:
        isAbstract in class StructuredType
        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 interface Type
        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 interface Type
        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 interface Type
        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 interface Type
        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.
        Specified by:
        toString in interface Type
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string of form 'object("classname")'.
      • _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 class StructuredType
        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 class StructuredType
        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 class StructuredType
        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 class StructuredType
        Parameters:
        type - a StructuredType.
        Returns:
        a StructuredType.
        Throws:
        java.lang.IllegalArgumentException - If the specified type is not the same structured type as this one.