org.datanucleus.util
Class TypeConversionHelper

java.lang.Object
  extended by org.datanucleus.util.TypeConversionHelper

public class TypeConversionHelper
extends java.lang.Object

Class with methods for type conversion.


Constructor Summary
TypeConversionHelper()
           
 
Method Summary
static java.lang.Object convertTo(java.lang.Object value, java.lang.Class type)
          Convert the value to a instance of the given type.
static java.lang.Object getBigDecimalArrayFromByteArray(byte[] buf)
          Convert a byte[] into an instance of our value class.
static java.lang.Object getBigIntegerArrayFromByteArray(byte[] buf)
          Convert a byte[] into an instance of our value class.
static java.util.BitSet getBitSetFromBooleanArray(boolean[] buf)
          Convert a boolean[] into an instance of our value class.
static boolean[] getBooleanArrayFromBitSet(java.util.BitSet value)
          Convert an instance of our value class into a boolean[].
static java.lang.Object getBooleanArrayFromByteArray(byte[] buf)
          Convert a byte[] into an instance of our value class.
static java.lang.Object getBooleanObjectArrayFromByteArray(byte[] buf)
          Convert a byte[] into an instance of our value class.
static byte[] getByteArrayFromBigDecimalArray(java.lang.Object value)
          Convert an instance of our value class into a byte[].
static byte[] getByteArrayFromBigIntegerArray(java.lang.Object value)
          Convert an instance of our value class into a byte[].
static byte[] getByteArrayFromBooleanArray(java.lang.Object value)
          Convert an instance of our value class into a byte[].
static byte[] getByteArrayFromBooleanObjectArray(java.lang.Object value)
          Convert an instance of our value class into a byte[].
static byte[] getByteArrayFromByteObjectArray(java.lang.Object value)
          Convert an instance of our value class into a byte[].
static byte[] getByteArrayFromCharArray(java.lang.Object value)
          Convert an instance of our value class into a byte[].
static byte[] getByteArrayFromCharObjectArray(java.lang.Object value)
          Convert an instance of our value class into a byte[].
static byte[] getByteArrayFromDoubleArray(java.lang.Object value)
          Convert an instance of our value class into a byte[].
static byte[] getByteArrayFromDoubleObjectArray(java.lang.Object value)
          Convert an instance of our value class into a byte[].
static byte[] getByteArrayFromFloatArray(java.lang.Object value)
          Convert an instance of our value class into a byte[].
static byte[] getByteArrayFromFloatObjectArray(java.lang.Object value)
          Convert an instance of our value class into a byte[].
static byte[] getByteArrayFromIntArray(java.lang.Object value)
          Convert an instance of our value class into a byte[].
static byte[] getByteArrayFromIntObjectArray(java.lang.Object value)
          Convert an instance of our value class into a byte[].
static byte[] getByteArrayFromLongArray(java.lang.Object value)
          Convert an instance of our value class into a byte[].
static byte[] getByteArrayFromLongObjectArray(java.lang.Object value)
          Convert an instance of our value class into a byte[].
static byte[] getByteArrayFromShortArray(java.lang.Object value)
          Convert an instance of our value class into a byte[].
static byte[] getByteArrayFromShortObjectArray(java.lang.Object value)
          Convert an instance of our value class into a byte[].
static java.lang.Object getByteObjectArrayFromByteArray(byte[] buf)
          Convert a byte[] into an instance of our value class.
static java.lang.Object getCharArrayFromByteArray(byte[] buf)
          Convert a byte[] into an instance of our value class.
static java.lang.Object getCharObjectArrayFromByteArray(byte[] buf)
          Convert a byte[] into an instance of our value class.
static java.lang.Object getDoubleArrayFromByteArray(byte[] buf)
          Convert a byte[] into an instance of our value class.
static java.lang.Object getDoubleObjectArrayFromByteArray(byte[] buf)
          Convert a byte[] into an instance of our value class.
static java.lang.Object getFloatArrayFromByteArray(byte[] buf)
          Convert a byte[] into an instance of our value class.
static java.lang.Object getFloatObjectArrayFromByteArray(byte[] buf)
          Convert a byte[] into an instance of our value class.
static java.lang.String getHexFromInt(int val)
          Utility to convert an int into a 8-char hex String
static java.lang.String getHexFromShort(short val)
          Utility to convert a short into a 4-char hex String
static java.lang.Object getIntArrayFromByteArray(byte[] buf)
          Convert a byte[] into an instance of our value class.
static int getIntFromByteArray(byte[] bytes)
          Utility to convert a byte array to an int.
static java.lang.Object getIntObjectArrayFromByteArray(byte[] buf)
          Convert a byte[] into an instance of our value class.
static java.lang.Object getLongArrayFromByteArray(byte[] buf)
          Convert a byte[] into an instance of our value class.
static java.lang.Object getLongObjectArrayFromByteArray(byte[] buf)
          Convert a byte[] into an instance of our value class.
static java.lang.Object getShortArrayFromByteArray(byte[] buf)
          Convert a byte[] into an instance of our value class.
static java.lang.Object getShortObjectArrayFromByteArray(byte[] buf)
          Convert a byte[] into an instance of our value class.
static java.lang.String getStringFromInt(int val)
          Utility to convert an int into a byte-generated String
static java.lang.String getStringFromShort(short val)
          Utility to convert a short into a byte-generated String
static int intFromString(java.lang.String str, int dflt)
          Convert a string into an integer.
static java.sql.Timestamp stringToTimestamp(java.lang.String s, java.util.Calendar cal)
          Converts a string in JDBC timestamp escape format to a Timestamp object.
static java.lang.String timestampToString(java.sql.Timestamp ts, java.util.Calendar cal)
          Formats a timestamp in JDBC timestamp escape format using the timezone of the passed Calendar.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TypeConversionHelper

public TypeConversionHelper()
Method Detail

getBooleanArrayFromBitSet

public static boolean[] getBooleanArrayFromBitSet(java.util.BitSet value)
Convert an instance of our value class into a boolean[].

Parameters:
value - Object to be converted
Returns:
converted boolean array

getBitSetFromBooleanArray

public static java.util.BitSet getBitSetFromBooleanArray(boolean[] buf)
Convert a boolean[] into an instance of our value class.

Parameters:
buf - boolean array to be converted
Returns:
converted boolean array as BitSet

getBooleanArrayFromByteArray

public static java.lang.Object getBooleanArrayFromByteArray(byte[] buf)
Convert a byte[] into an instance of our value class.

Parameters:
buf - byte array to be converted
Returns:
converted boolean array as object

getByteArrayFromBooleanArray

public static byte[] getByteArrayFromBooleanArray(java.lang.Object value)
Convert an instance of our value class into a byte[].

Parameters:
value - Object to be converted
Returns:
converted byte array

getCharArrayFromByteArray

public static java.lang.Object getCharArrayFromByteArray(byte[] buf)
Convert a byte[] into an instance of our value class.

Parameters:
buf - byte array to be converted
Returns:
converted char array as object

getByteArrayFromCharArray

public static byte[] getByteArrayFromCharArray(java.lang.Object value)
Convert an instance of our value class into a byte[].

Parameters:
value - Object to be converted
Returns:
converted byte array

getDoubleArrayFromByteArray

public static java.lang.Object getDoubleArrayFromByteArray(byte[] buf)
Convert a byte[] into an instance of our value class.

Parameters:
buf - byte array to be converted
Returns:
converted double array as object

getByteArrayFromDoubleArray

public static byte[] getByteArrayFromDoubleArray(java.lang.Object value)
Convert an instance of our value class into a byte[].

Parameters:
value - Object to be converted
Returns:
converted byte array

getFloatArrayFromByteArray

public static java.lang.Object getFloatArrayFromByteArray(byte[] buf)
Convert a byte[] into an instance of our value class.

Parameters:
buf - byte array to be converted
Returns:
converted float array as object

getByteArrayFromFloatArray

public static byte[] getByteArrayFromFloatArray(java.lang.Object value)
Convert an instance of our value class into a byte[].

Parameters:
value - Object to be converted
Returns:
converted byte array

getIntArrayFromByteArray

public static java.lang.Object getIntArrayFromByteArray(byte[] buf)
Convert a byte[] into an instance of our value class.

Parameters:
buf - byte array to be converted
Returns:
converted int array as object

getByteArrayFromIntArray

public static byte[] getByteArrayFromIntArray(java.lang.Object value)
Convert an instance of our value class into a byte[].

Parameters:
value - Object to be converted
Returns:
converted byte array

getLongArrayFromByteArray

public static java.lang.Object getLongArrayFromByteArray(byte[] buf)
Convert a byte[] into an instance of our value class.

Parameters:
buf - byte array to be converted
Returns:
converted long array as object

getByteArrayFromLongArray

public static byte[] getByteArrayFromLongArray(java.lang.Object value)
Convert an instance of our value class into a byte[].

Parameters:
value - Object to be converted
Returns:
converted byte array

getShortArrayFromByteArray

public static java.lang.Object getShortArrayFromByteArray(byte[] buf)
Convert a byte[] into an instance of our value class.

Parameters:
buf - byte array to be converted
Returns:
converted short array as object

getByteArrayFromShortArray

public static byte[] getByteArrayFromShortArray(java.lang.Object value)
Convert an instance of our value class into a byte[].

Parameters:
value - Object to be converted
Returns:
converted byte array

getByteArrayFromBigDecimalArray

public static byte[] getByteArrayFromBigDecimalArray(java.lang.Object value)
Convert an instance of our value class into a byte[].

Parameters:
value - Object to be converted
Returns:
converted byte array

getBigDecimalArrayFromByteArray

public static java.lang.Object getBigDecimalArrayFromByteArray(byte[] buf)
Convert a byte[] into an instance of our value class.

Parameters:
buf - byte array to be converted
Returns:
converted BigDecimal array as object

getByteArrayFromBigIntegerArray

public static byte[] getByteArrayFromBigIntegerArray(java.lang.Object value)
Convert an instance of our value class into a byte[].

Parameters:
value - Object to be converted
Returns:
converted byte array

getBigIntegerArrayFromByteArray

public static java.lang.Object getBigIntegerArrayFromByteArray(byte[] buf)
Convert a byte[] into an instance of our value class.

Parameters:
buf - byte array to be converted
Returns:
converted short array as object

getByteArrayFromBooleanObjectArray

public static byte[] getByteArrayFromBooleanObjectArray(java.lang.Object value)
Convert an instance of our value class into a byte[].

Parameters:
value - Boolean[] to be converted
Returns:
converted byte array

getBooleanObjectArrayFromByteArray

public static java.lang.Object getBooleanObjectArrayFromByteArray(byte[] buf)
Convert a byte[] into an instance of our value class.

Parameters:
buf - byte array to be converted
Returns:
converted Boolean array as object

getByteArrayFromByteObjectArray

public static byte[] getByteArrayFromByteObjectArray(java.lang.Object value)
Convert an instance of our value class into a byte[].

Parameters:
value - Byte[] to be converted
Returns:
converted byte array

getByteObjectArrayFromByteArray

public static java.lang.Object getByteObjectArrayFromByteArray(byte[] buf)
Convert a byte[] into an instance of our value class.

Parameters:
buf - byte array to be converted
Returns:
converted Byte array as object

getByteArrayFromCharObjectArray

public static byte[] getByteArrayFromCharObjectArray(java.lang.Object value)
Convert an instance of our value class into a byte[].

Parameters:
value - Character array to be converted
Returns:
converted byte array

getCharObjectArrayFromByteArray

public static java.lang.Object getCharObjectArrayFromByteArray(byte[] buf)
Convert a byte[] into an instance of our value class.

Parameters:
buf - byte array to be converted
Returns:
converted Character array as object

getByteArrayFromDoubleObjectArray

public static byte[] getByteArrayFromDoubleObjectArray(java.lang.Object value)
Convert an instance of our value class into a byte[].

Parameters:
value - Double array to be converted
Returns:
converted byte array

getDoubleObjectArrayFromByteArray

public static java.lang.Object getDoubleObjectArrayFromByteArray(byte[] buf)
Convert a byte[] into an instance of our value class.

Parameters:
buf - byte array to be converted
Returns:
converted Double array as object

getByteArrayFromFloatObjectArray

public static byte[] getByteArrayFromFloatObjectArray(java.lang.Object value)
Convert an instance of our value class into a byte[].

Parameters:
value - Float array to be converted
Returns:
converted byte array

getFloatObjectArrayFromByteArray

public static java.lang.Object getFloatObjectArrayFromByteArray(byte[] buf)
Convert a byte[] into an instance of our value class.

Parameters:
buf - byte array to be converted
Returns:
converted Float array as object

getByteArrayFromIntObjectArray

public static byte[] getByteArrayFromIntObjectArray(java.lang.Object value)
Convert an instance of our value class into a byte[].

Parameters:
value - Integer array to be converted
Returns:
converted byte array

getIntObjectArrayFromByteArray

public static java.lang.Object getIntObjectArrayFromByteArray(byte[] buf)
Convert a byte[] into an instance of our value class.

Parameters:
buf - byte array to be converted
Returns:
converted Integer array as object

getByteArrayFromLongObjectArray

public static byte[] getByteArrayFromLongObjectArray(java.lang.Object value)
Convert an instance of our value class into a byte[].

Parameters:
value - Long array to be converted
Returns:
converted byte array

getLongObjectArrayFromByteArray

public static java.lang.Object getLongObjectArrayFromByteArray(byte[] buf)
Convert a byte[] into an instance of our value class.

Parameters:
buf - byte array to be converted
Returns:
converted Long array as object

getByteArrayFromShortObjectArray

public static byte[] getByteArrayFromShortObjectArray(java.lang.Object value)
Convert an instance of our value class into a byte[].

Parameters:
value - Short array to be converted
Returns:
converted byte array

getShortObjectArrayFromByteArray

public static java.lang.Object getShortObjectArrayFromByteArray(byte[] buf)
Convert a byte[] into an instance of our value class.

Parameters:
buf - byte array to be converted
Returns:
converted Short array as object

convertTo

public static java.lang.Object convertTo(java.lang.Object value,
                                         java.lang.Class type)
Convert the value to a instance of the given type. The value is converted only if the type can't be assigned from the current type of the value instance.

Parameters:
value - the value to be converted
type - the type of the expected object returned from the conversion
Returns:
the converted object, or null if the object can't be converted

getStringFromInt

public static java.lang.String getStringFromInt(int val)
Utility to convert an int into a byte-generated String

Parameters:
val - The int
Returns:
The String form of the bytes

getStringFromShort

public static java.lang.String getStringFromShort(short val)
Utility to convert a short into a byte-generated String

Parameters:
val - The short
Returns:
The String form of the bytes

getHexFromInt

public static java.lang.String getHexFromInt(int val)
Utility to convert an int into a 8-char hex String

Parameters:
val - The int
Returns:
The hex String form of the int

getHexFromShort

public static java.lang.String getHexFromShort(short val)
Utility to convert a short into a 4-char hex String

Parameters:
val - The short
Returns:
The hex String form of the short

getIntFromByteArray

public static int getIntFromByteArray(byte[] bytes)
Utility to convert a byte array to an int.

Parameters:
bytes - The byte array
Returns:
The int

stringToTimestamp

public static java.sql.Timestamp stringToTimestamp(java.lang.String s,
                                                   java.util.Calendar cal)
Converts a string in JDBC timestamp escape format to a Timestamp object. To be precise, we prefer to find a JDBC escape type sequence in the format "yyyy-mm-dd hh:mm:ss.fffffffff", but this does accept other separators of fields, so as long as the numbers are in the order year, month, day, hour, minute, second then we accept it.

Parameters:
s - Timestamp string
cal - The Calendar to use for conversion
Returns:
Corresponding java.sql.Timestamp value.
Throws:
java.lang.IllegalArgumentException - Thrown if the format of the String is invalid

timestampToString

public static java.lang.String timestampToString(java.sql.Timestamp ts,
                                                 java.util.Calendar cal)
Formats a timestamp in JDBC timestamp escape format using the timezone of the passed Calendar.

Parameters:
ts - The timestamp to be formatted.
cal - The Calendar
Returns:
A String in yyyy-mm-dd hh:mm:ss.fffffffff format.
See Also:
Timestamp

intFromString

public static int intFromString(java.lang.String str,
                                int dflt)
Convert a string into an integer. Returns the default value if not convertable.

Parameters:
str - The string
dflt - The default value
Returns:
The converted int value


Copyright © 2011. All Rights Reserved.