Package org.eclipse.birt.core.data
Class DataTypeUtil
- java.lang.Object
-
- org.eclipse.birt.core.data.DataTypeUtil
-
public final class DataTypeUtil extends java.lang.Object
A utility function The convert method converts the source object, which can be any supported data type, into an object given specified type. If no reasonable conversion can be made, throw a BirtException.
-
-
Field Summary
Fields Modifier and Type Field Description static long
count
static java.util.ResourceBundle
resourceBundle
-
Constructor Summary
Constructors Constructor Description DataTypeUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.lang.Object
convert(java.lang.Object source, int toType)
convert an object to given type Types supported: DataType.INTEGER_TYPE DataType.DECIMAL_TYPE DataType.BOOLEAN_TYPE DataType.DATE_TYPE DataType.DOUBLE_TYPE DataType.STRING_TYPE DataType.BLOB_TYPE DataType.SQL_DATE_TYPE DataType.SQL_TIME_TYPEstatic java.lang.Object
convert(java.lang.Object source, java.lang.Class toTypeClass)
convert a object to given class Classes supported: Integer.class BigDecimal.class Boolean.class Time.class Date.class Double.class String.class Blob.classstatic java.lang.Class
fromApiDataTypeToJavaClass(int apiDataType)
static java.lang.String
getDateFormat(java.lang.String source)
Find the date format pattern string for a given datetime string without specified locale.static com.ibm.icu.text.DateFormat
getDateFormat(java.lang.String source, com.ibm.icu.util.ULocale locale, com.ibm.icu.util.TimeZone timeZone)
Deprecated.use getDateFormatObject insteadstatic com.ibm.icu.text.DateFormat
getDateFormatObject(java.lang.String source, com.ibm.icu.util.ULocale locale, com.ibm.icu.util.TimeZone timeZone)
Retrieve date format object that matches the given date/time stringstatic int
toApiDataType(int odaDataTypeCode)
Converts an ODA data type code to its corresponding Data Engine API data type constant defined in DataType.static int
toApiDataType(java.lang.Class clazz)
Converts a Java class to its corresponding data type constant defined in DataTypestatic java.lang.Object
toAutoValue(java.lang.Object evaValue)
Convert object to a suitable type from its value Object -> Integer -> Double -> BigDecimal -> Date -> Stringstatic java.math.BigDecimal
toBigDecimal(java.lang.Object source)
Boolean -> BigDecimal true -> 1 others -> 0 Date -> BigDecimal Date.getTime(); String -> BigDecimal new BigDecimal(String);static java.sql.Blob
toBlob(java.lang.Object source)
Converting Blob to/from other types is not currently supportedstatic java.lang.Boolean
toBoolean(java.lang.Object source)
Number -> Boolean 0 -> false others -> true String -> Boolean "true" -> true (ignore case) "false" -> false (ignore case) other string will throw an exception Date -> Boolean throw exceptionstatic byte[]
toBytes(java.lang.Object source)
static java.util.Date
toDate(java.lang.Object source)
Number -> Date new Date((long)Number) String -> Date toDate(String)static java.util.Date
toDate(java.lang.String source, com.ibm.icu.util.TimeZone timeZone)
Convert a string to a Date instance according to the TimeZone valuestatic java.util.Date
toDate(java.lang.String source, com.ibm.icu.util.ULocale locale)
convert String with the specified locale to java.util.Datestatic java.util.Date
toDate(java.lang.String source, com.ibm.icu.util.ULocale locale, com.ibm.icu.util.TimeZone timeZone)
Parses a date/time stringstatic java.util.Date
toDate(java.lang.String source, java.util.Locale locale)
A temp solution to the adoption of ICU4J to BIRT.static java.util.Date
toDateWithCheck(java.lang.String source, com.ibm.icu.util.ULocale locale)
Convert string to date with check.static java.util.Date
toDateWithCheck(java.lang.String source, java.util.Locale locale)
A temp solution to the adoption of ICU4J in BIRT.static java.lang.Double
toDouble(java.lang.Object source)
Boolean -> Double true -> 1 others -> 0 Date -> Double Date.getTime(); String -> Double Double.valueOf(String);static java.lang.Double
toDouble(java.lang.Object source, com.ibm.icu.util.ULocale locale)
static java.lang.Double
toDouble(java.lang.Object source, java.util.Locale locale)
static java.lang.Integer
toInteger(java.lang.Object source)
Boolean -> Integer true -> 1 others -> 0 Date -> Integer Date.getTime(); String -> Integer Integer.valueOf();static java.lang.Integer
toInteger(java.lang.Object source, com.ibm.icu.util.ULocale locale)
Boolean -> Integer true -> 1 others -> 0 Date -> Integer Date.getTime(); String -> Integer Integer.valueOf();static java.lang.Integer
toIntegerValue(java.lang.Object evaValue)
convert object to Integer.static java.lang.String
toLocaleNeutralString(java.lang.Object source)
Convert an object to an locale neutral String value.static java.lang.String
toLocaleNeutralString(java.lang.Object source, com.ibm.icu.util.TimeZone zone)
Convert an object to an locale neutral String value.static int
toOdaDataType(java.lang.Class odiTypeClass)
Converts an ODI type class to its corresponding ODA data type code.static java.lang.Class
toOdiTypeClass(int odaDataTypeCode)
Converts an ODA data type code to the Java class of its corresponding Data Engine ODI data type.static java.sql.Date
toSqlDate(java.lang.Object source)
Date -> Time String -> Timestatic java.sql.Time
toSqlTime(java.lang.Object source)
Date -> Time String -> Timestatic java.lang.String
toString(java.lang.Object source)
Number -> String Number.toString() Boolean -> String Boolean.toString() Date -> String toString(Date)static java.lang.String
toString(java.lang.Object source, com.ibm.icu.util.ULocale locale)
Number -> String Number.toString() Boolean -> String Boolean.toString() Date -> String toString(Date,locale)static java.lang.String
toString(java.lang.Object source, java.util.Locale locale)
A temp solution to the adoption of ICU4J.static java.sql.Timestamp
toTimestamp(java.lang.Object source)
-
-
-
Method Detail
-
convert
public static java.lang.Object convert(java.lang.Object source, int toType) throws BirtException
convert an object to given type Types supported: DataType.INTEGER_TYPE DataType.DECIMAL_TYPE DataType.BOOLEAN_TYPE DataType.DATE_TYPE DataType.DOUBLE_TYPE DataType.STRING_TYPE DataType.BLOB_TYPE DataType.SQL_DATE_TYPE DataType.SQL_TIME_TYPE- Parameters:
source
-toType
-- Returns:
- Throws:
BirtException
-
convert
public static java.lang.Object convert(java.lang.Object source, java.lang.Class toTypeClass) throws BirtException
convert a object to given class Classes supported: Integer.class BigDecimal.class Boolean.class Time.class Date.class Double.class String.class Blob.class- Parameters:
source
-toTypeClass
-- Returns:
- Throws:
BirtException
-
toInteger
public static java.lang.Integer toInteger(java.lang.Object source) throws BirtException
Boolean -> Integer true -> 1 others -> 0 Date -> Integer Date.getTime(); String -> Integer Integer.valueOf();- Parameters:
source
-- Returns:
- Throws:
BirtException
-
toInteger
public static java.lang.Integer toInteger(java.lang.Object source, com.ibm.icu.util.ULocale locale) throws BirtException
Boolean -> Integer true -> 1 others -> 0 Date -> Integer Date.getTime(); String -> Integer Integer.valueOf();- Parameters:
source
-locale
- Locale- Returns:
- Throws:
BirtException
-
toBigDecimal
public static java.math.BigDecimal toBigDecimal(java.lang.Object source) throws BirtException
Boolean -> BigDecimal true -> 1 others -> 0 Date -> BigDecimal Date.getTime(); String -> BigDecimal new BigDecimal(String);- Parameters:
source
-- Returns:
- Throws:
BirtException
-
toBoolean
public static java.lang.Boolean toBoolean(java.lang.Object source) throws BirtException
Number -> Boolean 0 -> false others -> true String -> Boolean "true" -> true (ignore case) "false" -> false (ignore case) other string will throw an exception Date -> Boolean throw exception- Parameters:
source
-- Returns:
- Throws:
BirtException
-
toDate
public static java.util.Date toDate(java.lang.Object source) throws BirtException
Number -> Date new Date((long)Number) String -> Date toDate(String)- Parameters:
source
-- Returns:
- Throws:
BirtException
-
toTimestamp
public static java.sql.Timestamp toTimestamp(java.lang.Object source) throws BirtException
- Parameters:
source
-- Returns:
- Throws:
BirtException
-
toSqlTime
public static java.sql.Time toSqlTime(java.lang.Object source) throws BirtException
Date -> Time String -> Time- Parameters:
source
-- Returns:
- Throws:
BirtException
-
toSqlDate
public static java.sql.Date toSqlDate(java.lang.Object source) throws BirtException
Date -> Time String -> Time- Parameters:
source
-- Returns:
- Throws:
BirtException
-
toDate
public static java.util.Date toDate(java.lang.String source, java.util.Locale locale) throws BirtException
A temp solution to the adoption of ICU4J to BIRT. Simply delegate toDate( String, Locale) method.- Parameters:
source
- the String to be convertlocate
- the locate of the string- Returns:
- result Date
- Throws:
BirtException
-
toDate
public static java.util.Date toDate(java.lang.String source, com.ibm.icu.util.ULocale locale) throws BirtException
convert String with the specified locale to java.util.Date- Parameters:
source
- the String to be convertlocate
- the locate of the string- Returns:
- result Date
- Throws:
BirtException
-
toDate
public static java.util.Date toDate(java.lang.String source, com.ibm.icu.util.ULocale locale, com.ibm.icu.util.TimeZone timeZone) throws BirtException
Parses a date/time string- Parameters:
source
-locale
-timeZone
-- Returns:
- Throws:
BirtException
-
getDateFormat
@Deprecated public static com.ibm.icu.text.DateFormat getDateFormat(java.lang.String source, com.ibm.icu.util.ULocale locale, com.ibm.icu.util.TimeZone timeZone) throws BirtException
Deprecated.use getDateFormatObject instead- Throws:
BirtException
-
getDateFormatObject
public static com.ibm.icu.text.DateFormat getDateFormatObject(java.lang.String source, com.ibm.icu.util.ULocale locale, com.ibm.icu.util.TimeZone timeZone) throws BirtException
Retrieve date format object that matches the given date/time string- Parameters:
source
-locale
-timeZone
-- Returns:
- Throws:
BirtException
- Since:
- 4.8
-
toDate
public static java.util.Date toDate(java.lang.String source, com.ibm.icu.util.TimeZone timeZone) throws BirtException
Convert a string to a Date instance according to the TimeZone value- Parameters:
source
-timeZone
-- Returns:
- Throws:
BirtException
-
toDateWithCheck
public static java.util.Date toDateWithCheck(java.lang.String source, java.util.Locale locale) throws BirtException
A temp solution to the adoption of ICU4J in BIRT. It is a simple delegation to toDateWithCheck( String, Locale ).- Parameters:
source
-locale
-- Returns:
- Date
- Throws:
BirtException
-
toDateWithCheck
public static java.util.Date toDateWithCheck(java.lang.String source, com.ibm.icu.util.ULocale locale) throws BirtException
Convert string to date with check. JDK may do incorrect converse, for example: 2005/1/1 Local.US, format pattern is MM/dd/YY. Above conversion can be done without error, but obviously the result is not right. This method will do such a simple check, in DateFormat.SHORT case instead of all cases. Year is not lower than 0. Month is from 1 to 12. Day is from 1 to 31.- Parameters:
source
-locale
-- Returns:
- Date
- Throws:
BirtException
-
toDouble
public static java.lang.Double toDouble(java.lang.Object source, java.util.Locale locale) throws CoreException
- Throws:
CoreException
-
toDouble
public static java.lang.Double toDouble(java.lang.Object source, com.ibm.icu.util.ULocale locale) throws CoreException
- Throws:
CoreException
-
toDouble
public static java.lang.Double toDouble(java.lang.Object source) throws BirtException
Boolean -> Double true -> 1 others -> 0 Date -> Double Date.getTime(); String -> Double Double.valueOf(String);- Parameters:
source
-- Returns:
- Throws:
BirtException
-
toString
public static java.lang.String toString(java.lang.Object source) throws BirtException
Number -> String Number.toString() Boolean -> String Boolean.toString() Date -> String toString(Date)- Parameters:
source
-- Returns:
- Throws:
BirtException
-
toString
public static java.lang.String toString(java.lang.Object source, java.util.Locale locale) throws BirtException
A temp solution to the adoption of ICU4J. It is a simple delegation to toString( Object, Locale ).- Parameters:
source
-- Returns:
- Throws:
BirtException
-
toLocaleNeutralString
public static java.lang.String toLocaleNeutralString(java.lang.Object source, com.ibm.icu.util.TimeZone zone) throws BirtException
Convert an object to an locale neutral String value. For Date values we will convert to ISO8601 format. User can specify the time zone to output.- Parameters:
source
-zone
-- Returns:
- Throws:
BirtException
-
toLocaleNeutralString
public static java.lang.String toLocaleNeutralString(java.lang.Object source) throws BirtException
Convert an object to an locale neutral String value. For Date values we will convert to ISO8601 format. This will always output default(current) time zone.- Parameters:
source
-- Returns:
- Throws:
BirtException
-
toString
public static java.lang.String toString(java.lang.Object source, com.ibm.icu.util.ULocale locale) throws BirtException
Number -> String Number.toString() Boolean -> String Boolean.toString() Date -> String toString(Date,locale)- Parameters:
source
-- Returns:
- Throws:
BirtException
-
toBlob
public static java.sql.Blob toBlob(java.lang.Object source) throws BirtException
Converting Blob to/from other types is not currently supported- Parameters:
source
-- Returns:
- Throws:
BirtException
-
toBytes
public static byte[] toBytes(java.lang.Object source) throws BirtException
- Parameters:
source
-- Returns:
- byte array
- Throws:
BirtException
-
toApiDataType
public static int toApiDataType(java.lang.Class clazz)
Converts a Java class to its corresponding data type constant defined in DataType
-
fromApiDataTypeToJavaClass
public static java.lang.Class fromApiDataTypeToJavaClass(int apiDataType)
-
toApiDataType
public static int toApiDataType(int odaDataTypeCode) throws BirtException
Converts an ODA data type code to its corresponding Data Engine API data type constant defined in DataType.- Parameters:
odaDataTypeCode
- an ODA data type code- Throws:
BirtException
- if the specified ODA data type code is not a supported type
-
toAutoValue
public static java.lang.Object toAutoValue(java.lang.Object evaValue)
Convert object to a suitable type from its value Object -> Integer -> Double -> BigDecimal -> Date -> String
-
toIntegerValue
public static java.lang.Integer toIntegerValue(java.lang.Object evaValue)
convert object to Integer. If fails, return null. Object -> Integer
-
getDateFormat
public static java.lang.String getDateFormat(java.lang.String source) throws BirtException
Find the date format pattern string for a given datetime string without specified locale. If a suitable date format cannot be found or the pattern string cannot be retrieved, returns null- Parameters:
source
-- Returns:
- Throws:
BirtException
- Since:
- 4.8
-
toOdiTypeClass
public static java.lang.Class toOdiTypeClass(int odaDataTypeCode) throws BirtException
Converts an ODA data type code to the Java class of its corresponding Data Engine ODI data type.
ODA Data Type -> ODI Type Class
Integer -> java.lang.Integer
Double -> java.lang.Double
Character -> java.lang.String
Decimal -> java.math.BigDecimal
Date -> java.sql.Date
Time -> java.sql.Time
Timestamp -> java.sql.Timestamp
Blob -> java.sql.Blob
Clob -> java.sql.Clob
Boolean -> java.lang.Boolean
JavaObject -> java.lang.Object
- Parameters:
odaDataTypeCode
- an ODA data type code- Returns:
- the ODI type class that corresponds with the specified ODA data type
- Throws:
BirtException
- if the specified ODA data type is not a supported type
-
toOdaDataType
public static int toOdaDataType(java.lang.Class odiTypeClass)
Converts an ODI type class to its corresponding ODA data type code.
ODI Type Class -> ODA Data Type
java.lang.Integer -> Integer
java.lang.Double -> Double
java.lang.String -> Character
java.math.BigDecimal -> Decimal
java.util.Date -> Timestamp
java.sql.Date -> Date
java.sql.Time -> Time
java.sql.Timestamp -> Timestamp
java.sql.Blob -> Blob
java.sql.Clob -> Clob
java.lang.Boolean -> Boolean
java.lang.Object -> JavaObject
All other type classes are mapped to the ODA String data type.- Parameters:
odiTypeClass
- a type class used by the Data Engine ODI component- Returns:
- the ODA data type that maps to the ODI type class.
-
-