Package ucar.ma2
Enum DataType
- java.lang.Object
-
- java.lang.Enum<DataType>
-
- ucar.ma2.DataType
-
- All Implemented Interfaces:
Serializable,Comparable<DataType>
public enum DataType extends Enum<DataType>
Type-safe enumeration of data types. Do not change the ordering of these enums, as they are used in protobuf messages, only add new ones onto the end.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDataType.SignednessA property ofintegraldata types that determines whether they can represent both positive and negative numbers (signed), or only non-negative numbers (unsigned).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DataTypeenumTypeize(DataType dt)ClassgetPrimitiveClassType()The primitive class type: char, byte, float, double, short, int, long, boolean, String, StructureData, StructureDataIterator, ByteBuffer.DataType.SignednessgetSignedness()Returns thesignednessof this data type.intgetSize()Size in bytes of one element of this data type.static DataTypegetType(Class c, boolean isUnsigned)Find the DataType that matches this class.static DataTypegetType(String name)Find the DataType that matches this name.static DataTypegetType(Array arr)booleanisEnum()Is this an enumeration types?booleanisEnumCompatible(DataType inferred)booleanisFloatingPoint()Is Float or DoublebooleanisIntegral()Is Byte, Int, Short, or LongbooleanisNumeric()Is Byte, Float, Double, Int, Short, or LongbooleanisString()Is String or CharbooleanisUnsigned()Returnstrueif the data type isunsigned.StringtoString()The DataType name, eg "byte", "float", "String".static shortunsignedByteToShort(byte b)Converts the argument to ashortby an unsigned conversion.static longunsignedIntToLong(int i)Converts the argument to alongby an unsigned conversion.static BigIntegerunsignedLongToBigInt(long l)Converts the argument to aBigIntegerby an unsigned conversion.static intunsignedShortToInt(short s)Converts the argument to anintby an unsigned conversion.static DataTypevalueOf(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 NumberwidenNumber(Number number)Convert the argument to the next largest integral data type by an unsigned conversion.static NumberwidenNumberIfNegative(Number number)This method is similar towidenNumber(java.lang.Number), but only integral types that are negative are widened.DataTypewithSignedness(DataType.Signedness signedness)Returns a DataType that is related tothis, but with the specified signedness.
-
-
-
Enum Constant Detail
-
BOOLEAN
public static final DataType BOOLEAN
-
BYTE
public static final DataType BYTE
-
CHAR
public static final DataType CHAR
-
SHORT
public static final DataType SHORT
-
INT
public static final DataType INT
-
LONG
public static final DataType LONG
-
FLOAT
public static final DataType FLOAT
-
DOUBLE
public static final DataType DOUBLE
-
SEQUENCE
public static final DataType SEQUENCE
-
STRING
public static final DataType STRING
-
STRUCTURE
public static final DataType STRUCTURE
-
ENUM1
public static final DataType ENUM1
-
ENUM2
public static final DataType ENUM2
-
ENUM4
public static final DataType ENUM4
-
OPAQUE
public static final DataType OPAQUE
-
OBJECT
public static final DataType OBJECT
-
UBYTE
public static final DataType UBYTE
-
USHORT
public static final DataType USHORT
-
UINT
public static final DataType UINT
-
ULONG
public static final DataType ULONG
-
-
Method Detail
-
values
public static DataType[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (DataType c : DataType.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static DataType valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-
toString
public String toString()
The DataType name, eg "byte", "float", "String".
-
getSize
public int getSize()
Size in bytes of one element of this data type. Strings dont know, so return 0. Structures return 1.- Returns:
- Size in bytes of one element of this data type.
-
getPrimitiveClassType
public Class getPrimitiveClassType()
The primitive class type: char, byte, float, double, short, int, long, boolean, String, StructureData, StructureDataIterator, ByteBuffer.- Returns:
- the primitive class type
-
getSignedness
public DataType.Signedness getSignedness()
Returns thesignednessof this data type. For non-integraldata types, it is guaranteed to beDataType.Signedness.SIGNED.- Returns:
- the signedness of this data type.
-
isUnsigned
public boolean isUnsigned()
Returnstrueif the data type isunsigned. For non-integraldata types, it is guaranteed to befalse.- Returns:
trueif the data type is unsigned.
-
isString
public boolean isString()
Is String or Char- Returns:
- true if String or Char
-
isNumeric
public boolean isNumeric()
Is Byte, Float, Double, Int, Short, or Long- Returns:
- true if numeric
-
isIntegral
public boolean isIntegral()
Is Byte, Int, Short, or Long- Returns:
- true if integral
-
isFloatingPoint
public boolean isFloatingPoint()
Is Float or Double- Returns:
- true if floating point type
-
isEnum
public boolean isEnum()
Is this an enumeration types?- Returns:
- true if ENUM1, 2, or 4
-
withSignedness
public DataType withSignedness(DataType.Signedness signedness)
Returns a DataType that is related tothis, but with the specified signedness. This method is only meaningful forintegraldata types; if it is called on a non-integral type, thenthisis 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
- Parameters:
signedness- the desired signedness of the returned DataType.- Returns:
- a DataType that is related to
this, but with the specified signedness.
-
isEnumCompatible
public boolean isEnumCompatible(DataType inferred)
-
getType
public static DataType getType(String name)
Find the DataType that matches this name.- Parameters:
name- find DataType with this name.- Returns:
- DataType or null if no match.
-
getType
public static DataType getType(Class c, boolean isUnsigned)
Find the DataType that matches this class.- Parameters:
c- primitive or object class, eg float.class or Float.class- Returns:
- DataType or null if no match.
-
widenNumber
public static Number widenNumber(Number number)
Convert the argument to the next largest integral data type by an unsigned conversion. In the larger data type, the upper-order bits will be zero, and the lower-order bits will be equivalent to the bits innumber. 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 - Parameters:
number- an integral number to treat as unsigned.- Returns:
- an equivalent but wider value that Java will interpret as non-negative.
-
widenNumberIfNegative
public static Number widenNumberIfNegative(Number number)
This method is similar towidenNumber(java.lang.Number), but only integral types that are negative are widened.- Parameters:
number- an integral number to treat as unsigned.- Returns:
- an equivalent value that Java will interpret as non-negative.
-
unsignedLongToBigInt
public static BigInteger unsignedLongToBigInt(long l)
Converts the argument to aBigIntegerby an unsigned conversion. In an unsigned conversion to aBigInteger, zero and positivelongvalues are mapped to a numerically equalBigIntegervalue and negativelongvalues are mapped to aBigIntegervalue equal to the input plus 264.- Parameters:
l- alongto treat as unsigned.- Returns:
- the equivalent
BigIntegervalue.
-
unsignedIntToLong
public static long unsignedIntToLong(int i)
Converts the argument to alongby an unsigned conversion. In an unsigned conversion to along, the high-order 32 bits of thelongare zero and the low-order 32 bits are equal to the bits of the integer argument. Consequently, zero and positiveintvalues are mapped to a numerically equallongvalue and negativeintvalues are mapped to alongvalue equal to the input plus 232.- Parameters:
i- anintto treat as unsigned.- Returns:
- the equivalent
longvalue.
-
unsignedShortToInt
public static int unsignedShortToInt(short s)
Converts the argument to anintby an unsigned conversion. In an unsigned conversion to anint, the high-order 16 bits of theintare zero and the low-order 16 bits are equal to the bits of theshortargument. Consequently, zero and positiveshortvalues are mapped to a numerically equalintvalue and negativeshortvalues are mapped to anintvalue equal to the input plus 216.- Parameters:
s- ashortto treat as unsigned.- Returns:
- the equivalent
intvalue.
-
unsignedByteToShort
public static short unsignedByteToShort(byte b)
Converts the argument to ashortby an unsigned conversion. In an unsigned conversion to ashort, the high-order 8 bits of theshortare zero and the low-order 8 bits are equal to the bits of thebyteargument. Consequently, zero and positivebytevalues are mapped to a numerically equalshortvalue and negativebytevalues are mapped to ashortvalue equal to the input plus 28.- Parameters:
b- abyteto treat as unsigned.- Returns:
- the equivalent
shortvalue.
-
-