|
Sharkysoft home | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--lava.array.ArrayCaster
Casts array elements from one type to another.
Details: ArrayCaster
casts arrays of primitives from one type to another. All casting is performed using standard Java primitive narrowing and widening conventions.
Some of the Java primitive widening and narrowing rules are strange and unintuitive. For these cases, alternate versions are provided in SignedArrayCaster
. For unsigned numeric casts, use UnsignedArrayCaster
.
The functions in this class have the following general signature:
DEST_TYPE[] toDEST_TYPE (SRC_TYPE[] src, int from, DEST_TYPE[] dest, int to, int amt)
where
If src is null
, no action is taken and null
is returned. If dest is null
, a new array is created whose length is just long enough to accomodate the requested operation, and that new array is returned.
SignedArrayCaster
,
UnsignedArrayCaster
Constructor Summary | |
ArrayCaster()
|
Method Summary | |
static int |
getPrimitiveElementType(java.lang.Object array)
Identifies primitive array type. |
static byte[] |
toBytes(char[] src,
int from,
byte[] dest,
int to,
int amt)
|
static byte[] |
toBytes(double[] src,
int from,
byte[] dest,
int to,
int amt)
|
static byte[] |
toBytes(float[] src,
int from,
byte[] dest,
int to,
int amt)
|
static byte[] |
toBytes(int[] src,
int from,
byte[] dest,
int to,
int amt)
|
static byte[] |
toBytes(long[] src,
int from,
byte[] dest,
int to,
int amt)
|
static byte[] |
toBytes(short[] src,
int from,
byte[] dest,
int to,
int amt)
|
static char[] |
toChars(byte[] src,
int from,
char[] dest,
int to,
int amt)
|
static char[] |
toChars(double[] src,
int from,
char[] dest,
int to,
int amt)
|
static char[] |
toChars(float[] src,
int from,
char[] dest,
int to,
int amt)
|
static char[] |
toChars(int[] src,
int from,
char[] dest,
int to,
int amt)
|
static char[] |
toChars(long[] src,
int from,
char[] dest,
int to,
int amt)
|
static char[] |
toChars(short[] src,
int from,
char[] dest,
int to,
int amt)
|
static double[] |
toDoubles(byte[] src,
int from,
double[] dest,
int to,
int amt)
|
static double[] |
toDoubles(char[] src,
int from,
double[] dest,
int to,
int amt)
|
static double[] |
toDoubles(float[] src,
int from,
double[] dest,
int to,
int amt)
|
static double[] |
toDoubles(int[] src,
int from,
double[] dest,
int to,
int amt)
|
static double[] |
toDoubles(long[] src,
int from,
double[] dest,
int to,
int amt)
|
static double[] |
toDoubles(short[] src,
int from,
double[] dest,
int to,
int amt)
|
static float[] |
toFloats(byte[] src,
int from,
float[] dest,
int to,
int amt)
|
static float[] |
toFloats(char[] src,
int from,
float[] dest,
int to,
int amt)
|
static float[] |
toFloats(double[] src,
int from,
float[] dest,
int to,
int amt)
|
static float[] |
toFloats(int[] src,
int from,
float[] dest,
int to,
int amt)
|
static float[] |
toFloats(long[] src,
int from,
float[] dest,
int to,
int amt)
|
static float[] |
toFloats(short[] src,
int from,
float[] dest,
int to,
int amt)
|
static int[] |
toInts(byte[] src,
int from,
int[] dest,
int to,
int amt)
|
static int[] |
toInts(char[] src,
int from,
int[] dest,
int to,
int amt)
|
static int[] |
toInts(double[] src,
int from,
int[] dest,
int to,
int amt)
|
static int[] |
toInts(float[] src,
int from,
int[] dest,
int to,
int amt)
|
static int[] |
toInts(long[] src,
int from,
int[] dest,
int to,
int amt)
|
static int[] |
toInts(short[] src,
int from,
int[] dest,
int to,
int amt)
|
static long[] |
toLongs(byte[] src,
int from,
long[] dest,
int to,
int amt)
|
static long[] |
toLongs(char[] src,
int from,
long[] dest,
int to,
int amt)
|
static long[] |
toLongs(double[] src,
int from,
long[] dest,
int to,
int amt)
|
static long[] |
toLongs(float[] src,
int from,
long[] dest,
int to,
int amt)
|
static long[] |
toLongs(int[] src,
int from,
long[] dest,
int to,
int amt)
|
static long[] |
toLongs(short[] src,
int from,
long[] dest,
int to,
int amt)
|
static short[] |
toShorts(byte[] src,
int from,
short[] dest,
int to,
int amt)
|
static short[] |
toShorts(char[] src,
int from,
short[] dest,
int to,
int amt)
|
static short[] |
toShorts(double[] src,
int from,
short[] dest,
int to,
int amt)
|
static short[] |
toShorts(float[] src,
int from,
short[] dest,
int to,
int amt)
|
static short[] |
toShorts(int[] src,
int from,
short[] dest,
int to,
int amt)
|
static short[] |
toShorts(long[] src,
int from,
short[] dest,
int to,
int amt)
|
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Constructor Detail |
public ArrayCaster()
Method Detail |
public static final double[] toDoubles(float[] src, int from, double[] dest, int to, int amt)
public static double[] toDoubles(long[] src, int from, double[] dest, int to, int amt)
public static double[] toDoubles(int[] src, int from, double[] dest, int to, int amt)
public static double[] toDoubles(short[] src, int from, double[] dest, int to, int amt)
public static double[] toDoubles(byte[] src, int from, double[] dest, int to, int amt)
public static final double[] toDoubles(char[] src, int from, double[] dest, int to, int amt)
public static final float[] toFloats(double[] src, int from, float[] dest, int to, int amt)
public static float[] toFloats(long[] src, int from, float[] dest, int to, int amt)
public static float[] toFloats(int[] src, int from, float[] dest, int to, int amt)
public static float[] toFloats(short[] src, int from, float[] dest, int to, int amt)
public static float[] toFloats(byte[] src, int from, float[] dest, int to, int amt)
public static final float[] toFloats(char[] src, int from, float[] dest, int to, int amt)
public static long[] toLongs(double[] src, int from, long[] dest, int to, int amt)
public static long[] toLongs(float[] src, int from, long[] dest, int to, int amt)
public static long[] toLongs(int[] src, int from, long[] dest, int to, int amt)
public static long[] toLongs(short[] src, int from, long[] dest, int to, int amt)
public static long[] toLongs(byte[] src, int from, long[] dest, int to, int amt)
public static final long[] toLongs(char[] src, int from, long[] dest, int to, int amt)
public static int[] toInts(double[] src, int from, int[] dest, int to, int amt)
public static int[] toInts(float[] src, int from, int[] dest, int to, int amt)
public static final int[] toInts(long[] src, int from, int[] dest, int to, int amt)
public static int[] toInts(short[] src, int from, int[] dest, int to, int amt)
public static int[] toInts(byte[] src, int from, int[] dest, int to, int amt)
public static final int[] toInts(char[] src, int from, int[] dest, int to, int amt)
public static short[] toShorts(double[] src, int from, short[] dest, int to, int amt)
public static short[] toShorts(float[] src, int from, short[] dest, int to, int amt)
public static final short[] toShorts(long[] src, int from, short[] dest, int to, int amt)
public static final short[] toShorts(int[] src, int from, short[] dest, int to, int amt)
public static short[] toShorts(byte[] src, int from, short[] dest, int to, int amt)
public static final short[] toShorts(char[] src, int from, short[] dest, int to, int amt)
public static byte[] toBytes(double[] src, int from, byte[] dest, int to, int amt)
public static byte[] toBytes(float[] src, int from, byte[] dest, int to, int amt)
public static byte[] toBytes(long[] src, int from, byte[] dest, int to, int amt)
public static final byte[] toBytes(int[] src, int from, byte[] dest, int to, int amt)
public static final byte[] toBytes(short[] src, int from, byte[] dest, int to, int amt)
public static final byte[] toBytes(char[] src, int from, byte[] dest, int to, int amt)
public static char[] toChars(double[] src, int from, char[] dest, int to, int amt)
public static char[] toChars(float[] src, int from, char[] dest, int to, int amt)
public static final char[] toChars(long[] src, int from, char[] dest, int to, int amt)
public static final char[] toChars(int[] src, int from, char[] dest, int to, int amt)
public static final char[] toChars(short[] src, int from, char[] dest, int to, int amt)
public static char[] toChars(byte[] src, int from, char[] dest, int to, int amt)
public static int getPrimitiveElementType(java.lang.Object array)
Details: This method determines which primitive type the elements in this array are, and returns a value as follows:
array type | returns |
---|---|
boolean[] | 0 |
byte[] | 1 |
short[] | 2 |
char[] | 3 |
int[] | 4 |
long[] | 8 |
float[] | 6 |
double[] | 10 |
anything else, including null |
-1 |
Note that for byte[]
, short[]
, int[]
, and long[]
, the return value is the size of the element type in bytes.
array
- the array
|
Sharkysoft home | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |