Determines
whether it is possible to convert a value from one
data type to another.
Syntax
int isOKToConvert(int srcDatatype, int destDataType)
int isOKToConvert(String srcDataTypeStr, String destDataTypeStr)
Parameters
- srcDataType
- Integer returned by getType(), which represents the data type of the source
value that you want to convert.
- destDataType
- Integer returned by getType(), which represents the data type to which you
want to convert the source value.
- srcDataTypeStr
- String containing the data type name for the source value that you want to
convert. Possible values are: Boolean, boolean,
Double, double, Float, float,
Integer, int, and String.
- destDataTypeStr
- String containing the data type name to which you want to convert the
source value. Possible values are: Boolean, boolean,
Double, double, Float, float,
Integer, int, and String.
Return values
Returns an integer specifying whether it is possible to convert a value of
the source data type to a value of the destination data type. You can
interpret the return value by comparing it to one of these constants, which
are declared as static and final in the DtpDataConversion
class:
-
OKTOCONVERT
- You can convert from the source to the destination data type.
-
POTENTIALDATALOSS
- You can convert, but there is a potential for data loss if the source
value contains unconvertable characters or must be truncated to fit the
destination data type.
-
CANNOTCONVERT
- The source data type cannot be converted to the destination data
type.
Exceptions
None.
Notes
The getType() method returns an integer representing the data
type of the value you pass as a parameter. You use the first form of
isOKToConvert() together with getType() to determine
whether a data conversion between two attributes is possible. In your
isOKToConvert() method call, use getType() on both the
source and destination attributes to generate the
srcDataType and destDataType
parameters.
The second form of the method accepts String values containing the data
type names for the source and destination data. Use this form of the
method if you know what the data types are, and you want to check whether you
can perform a conversion.
Table 100 shows the possible conversions for each combination of
source and destination data type. In the table:
- OK means you can convert the source type to the destination type with no
data loss.
- DL means you can convert, but data loss might occur if the source contains
unconvertable characters or must be truncated to fit the destination
type.
- NO means you cannot convert the a value from source data type to the
destination data type.
Table 100.
Possible Conversions Between Data Types
|
|
|
| D E S T I N A T I O N
|
|
|
| SOURCE
|
int,
Integer
|
String
|
float,
Float
|
double,
Double
|
boolean
Boolean
|
Date
|
Longtext
|
int Integer
| OK
| OK
| OK
| OK
| NO
| NO
| OK
|
String
| DL1
| OK
| DL1
| DL1
| DL2
| DL
| OK
|
float, Float
| DL3
| OK
| OK
| OK
| NO
| NO
| OK
|
double, Double
| DL3
| OK
| DL3
| OK
| NO
| NO
| OK
|
boolean, Boolean
| NO
| OK
| NO
| NO
| OK
| NO
| OK
|
Date
| NO
| OK
| NO
| NO
| NO
| OK
| OK
|
Longtext
| DL1
| DL3
| DL1
| DL1
| DL2
| DL
| OK
|
| 1When converting a String or Longtext value to any numeric
type, the String or Longtext value can contain only numbers and
decimals. You must remove any other characters, such as currency
symbols, from the String or Longtext value before converting.
Otherwise, a DtpIncompatibleFormatException will be thrown.
|
| 2When converting a String or Longtext value to Boolean, the
value of the String or Longtext should be "true" or
"false". Any string that is not
"true" (case does not matter) will be considered
false.
|
| 3Because the source data type supports greater precision than
the destination data type, the value might be truncated.
|
Examples
if (DtpDataConversion.isOKToConvert(getType(mySource),
getType(myDest))== DtpDataConversion.OKTOCONVERT)
// map these attributes
else
// skip these attributes
See also
getType()
