Sharkysoft home

lava.array
Class ArrayCaster

java.lang.Object
  |
  +--lava.array.ArrayCaster
Direct Known Subclasses:
BooleanArrayCaster, SignedArrayCaster, UnsignedArrayCaster

public abstract class ArrayCaster
extends java.lang.Object

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

SRC_TYPE
is the primitive type of the source array (byte, short, int, float, etc.)
src
is the source array
from
is the starting index in the source array
DEST_TYPE
is the primitive type of the destination array (byte, short, int, float, etc.)
dest
is the destination array
to
is the starting index in the destination array
amt
is the number of elements from the source array to cast
the return value
is dest, returned for convenience

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.

Since:
1998.05.27
Version:
1999.09.11
See Also:
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

ArrayCaster

public ArrayCaster()
Method Detail

toDoubles

public static final double[] toDoubles(float[] src,
                                       int from,
                                       double[] dest,
                                       int to,
                                       int amt)

toDoubles

public static double[] toDoubles(long[] src,
                                 int from,
                                 double[] dest,
                                 int to,
                                 int amt)

toDoubles

public static double[] toDoubles(int[] src,
                                 int from,
                                 double[] dest,
                                 int to,
                                 int amt)

toDoubles

public static double[] toDoubles(short[] src,
                                 int from,
                                 double[] dest,
                                 int to,
                                 int amt)

toDoubles

public static double[] toDoubles(byte[] src,
                                 int from,
                                 double[] dest,
                                 int to,
                                 int amt)

toDoubles

public static final double[] toDoubles(char[] src,
                                       int from,
                                       double[] dest,
                                       int to,
                                       int amt)

toFloats

public static final float[] toFloats(double[] src,
                                     int from,
                                     float[] dest,
                                     int to,
                                     int amt)

toFloats

public static float[] toFloats(long[] src,
                               int from,
                               float[] dest,
                               int to,
                               int amt)

toFloats

public static float[] toFloats(int[] src,
                               int from,
                               float[] dest,
                               int to,
                               int amt)

toFloats

public static float[] toFloats(short[] src,
                               int from,
                               float[] dest,
                               int to,
                               int amt)

toFloats

public static float[] toFloats(byte[] src,
                               int from,
                               float[] dest,
                               int to,
                               int amt)

toFloats

public static final float[] toFloats(char[] src,
                                     int from,
                                     float[] dest,
                                     int to,
                                     int amt)

toLongs

public static long[] toLongs(double[] src,
                             int from,
                             long[] dest,
                             int to,
                             int amt)

toLongs

public static long[] toLongs(float[] src,
                             int from,
                             long[] dest,
                             int to,
                             int amt)

toLongs

public static long[] toLongs(int[] src,
                             int from,
                             long[] dest,
                             int to,
                             int amt)

toLongs

public static long[] toLongs(short[] src,
                             int from,
                             long[] dest,
                             int to,
                             int amt)

toLongs

public static long[] toLongs(byte[] src,
                             int from,
                             long[] dest,
                             int to,
                             int amt)

toLongs

public static final long[] toLongs(char[] src,
                                   int from,
                                   long[] dest,
                                   int to,
                                   int amt)

toInts

public static int[] toInts(double[] src,
                           int from,
                           int[] dest,
                           int to,
                           int amt)

toInts

public static int[] toInts(float[] src,
                           int from,
                           int[] dest,
                           int to,
                           int amt)

toInts

public static final int[] toInts(long[] src,
                                 int from,
                                 int[] dest,
                                 int to,
                                 int amt)

toInts

public static int[] toInts(short[] src,
                           int from,
                           int[] dest,
                           int to,
                           int amt)

toInts

public static int[] toInts(byte[] src,
                           int from,
                           int[] dest,
                           int to,
                           int amt)

toInts

public static final int[] toInts(char[] src,
                                 int from,
                                 int[] dest,
                                 int to,
                                 int amt)

toShorts

public static short[] toShorts(double[] src,
                               int from,
                               short[] dest,
                               int to,
                               int amt)

toShorts

public static short[] toShorts(float[] src,
                               int from,
                               short[] dest,
                               int to,
                               int amt)

toShorts

public static final short[] toShorts(long[] src,
                                     int from,
                                     short[] dest,
                                     int to,
                                     int amt)

toShorts

public static final short[] toShorts(int[] src,
                                     int from,
                                     short[] dest,
                                     int to,
                                     int amt)

toShorts

public static short[] toShorts(byte[] src,
                               int from,
                               short[] dest,
                               int to,
                               int amt)

toShorts

public static final short[] toShorts(char[] src,
                                     int from,
                                     short[] dest,
                                     int to,
                                     int amt)

toBytes

public static byte[] toBytes(double[] src,
                             int from,
                             byte[] dest,
                             int to,
                             int amt)

toBytes

public static byte[] toBytes(float[] src,
                             int from,
                             byte[] dest,
                             int to,
                             int amt)

toBytes

public static byte[] toBytes(long[] src,
                             int from,
                             byte[] dest,
                             int to,
                             int amt)

toBytes

public static final byte[] toBytes(int[] src,
                                   int from,
                                   byte[] dest,
                                   int to,
                                   int amt)

toBytes

public static final byte[] toBytes(short[] src,
                                   int from,
                                   byte[] dest,
                                   int to,
                                   int amt)

toBytes

public static final byte[] toBytes(char[] src,
                                   int from,
                                   byte[] dest,
                                   int to,
                                   int amt)

toChars

public static char[] toChars(double[] src,
                             int from,
                             char[] dest,
                             int to,
                             int amt)

toChars

public static char[] toChars(float[] src,
                             int from,
                             char[] dest,
                             int to,
                             int amt)

toChars

public static final char[] toChars(long[] src,
                                   int from,
                                   char[] dest,
                                   int to,
                                   int amt)

toChars

public static final char[] toChars(int[] src,
                                   int from,
                                   char[] dest,
                                   int to,
                                   int amt)

toChars

public static final char[] toChars(short[] src,
                                   int from,
                                   char[] dest,
                                   int to,
                                   int amt)

toChars

public static char[] toChars(byte[] src,
                             int from,
                             char[] dest,
                             int to,
                             int amt)

getPrimitiveElementType

public static int getPrimitiveElementType(java.lang.Object array)
Identifies primitive array type.

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.

Parameters:
array - the array
Returns:
the array type if elements are primitive
Since:
1999.08.26

Sharkysoft home