public class Type extends Object
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.
Modifier and Type | Field and 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. |
Modifier and Type | Method and Description |
---|---|
static 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.
|
BadHandler |
defaultBadHandler()
Returns a default bad value handler for this type.
|
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(Class cls)
Returns the Type object corresponding to a given java class.
|
boolean |
isFloating()
Indicates whether this type represents floating point values.
|
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.
|
Object |
newArray(int size)
Constructs a new primitive array of a requested size and the
appropriate type for this object.
|
String |
toString() |
public static final Type BYTE
byte
type.public static final Type SHORT
short
type.public static final Type INT
int
type.public static final Type FLOAT
float
type.public static final Type DOUBLE
double
type.public int getNumBytes()
public Class javaClass()
public Number defaultBadValue()
NaN
value for floating point
types, and the lowest (negatative) value for the integer types.public BadHandler defaultBadHandler()
defaultBadValue
method.public boolean isFloating()
public double minimumValue()
double
public double maximumValue()
double
public Object newArray(int size)
Array.newInstance(java.lang.Class<?>, int)
.size
- the number of elements requiredpublic void checkArray(Object array, int minsize)
IllegalArgumentException
is thrown.
This utility method is useful for parameter checking in
type-generic programming.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 arrayIllegalArgumentException
- if array is not an array or
has fewer than minSize elementspublic static List allTypes()
public static Type getType(Class cls)
cls
is not one of the
supported primitive numeric types) then null
is returned.cls
- a (presumably numeric primitive) class.
May be null
cls
,
or null
Copyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.