Package uk.ac.starlink.array
Class Type
java.lang.Object
uk.ac.starlink.array.Type
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
FieldsModifier and TypeFieldDescriptionstatic final TypeObject representing primitive data ofbytetype.static final TypeObject representing primitive data ofdoubletype.static final TypeObject representing primitive data offloattype.static final TypeObject representing primitive data ofinttype.static final TypeObject representing primitive data ofshorttype. -
Method Summary
Modifier and TypeMethodDescriptionstatic ListallTypes()Returns a list of all the known Types.voidcheckArray(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.intReturns the number of bytes occupied by this primitive type.static TypeReturns the Type object corresponding to a given java class.booleanIndicates whether this type represents floating point values.Returns the java primitive class associated with this type.doubleReturns the highest value which can be represented by this type.doubleReturns 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.toString()
-
Field Details
-
BYTE
Object representing primitive data ofbytetype. -
SHORT
Object representing primitive data ofshorttype. -
INT
Object representing primitive data ofinttype. -
FLOAT
Object representing primitive data offloattype. -
DOUBLE
Object representing primitive data ofdoubletype.
-
-
Method Details
-
toString
-
getNumBytes
public int getNumBytes()Returns the number of bytes occupied by this primitive type.- Returns:
- the size of this type in bytes
-
javaClass
Returns the java primitive class associated with this type.- Returns:
- the class corresponding to this object
-
defaultBadValue
Returns the default bad value used for this type. This is never null; it is theNaNvalue for floating point types, and the lowest (negatative) value for the integer types.- Returns:
- the bad value used for this Type by default
-
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 thedefaultBadValuemethod.- 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
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 invokesArray.newInstance(java.lang.Class<?>, int).- Parameters:
size- the number of elements required- Returns:
- a new primitive array
-
checkArray
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 anIllegalArgumentExceptionis 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 elementsminsize- the minimum satisfactory size of array- Throws:
IllegalArgumentException- if array is not an array or has fewer than minSize elements
-
allTypes
Returns a list of all the known Types.- Returns:
- an unmodifiable List containing all the existing type objects.
-
getType
Returns the Type object corresponding to a given java class. If no corresponding type exists (clsis not one of the supported primitive numeric types) thennullis returned.- Parameters:
cls- a (presumably numeric primitive) class. May benull- Returns:
- the Type object corresponding to
cls, ornull
-