public enum DataType extends Enum<DataType>
Modifier and Type | Class and Description |
---|---|
static class |
DataType.Signedness
A property of
integral data types that determines whether they can represent both
positive and negative numbers (signed), or only non-negative numbers (unsigned). |
Enum Constant and Description |
---|
BOOLEAN |
BYTE |
CHAR |
DOUBLE |
ENUM1 |
ENUM2 |
ENUM4 |
FLOAT |
INT |
LONG |
OBJECT |
OPAQUE |
SEQUENCE |
SHORT |
STRING |
STRUCTURE |
UBYTE |
UINT |
ULONG |
USHORT |
Modifier and Type | Method and Description |
---|---|
static DataType |
enumTypeize(DataType dt) |
Class |
getPrimitiveClassType()
The primitive class type: char, byte, float, double, short, int, long, boolean, String, StructureData,
StructureDataIterator, ByteBuffer.
|
DataType.Signedness |
getSignedness()
Returns the
signedness of this data type. |
int |
getSize()
Size in bytes of one element of this data type.
|
static DataType |
getType(Array arr) |
static DataType |
getType(Class c,
boolean isUnsigned)
Find the DataType that matches this class.
|
static DataType |
getType(String name)
Find the DataType that matches this name.
|
boolean |
isEnum()
Is this an enumeration types?
|
boolean |
isEnumCompatible(DataType inferred) |
boolean |
isFloatingPoint()
Is Float or Double
|
boolean |
isIntegral()
Is Byte, Int, Short, or Long
|
boolean |
isNumeric()
Is Byte, Float, Double, Int, Short, or Long
|
boolean |
isString()
Is String or Char
|
boolean |
isUnsigned()
Returns
true if the data type is unsigned . |
String |
toString()
The DataType name, eg "byte", "float", "String".
|
static short |
unsignedByteToShort(byte b)
Converts the argument to a
short by an unsigned conversion. |
static long |
unsignedIntToLong(int i)
Converts the argument to a
long by an unsigned conversion. |
static BigInteger |
unsignedLongToBigInt(long l)
Converts the argument to a
BigInteger by an unsigned conversion. |
static int |
unsignedShortToInt(short s)
Converts the argument to an
int by an unsigned conversion. |
static DataType |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static DataType[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
static Number |
widenNumber(Number number)
Convert the argument to the next largest integral data type by an unsigned conversion.
|
static Number |
widenNumberIfNegative(Number number)
This method is similar to
widenNumber(java.lang.Number) , but only integral types that are negative are widened. |
DataType |
withSignedness(DataType.Signedness signedness)
Returns a DataType that is related to
this , but with the specified signedness. |
public static final DataType BOOLEAN
public static final DataType BYTE
public static final DataType CHAR
public static final DataType DOUBLE
public static final DataType ENUM1
public static final DataType ENUM2
public static final DataType ENUM4
public static final DataType FLOAT
public static final DataType INT
public static final DataType LONG
public static final DataType OBJECT
public static final DataType OPAQUE
public static final DataType SEQUENCE
public static final DataType SHORT
public static final DataType STRING
public static final DataType STRUCTURE
public static final DataType UBYTE
public static final DataType UINT
public static final DataType ULONG
public static final DataType USHORT
public Class getPrimitiveClassType()
public DataType.Signedness getSignedness()
signedness
of this data type.
For non-integral
data types, it is guaranteed to be DataType.Signedness.SIGNED
.public int getSize()
public static DataType getType(Class c, boolean isUnsigned)
c
- primitive or object class, eg float.class or Float.classpublic static DataType getType(String name)
name
- find DataType with this name.public boolean isEnum()
public boolean isEnumCompatible(DataType inferred)
public boolean isFloatingPoint()
public boolean isIntegral()
public boolean isNumeric()
public boolean isString()
public boolean isUnsigned()
true
if the data type is unsigned
.
For non-integral
data types, it is guaranteed to be false
.true
if the data type is unsigned.public String toString()
public static short unsignedByteToShort(byte b)
short
by an unsigned conversion. In an unsigned conversion to a short
, the high-order 8 bits of the short
are zero and the low-order 8 bits are equal to the bits of
the byte
argument.
Consequently, zero and positive byte
values are mapped to a numerically equal short
value and
negative byte
values are mapped to a short
value equal to the input plus 28.b
- a byte
to treat as unsigned.short
value.public static long unsignedIntToLong(int i)
long
by an unsigned conversion. In an unsigned conversion to a long
,
the high-order 32 bits of the long
are zero and the low-order 32 bits are equal to the bits of the integer
argument.
Consequently, zero and positive int
values are mapped to a numerically equal long
value and
negative int
values are mapped to a long
value equal to the input plus 232.i
- an int
to treat as unsigned.long
value.public static BigInteger unsignedLongToBigInt(long l)
BigInteger
by an unsigned conversion. In an unsigned conversion to a
BigInteger
, zero and positive long
values are mapped to a numerically equal BigInteger
value and negative long
values are mapped to a BigInteger
value equal to the input plus
264.l
- a long
to treat as unsigned.BigInteger
value.public static int unsignedShortToInt(short s)
int
by an unsigned conversion. In an unsigned conversion to an int
,
the high-order 16 bits of the int
are zero and the low-order 16 bits are equal to the bits of the short
argument.
Consequently, zero and positive short
values are mapped to a numerically equal int
value and
negative short
values are mapped to an int
value equal to the input plus 216.s
- a short
to treat as unsigned.int
value.public static DataType valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic static DataType[] values()
for (DataType c : DataType.values()) System.out.println(c);
public static Number widenNumber(Number number)
number
.
Thus, we are "widening" the argument by prepending a bunch of zero bits to it.
This widening operation is intended to be used on unsigned integral values that are being stored within one of
Java's signed, integral data types. For example, if we have the bit pattern "11001010" and treat it as
an unsigned byte, it'll have the decimal value "202". However, if we store that bit pattern in a (signed)
byte, Java will interpret it as "-52". Widening the byte to a short will mean that the most-significant
set bit is no longer the sign bit, and thus Java will no longer consider the value to be negative.
Argument type | Result type |
---|---|
Byte | Short |
Short | Integer |
Integer | Long |
Long | BigInteger |
Any other Number subtype | Just return argument |
number
- an integral number to treat as unsigned.public static Number widenNumberIfNegative(Number number)
widenNumber(java.lang.Number)
, but only integral types that are negative are widened.number
- an integral number to treat as unsigned.public DataType withSignedness(DataType.Signedness signedness)
this
, but with the specified signedness.
This method is only meaningful for integral
data types; if it is called on a non-integral
type, then this
is simply returned. Examples:
assert DataType.INT.withSignedness(DataType.Signedness.UNSIGNED) == DataType.UINT; // INT to UINT assert DataType.ULONG.withSignedness(DataType.Signedness.SIGNED) == DataType.LONG; // ULONG to LONG assert DataType.SHORT.withSignedness(DataType.Signedness.SIGNED) == DataType.SHORT; // this: Same signs assert DataType.STRING.withSignedness(DataType.Signedness.UNSIGNED) == DataType.STRING; // this: Non-integral
signedness
- the desired signedness of the returned DataType.this
, but with the specified signedness.