Package ucar.array
Enum ArrayType
- java.lang.Object
-
- java.lang.Enum<ArrayType>
-
- ucar.array.ArrayType
-
- All Implemented Interfaces:
Serializable
,Comparable<ArrayType>
public enum ArrayType extends Enum<ArrayType>
Type-safe enumeration of Array data types.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ArrayType.Signedness
A property ofintegral
data 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 ArrayType
forPrimitiveClass(Class<?> c, boolean isUnsigned)
Find the ArrayType used for this primitive class type.Class<?>
getPrimitiveClass()
The primitive Java class type, inverse of forPrimitiveClass()ArrayType.Signedness
getSignedness()
Returns thesignedness
of this data type.int
getSize()
Size in bytes of one element of this data type.static ArrayType
getTypeByName(String name)
Find the ArrayType that matches this name.boolean
isEnum()
Is this an enumeration types?boolean
isFloatingPoint()
Is Float or Doubleboolean
isIntegral()
Is Byte, Int, Short, or Longboolean
isNumeric()
Is Byte, Float, Double, Int, Short, or Longboolean
isString()
Is String or Charboolean
isStruct()
Is this a Structure type?boolean
isUnsigned()
Returnstrue
if the data type isunsigned
.String
toCdl()
The name used for CDLString
toNcml()
The name used for Ncml.String
toString()
static short
unsignedByteToShort(byte b)
Converts the argument to ashort
by an unsigned conversion.static long
unsignedIntToLong(int i)
Converts the argument to along
by an unsigned conversion.static BigInteger
unsignedLongToBigInt(long l)
Converts the argument to aBigInteger
by an unsigned conversion.static int
unsignedShortToInt(short s)
Converts the argument to anint
by an unsigned conversion.static ArrayType
valueOf(String name)
Returns the enum constant of this type with the specified name.static ArrayType[]
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 towidenNumber(java.lang.Number)
, but only integral types that are negative are widened.ArrayType
withSignedness(ArrayType.Signedness signedness)
Returns an ArrayType that is related tothis
, but with the specified signedness.
-
-
-
Enum Constant Detail
-
BYTE
public static final ArrayType BYTE
-
CHAR
public static final ArrayType CHAR
-
SHORT
public static final ArrayType SHORT
-
INT
public static final ArrayType INT
-
LONG
public static final ArrayType LONG
-
FLOAT
public static final ArrayType FLOAT
-
DOUBLE
public static final ArrayType DOUBLE
-
UBYTE
public static final ArrayType UBYTE
-
USHORT
public static final ArrayType USHORT
-
UINT
public static final ArrayType UINT
-
ULONG
public static final ArrayType ULONG
-
ENUM1
public static final ArrayType ENUM1
-
ENUM2
public static final ArrayType ENUM2
-
ENUM4
public static final ArrayType ENUM4
-
STRING
public static final ArrayType STRING
-
STRUCTURE
public static final ArrayType STRUCTURE
-
SEQUENCE
public static final ArrayType SEQUENCE
-
OPAQUE
public static final ArrayType OPAQUE
-
-
Method Detail
-
values
public static ArrayType[] 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 (ArrayType c : ArrayType.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static ArrayType 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
-
toNcml
public String toNcml()
The name used for Ncml.
-
toCdl
public String toCdl()
The name used for CDL
-
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.
-
getPrimitiveClass
public Class<?> getPrimitiveClass()
The primitive Java class type, inverse of forPrimitiveClass()
-
getSignedness
public ArrayType.Signedness getSignedness()
Returns thesignedness
of this data type. For non-integral
data types, it is guaranteed to beArrayType.Signedness.SIGNED
.- Returns:
- the signedness of this data type.
-
isUnsigned
public boolean isUnsigned()
Returnstrue
if the data type isunsigned
. For non-integral
data types, it is guaranteed to befalse
.- Returns:
true
if 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
-
isStruct
public boolean isStruct()
Is this a Structure type?- Returns:
- true if STRUCTURE or SEQUENCE
-
withSignedness
public ArrayType withSignedness(ArrayType.Signedness signedness)
Returns an ArrayType that is related tothis
, but with the specified signedness. This method is only meaningful forintegral
data types; if it is called on a non-integral type, thenthis
is simply returned. Examples:assert ArrayType.INT.withSignedness(ArrayType.Signedness.UNSIGNED) == ArrayType.UINT; // INT to UINT assert ArrayType.ULONG.withSignedness(ArrayType.Signedness.SIGNED) == ArrayType.LONG; // ULONG to LONG assert ArrayType.SHORT.withSignedness(ArrayType.Signedness.SIGNED) == ArrayType.SHORT; // this: Same signs assert ArrayType.STRING.withSignedness(ArrayType.Signedness.UNSIGNED) == ArrayType.STRING; // this: Non-integral
- Parameters:
signedness
- the desired signedness of the returned ArrayType.- Returns:
- a ArrayType that is related to
this
, but with the specified signedness.
-
getTypeByName
@Nullable public static ArrayType getTypeByName(String name)
Find the ArrayType that matches this name.- Parameters:
name
- find ArrayType with this name.- Returns:
- ArrayType or null if no match.
-
forPrimitiveClass
public static ArrayType forPrimitiveClass(Class<?> c, boolean isUnsigned)
Find the ArrayType used for this primitive class type.
-
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 aBigInteger
by an unsigned conversion. In an unsigned conversion to aBigInteger
, zero and positivelong
values are mapped to a numerically equalBigInteger
value and negativelong
values are mapped to aBigInteger
value equal to the input plus 264.- Parameters:
l
- along
to treat as unsigned.- Returns:
- the equivalent
BigInteger
value.
-
unsignedIntToLong
public static long unsignedIntToLong(int i)
Converts the argument to along
by an unsigned conversion. In an unsigned conversion to along
, the high-order 32 bits of thelong
are zero and the low-order 32 bits are equal to the bits of the integer argument. Consequently, zero and positiveint
values are mapped to a numerically equallong
value and negativeint
values are mapped to along
value equal to the input plus 232.- Parameters:
i
- anint
to treat as unsigned.- Returns:
- the equivalent
long
value.
-
unsignedShortToInt
public static int unsignedShortToInt(short s)
Converts the argument to anint
by an unsigned conversion. In an unsigned conversion to anint
, the high-order 16 bits of theint
are zero and the low-order 16 bits are equal to the bits of theshort
argument. Consequently, zero and positiveshort
values are mapped to a numerically equalint
value and negativeshort
values are mapped to anint
value equal to the input plus 216.- Parameters:
s
- ashort
to treat as unsigned.- Returns:
- the equivalent
int
value.
-
unsignedByteToShort
public static short unsignedByteToShort(byte b)
Converts the argument to ashort
by an unsigned conversion. In an unsigned conversion to ashort
, the high-order 8 bits of theshort
are zero and the low-order 8 bits are equal to the bits of thebyte
argument. Consequently, zero and positivebyte
values are mapped to a numerically equalshort
value and negativebyte
values are mapped to ashort
value equal to the input plus 28.- Parameters:
b
- abyte
to treat as unsigned.- Returns:
- the equivalent
short
value.
-
-