public final class Convert
extends java.lang.Object
This class provides less type-safety than the general jOOQ API methods. For
instance, it accepts arbitrary Converter
objects in methods like
convert(Collection, Converter)
and convert(Object, Class)
,
trying to retrofit the Object
argument to the type provided in
Converter.fromType()
before performing the actual conversion.
Modifier and Type | Field and Description |
---|---|
static java.util.Set<java.lang.String> |
FALSE_VALUES
All string values that can be transformed into a boolean
false value. |
static java.util.Set<java.lang.String> |
TRUE_VALUES
All string values that can be transformed into a boolean
true value. |
Modifier and Type | Method and Description |
---|---|
static <T> java.util.List<T> |
convert(java.util.Collection<?> collection,
java.lang.Class<? extends T> type)
Convert a collection of objects to a list of
T , using
convert(Object, Class) |
static <U> java.util.List<U> |
convert(java.util.Collection<?> collection,
Converter<?,U> converter)
Convert a collection of objects to a list of
T , using
convert(Object, Converter) |
static java.lang.Object[] |
convert(java.lang.Object[] values,
java.lang.Class<?>[] types)
Convert an array of values to a matching data type
This converts
values[i] to types[i] |
static java.lang.Object[] |
convert(java.lang.Object[] values,
Field<?>[] fields)
Convert an array of values to a matching data type
This converts
values[i] to fields[i].getType() |
static <T> T |
convert(java.lang.Object from,
java.lang.Class<? extends T> toClass)
Convert an object to a type.
|
static <U> U |
convert(java.lang.Object from,
Converter<?,U> converter)
Convert an object to a type.
|
static java.lang.Object[] |
convertArray(java.lang.Object[] from,
java.lang.Class<?> toClass)
Convert an array into another one by these rules
If
toClass is not an array class, then make it an array
class first
If toClass is an array class, then create an instance
from it, and convert all elements in the from array one by
one, using convert(Object, Class)
|
static <U> U[] |
convertArray(java.lang.Object[] from,
Converter<?,U> converter)
Convert an array into another one using a converter
This uses
convertArray(Object[], Class) to convert the array to
an array of Converter.fromType() first, before converting that
array again to Converter.toType() |
public static final java.util.Set<java.lang.String> TRUE_VALUES
true
value.public static final java.util.Set<java.lang.String> FALSE_VALUES
false
value.public static final java.lang.Object[] convert(java.lang.Object[] values, Field<?>[] fields)
This converts values[i]
to fields[i].getType()
public static final java.lang.Object[] convert(java.lang.Object[] values, java.lang.Class<?>[] types)
This converts values[i]
to types[i]
public static final <U> U[] convertArray(java.lang.Object[] from, Converter<?,U> converter) throws DataTypeException
This uses convertArray(Object[], Class)
to convert the array to
an array of Converter.fromType()
first, before converting that
array again to Converter.toType()
from
- The array to convertconverter
- The data type converterDataTypeException
- - When the conversion is not possiblepublic static final java.lang.Object[] convertArray(java.lang.Object[] from, java.lang.Class<?> toClass) throws DataTypeException
toClass
is not an array class, then make it an array
class firsttoClass
is an array class, then create an instance
from it, and convert all elements in the from
array one by
one, using convert(Object, Class)
from
- The array to converttoClass
- The target array typeDataTypeException
- - When the conversion is not possiblepublic static final <U> U convert(java.lang.Object from, Converter<?,U> converter) throws DataTypeException
from
- The source objectconverter
- The data type converterDataTypeException
- - When the conversion is not possiblepublic static final <T> T convert(java.lang.Object from, java.lang.Class<? extends T> toClass) throws DataTypeException
null
is always converted to null
,
regardless of the target type.String
Object
Number
types can be converted to other
Number
typesNumber
or String
types can be converted
to Boolean
. Possible (case-insensitive) values for
true
:
1
1.0
y
yes
true
on
enabled
Possible (case-insensitive) values for false
:
0
0.0
n
no
false
off
disabled
All other values evaluate to null
Date
types can be converted into each otherString
types can be converted into URI
,
URL
and File
null
is converted into the initialisation value (e.g.
0
for int
, false
for
boolean
)byte[]
can be converted into String
, using
the platform's default charsetObject[]
can be converted into any other array type, if
array elements can be converted, tooDataTypeException
from
- The object to converttoClass
- The target typeDataTypeException
- - When the conversion is not possiblepublic static final <T> java.util.List<T> convert(java.util.Collection<?> collection, java.lang.Class<? extends T> type) throws DataTypeException
T
, using
convert(Object, Class)
collection
- The list of objectstype
- The target typeDataTypeException
- - When the conversion is not possibleconvert(Object, Class)
public static final <U> java.util.List<U> convert(java.util.Collection<?> collection, Converter<?,U> converter) throws DataTypeException
T
, using
convert(Object, Converter)
collection
- The collection of objectsconverter
- The data type converterDataTypeException
- - When the conversion is not possibleconvert(Object, Converter)
Copyright © 2015. All Rights Reserved.