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 Type
Object representing primitive data ofbyte
type.static final Type
Object representing primitive data ofdouble
type.static final Type
Object representing primitive data offloat
type.static final Type
Object representing primitive data ofint
type.static final Type
Object representing primitive data ofshort
type. -
Method Summary
Modifier and TypeMethodDescriptionstatic List
allTypes()
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.toString()
-
Field Details
-
BYTE
Object representing primitive data ofbyte
type. -
SHORT
Object representing primitive data ofshort
type. -
INT
Object representing primitive data ofint
type. -
FLOAT
Object representing primitive data offloat
type. -
DOUBLE
Object representing primitive data ofdouble
type.
-
-
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 theNaN
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
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 thedefaultBadValue
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
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 anIllegalArgumentException
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 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 (cls
is not one of the supported primitive numeric types) thennull
is returned.- Parameters:
cls
- a (presumably numeric primitive) class. May benull
- Returns:
- the Type object corresponding to
cls
, ornull
-