Class BaseType

    • Field Detail

      • UNKNOWN

        public static final BaseType.UnknownType UNKNOWN
        The bottom element of the data type lattice.
      • FIX

        public static final BaseType.UnsizedFixType FIX
        An alias for the unsized fix data type, provided for backward compatibility with the previous versions of Ptolemy.
      • SIZED_FIX

        public static final FixType SIZED_FIX
        The fix data type, with a precision specified.
      • OBJECT

        public static final ObjectType OBJECT
        The object data type.
      • ACTOR

        public static final Type ACTOR
        The actor data type.
      • SCALAR

        public static final BaseType.ScalarType SCALAR
        The scalar data type: The least upper bound of all the scalar types.
      • MATRIX

        public static final MatrixType MATRIX
        The matrix data type: The least upper bound of all the matrix types.
      • GENERAL

        public static final BaseType.GeneralType GENERAL
        The general data type: The top of the lattice.
      • RECORD

        public static final RecordType RECORD
        Setting the type of something to RECORD allows it to take on a value that is any record with any fields. This is because a lossless conversion any such record to an empty record just returns the original record. So to force something to have a record type without specifying what fields it should have, do
            something.setTypeEquals(BaseType.RECORD);
          
        To allow the type to resolve to a specific record type (with particular fields), do instead
            something.setTypeAtMost(BaseType.RECORD);
          
        This will work for example to require a parameter to have a record value, but to allow its type to resolve to the specific record specified.
    • Method Detail

      • add

        public Type add​(Type rightArgumentType)
        Return a new type which represents the type that results from adding a token of this type and a token of the given argument type.
        Specified by:
        add in interface Type
        Parameters:
        rightArgumentType - The type to add to this type.
        Returns:
        A new type, or BaseType.GENERAL, if the operation does not make sense for the given types.
      • addType

        public static void addType​(Type type,
                                   java.lang.String name,
                                   java.lang.Class theClass)
        Specify that the given type, with the given name, is implemented by the specified token class. Normally, an end user won't need this method, but there is a particular use that can sometimes come in handy. Occasionally it is useful for a token that subclasses a standard token to be used in place of that standard token. For example, you could create a subclass of DoubleToken called DoublePlusPlus that includes some extra fields. For that class to be acceptable to the expression language, for example as a return type from a function, then you must call this method to register that class. In this case, you call it with arguments BaseType.DOUBLE, "doublePlusPlus" (or whatever name you choose), and DoublePlusPlus.class.
        Parameters:
        type - The type.
        name - The name of the type.
        theClass - The implementation (token class) for the type.
      • clone

        public java.lang.Object clone()
        Return this, that is, return the reference to this object.
        Specified by:
        clone in interface Type
        Overrides:
        clone in class java.lang.Object
        Returns:
        A BaseType.
      • divide

        public Type divide​(Type rightArgumentType)
        Return a new type which represents the type that results from dividing a token of this type and a token of the given argument type.
        Specified by:
        divide in interface Type
        Parameters:
        rightArgumentType - The type to add to this type.
        Returns:
        A new type, or BaseType.GENERAL, if the operation does not make sense for the given types.
      • equals

        public boolean equals​(java.lang.Object object)
        Determine if the argument represents the same BaseType as this object.
        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 BaseType as this object; false otherwise.
      • forClassName

        public static Type forClassName​(java.lang.String className)
        Return an instance of Type of that corresponds to tokens of a class with the given name, or null if none exists.
        Parameters:
        className - The name of the class.
        Returns:
        An instance of BaseType.
      • forName

        public static Type forName​(java.lang.String name)
        Return an instance of this class with the specified name, or null if none exists. Note that this does not recognize all the types that have symbolic names. It is better to use ptolemy.data.expr.Constants.types() to map a name to a type.
        Parameters:
        name - The name of the type.
        Returns:
        An instance of BaseType.
      • getTokenClass

        public java.lang.Class getTokenClass()
        Return the class for tokens that this basetype represents.
        Specified by:
        getTokenClass in interface Type
        Returns:
        The class for tokens that this type represents.
      • getTypeHash

        public int getTypeHash()
        Return a perfect hash for this type. This number corresponds uniquely to a particular type, and is used to improve performance of certain operations in the TypeLattice class. All instances of a particular type (e.g. integer array) must return the same number. Types that return HASH_INVALID will not have results in TypeLattice cached. Note that it is safer to return HASH_INVALID, than to return a number that is not unique, or different number for the same type from different instances. This base class returns HASH_INVALID.
        Specified by:
        getTypeHash in interface Type
        Returns:
        A number greater than or equal to 0, or HASH_INVALID.
      • hashCode

        public int hashCode()
        Return a hash code value for this object.
        Overrides:
        hashCode in class java.lang.Object
      • modulo

        public Type modulo​(Type rightArgumentType)
        Return a new type which represents the type that results from moduloing a token of this type and a token of the given argument type.
        Specified by:
        modulo in interface Type
        Parameters:
        rightArgumentType - The type to add to this type.
        Returns:
        A new type, or BaseType.GENERAL, if the operation does not make sense for the given types.
      • multiply

        public Type multiply​(Type rightArgumentType)
        Return a new type which represents the type that results from multiplying a token of this type and a token of the given argument type.
        Specified by:
        multiply in interface Type
        Parameters:
        rightArgumentType - The type to add to this type.
        Returns:
        A new type, or BaseType.GENERAL, if the operation does not make sense for the given types.
      • 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
        Returns:
        True if this type does not correspond to a single token class.
      • isCompatible

        public boolean isCompatible​(Type type)
        Test if the argument type is compatible with this type. The method returns true if this type is UNKNOWN, since any type is a substitution instance of it. If this type is not UNKNOWN, this method returns true if the argument type is less than or equal to this type in the type lattice, and false otherwise.
        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 Type is UNKNOWN.
        Specified by:
        isConstant in interface Type
        Returns:
        True if this Type is not UNKNOWN; false otherwise.
      • isInstantiable

        public boolean isInstantiable()
        Determine if this type corresponds to an instantiable token classes. A BaseType is instantiable if it does not correspond to an abstract token class, or an interface, or UNKNOWN.
        Specified by:
        isInstantiable in interface Type
        Returns:
        True if this type is instantiable.
      • isSubstitutionInstance

        public boolean isSubstitutionInstance​(Type type)
        Return true if the argument is a substitution instance of this type.
        Specified by:
        isSubstitutionInstance in interface Type
        Parameters:
        type - A Type.
        Returns:
        True if this type is UNKNOWN; false otherwise.
      • one

        public Type one()
        Return the type of the multiplicative identity for elements of this type.
        Specified by:
        one in interface Type
        Returns:
        A new type, or BaseType.GENERAL, if the operation does not make sense for the given types.
      • subtract

        public Type subtract​(Type rightArgumentType)
        Return a new type which represents the type that results from subtracting a token of this type and a token of the given argument type.
        Specified by:
        subtract in interface Type
        Parameters:
        rightArgumentType - The type to add to this type.
        Returns:
        A new type, or BaseType.GENERAL, if the operation does not make sense for the given types.
      • toString

        public java.lang.String toString()
        Return the string representation of this type.
        Specified by:
        toString in interface Type
        Overrides:
        toString in class java.lang.Object
        Returns:
        A String.
      • zero

        public Type zero()
        Return the type of the additive identity for elements of this type.
        Specified by:
        zero in interface Type
        Returns:
        A new type, or BaseType.GENERAL, if the operation does not make sense for the given types.