Class Type


  • public class Type
    extends java.lang.Object
    Primitive numeric data type identifier. Objects in this class are used to identify the type of the bulk data held in an NDArray.

    This class exemplifies the typesafe enum pattern -- the only possible instances are supplied as static final fields of the class, and these instances are immutable.

    Version:
    $Id$
    Author:
    Mark Taylor (Starlink)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static Type BYTE
      Object representing primitive data of byte type.
      static Type DOUBLE
      Object representing primitive data of double type.
      static Type FLOAT
      Object representing primitive data of float type.
      static Type INT
      Object representing primitive data of int type.
      static Type SHORT
      Object representing primitive data of short type.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.List allTypes()
      Returns a list of all the known Types.
      void checkArray​(java.lang.Object array, int minsize)
      Checks that a given Object is in fact an array of the primitive type corresponding to this Type, and contains at least a given number of elements; throws an exception if not.
      BadHandler defaultBadHandler()
      Returns a default bad value handler for this type.
      java.lang.Number defaultBadValue()
      Returns the default bad value used for this type.
      int getNumBytes()
      Returns the number of bytes occupied by this primitive type.
      static Type getType​(java.lang.Class cls)
      Returns the Type object corresponding to a given java class.
      boolean isFloating()
      Indicates whether this type represents floating point values.
      java.lang.Class javaClass()
      Returns the java primitive class associated with this type.
      double maximumValue()
      Returns the highest value which can be represented by this type.
      double minimumValue()
      Returns the lowest (= most negative) value which can be represented by this type.
      java.lang.Object newArray​(int size)
      Constructs a new primitive array of a requested size and the appropriate type for this object.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • BYTE

        public static final Type BYTE
        Object representing primitive data of byte type.
      • SHORT

        public static final Type SHORT
        Object representing primitive data of short type.
      • INT

        public static final Type INT
        Object representing primitive data of int type.
      • FLOAT

        public static final Type FLOAT
        Object representing primitive data of float type.
      • DOUBLE

        public static final Type DOUBLE
        Object representing primitive data of double type.
    • Method Detail

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getNumBytes

        public int getNumBytes()
        Returns the number of bytes occupied by this primitive type.
        Returns:
        the size of this type in bytes
      • javaClass

        public java.lang.Class javaClass()
        Returns the java primitive class associated with this type.
        Returns:
        the class corresponding to this object
      • defaultBadValue

        public java.lang.Number defaultBadValue()
        Returns the default bad value used for this type. This is never null; it is the NaN value for floating point types, and the lowest (negatative) value for the integer types.
        Returns:
        the bad value used for this Type by default
      • defaultBadHandler

        public BadHandler defaultBadHandler()
        Returns a default bad value handler for this type. For type BYTE, this is a null handler (no values considered bad), and for the other types it is a handler using the value returned by the defaultBadValue method.
        Returns:
        a BadHandler object implementing the default bad value policy for this type
      • isFloating

        public boolean isFloating()
        Indicates whether this type represents floating point values.
        Returns:
        true for floating point types, false for integral types
      • minimumValue

        public double minimumValue()
        Returns the lowest (= most negative) value which can be represented by this type.
        Returns:
        lowest value this type can represent, as a double
      • maximumValue

        public double maximumValue()
        Returns the highest value which can be represented by this type.
        Returns:
        highest value this type can represetn, as a double
      • newArray

        public java.lang.Object newArray​(int size)
        Constructs a new primitive array of a requested size and the appropriate type for this object. This utility method is useful for array allocation in type-generic programming. The current implementation just invokes Array.newInstance(java.lang.Class<?>, int).
        Parameters:
        size - the number of elements required
        Returns:
        a new primitive array
      • checkArray

        public void checkArray​(java.lang.Object array,
                               int minsize)
        Checks that a given Object is in fact an array of the primitive type corresponding to this Type, and contains at least a given number of elements; throws an exception if not. If the given Object satisfies these requirements no action is taken; if it does not then an IllegalArgumentException is thrown. This utility method is useful for parameter checking in type-generic programming.
        Parameters:
        array - an Object purporting to be a java array of primitives of the right primitive type for this Type and of at least minsize elements
        minsize - the minimum satisfactory size of array
        Throws:
        java.lang.IllegalArgumentException - if array is not an array or has fewer than minSize elements
      • allTypes

        public static java.util.List allTypes()
        Returns a list of all the known Types.
        Returns:
        an unmodifiable List containing all the existing type objects.
      • getType

        public static Type getType​(java.lang.Class cls)
        Returns the Type object corresponding to a given java class. If no corresponding type exists (cls is not one of the supported primitive numeric types) then null is returned.
        Parameters:
        cls - a (presumably numeric primitive) class. May be null
        Returns:
        the Type object corresponding to cls, or null