Class ncsa.horizon.util.JavaType
All Packages Class Hierarchy This Package Previous Next Index
Class ncsa.horizon.util.JavaType
java.lang.Object
|
+----ncsa.horizon.util.JavaType
- public final class JavaType
- extends Object
This class represents java primitive type information. It cannot be
instantiated but contains 8 primitive public final static type and
1 object public final static type. It
also provide a rich set of methods to automatically wrap and unwrap
java primitive data, to create primitive data array, to access primitive
data array.
The necessities of this class are justified in several situations.
1. Suppose a number wrapper nWrapper is returned, but the wrapper
is not know of its type.
If we somehow get its corresponding JavaType jType, we can call
jType.value(nWrapper) to get the value. It is especially useful
in wide conversion.
2. Allocate a 1-d array of corresponding primitive data type.
JDK1.1 provides 9 final static types, which have most of the functionalities
of JavaType's 8 static types. However, if you want to allocate a 1-d
array of corresponding primitive data type, JavaType is the way to go.
-
BOOLEAN
- code: 1, name: "boolean", className: "Java.Lang.Boolean"
data size: unknown
-
BYTE
- code: 3, name: "byte", className: "Java.Lang.Integer"
data size: 8
-
CHAR
- code: 2, name: "char", className: "Java.Lang.Character"
data size: 16
-
DOUBLE
- code: 8, name: "double", className: "Java.Lang.Double"
data size: 64
-
FLOAT
- code: 7, name: "float", className: "Java.Lang.Float"
data size: 32
-
INT
- code: 5, name: "int", className: "Java.Lang.Integer"
data size: 32
-
LONG
- code: 6, name: "long", className: "Java.Lang.Long"
data size: 64
-
OBJECT
- code: 9, name: "Object", className: "Java.Lang.Object"
data size: unknown
-
SHORT
- code: 4, name: "short", className: "Java.Lang.Integer"
data size: 16
-
allocateArray(int)
- Creates a new array with the specified length.
-
className()
-
-
code()
- Provide a code to each array for the purpose of switch.
-
isSizeKnown()
-
-
name()
-
-
setArray(Object, int, Object)
- Set the element of array at index to be value of the wrapper
-
size()
- Returns the type memory saving length.
-
value(Boolean)
-
-
value(Character)
-
-
value(Double)
-
-
value(Float)
-
-
value(Integer)
-
-
value(Long)
-
-
wrap(boolean)
- The overloading methods wrap corresponding
primitive data type, and returns the wrapper.
-
wrap(byte)
- The overloading methods wrap corresponding
primitive data type, and returns the wrapper.
-
wrap(char)
- The overloading methods wrap corresponding
primitive data type, and returns the wrapper.
-
wrap(double)
- The overloading methods wrap corresponding
primitive data type, and returns the wrapper.
-
wrap(float)
- The overloading methods wrap corresponding
primitive data type, and returns the wrapper.
-
wrap(int)
- The overloading methods wrap corresponding
primitive data type, and returns the wrapper.
-
wrap(long)
- The overloading methods wrap corresponding
primitive data type, and returns the wrapper.
-
wrap(short)
- The overloading methods wrap corresponding
primitive data type, and returns the wrapper.
-
wrappedValueFromArray(Object, int)
-
BOOLEAN
public final static JavaType BOOLEAN
- code: 1, name: "boolean", className: "Java.Lang.Boolean"
data size: unknown
CHAR
public final static JavaType CHAR
- code: 2, name: "char", className: "Java.Lang.Character"
data size: 16
BYTE
public final static JavaType BYTE
- code: 3, name: "byte", className: "Java.Lang.Integer"
data size: 8
SHORT
public final static JavaType SHORT
- code: 4, name: "short", className: "Java.Lang.Integer"
data size: 16
INT
public final static JavaType INT
- code: 5, name: "int", className: "Java.Lang.Integer"
data size: 32
LONG
public final static JavaType LONG
- code: 6, name: "long", className: "Java.Lang.Long"
data size: 64
FLOAT
public final static JavaType FLOAT
- code: 7, name: "float", className: "Java.Lang.Float"
data size: 32
DOUBLE
public final static JavaType DOUBLE
- code: 8, name: "double", className: "Java.Lang.Double"
data size: 64
OBJECT
public final static JavaType OBJECT
- code: 9, name: "Object", className: "Java.Lang.Object"
data size: unknown
allocateArray
public Object allocateArray(int length) throws OutOfMemoryError
- Creates a new array with the specified length. The new array
is with primitive type represented by this object.
code
public int code()
- Provide a code to each array for the purpose of switch.
The code for the types are:
1 for JavaType.BOOLEAN
2 for JavaType.CHAR
3 for JavaType.BYTE
4 for JavaType.SHORT
5 for JavaType.INT
6 for JavaType.LONG
7 for JavaType.FLOAT
8 for JavaType.DOUBLE
9 for JavaType.OBJECT
name
public String name()
className
public String className()
setArray
public void setArray(Object array,
int index,
Object wrapper)
- Set the element of array at index to be value of the wrapper
size
public int size() throws NoSuchElementException
- Returns the type memory saving length.
If the length is unknow, java.util.NoSuchElementException will
be thrown.
isSizeKnown
public boolean isSizeKnown()
value
public boolean value(Boolean wrapper)
value
public char value(Character wrapper)
value
public int value(Integer wrapper)
value
public long value(Long wrapper)
value
public float value(Float wrapper)
value
public double value(Double wrapper)
wrap
public Boolean wrap(boolean value)
- The overloading methods wrap corresponding
primitive data type, and returns the wrapper.
Since no Byte for byte and no Short for
short in JDK1.02, byte and short are wrapped
in Integer.
If this javaType is asked to wrap a data with
other data type, NumberFormatException is thrown.
wrap
public Character wrap(char value)
- The overloading methods wrap corresponding
primitive data type, and returns the wrapper.
Since no Byte for byte and no Short for
short in JDK1.02, byte and short are wrapped
in Integer.
If this javaType is asked to wrap a data with
other data type, NumberFormatException is thrown.
wrap
public Integer wrap(byte value)
- The overloading methods wrap corresponding
primitive data type, and returns the wrapper.
Since no Byte for byte and no Short for
short in JDK1.02, byte and short are wrapped
in Integer.
If this javaType is asked to wrap a data with
other data type, NumberFormatException is thrown.
wrap
public Integer wrap(short value)
- The overloading methods wrap corresponding
primitive data type, and returns the wrapper.
Since no Byte for byte and no Short for
short in JDK1.02, byte and short are wrapped
in Integer.
If this javaType is asked to wrap a data with
other data type, NumberFormatException is thrown.
wrap
public Integer wrap(int value)
- The overloading methods wrap corresponding
primitive data type, and returns the wrapper.
Since no Byte for byte and no Short for
short in JDK1.02, byte and short are wrapped
in Integer.
If this javaType is asked to wrap a data with
other data type, NumberFormatException is thrown.
wrap
public Long wrap(long value)
- The overloading methods wrap corresponding
primitive data type, and returns the wrapper.
Since no Byte for byte and no Short for
short in JDK1.02, byte and short are wrapped
in Integer.
If this javaType is asked to wrap a data with
other data type, NumberFormatException is thrown.
wrap
public Float wrap(float value)
- The overloading methods wrap corresponding
primitive data type, and returns the wrapper.
Since no Byte for byte and no Short for
short in JDK1.02, byte and short are wrapped
in Integer.
If this javaType is asked to wrap a data with
other data type, NumberFormatException is thrown.
wrap
public Double wrap(double value)
- The overloading methods wrap corresponding
primitive data type, and returns the wrapper.
Since no Byte for byte and no Short for
short in JDK1.02, byte and short are wrapped
in Integer.
If this javaType is asked to wrap a data with
other data type, NumberFormatException is thrown.
wrappedValueFromArray
public Object wrappedValueFromArray(Object array,
int index)
All Packages Class Hierarchy This Package Previous Next Index