Class Type

java.lang.Object
uk.ac.starlink.array.Type

public class Type extends 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 final Type
    Object representing primitive data of byte type.
    static final Type
    Object representing primitive data of double type.
    static final Type
    Object representing primitive data of float type.
    static final Type
    Object representing primitive data of int type.
    static final Type
    Object representing primitive data of short type.
  • Method Summary

    Modifier and Type
    Method
    Description
    static List
    Returns a list of all the known Types.
    void
    checkArray(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.
    Returns a default bad value handler for this type.
    Returns the default bad value used for this type.
    int
    Returns the number of bytes occupied by this primitive type.
    static Type
    Returns the Type object corresponding to a given java class.
    boolean
    Indicates whether this type represents floating point values.
    Returns the java primitive class associated with this type.
    double
    Returns the highest value which can be represented by this type.
    double
    Returns the lowest (= most negative) value which can be represented by this type.
    newArray(int size)
    Constructs a new primitive array of a requested size and the appropriate type for this object.
     

    Methods inherited from class java.lang.Object

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

    • 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 Details

    • toString

      public String toString()
      Overrides:
      toString in class 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 Class javaClass()
      Returns the java primitive class associated with this type.
      Returns:
      the class corresponding to this object
    • defaultBadValue

      public 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 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(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:
      IllegalArgumentException - if array is not an array or has fewer than minSize elements
    • allTypes

      public static 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(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