org.jooq.tools
Class Convert

java.lang.Object
  extended by org.jooq.tools.Convert

public final class Convert
extends Object

Utility methods for type conversions

This class provides less type-safety than the general jOOQ API methods. For instance, it accepts arbitrary Converter objects in methods like convert(List, Converter) and convert(Object, Class), trying to retrofit the Object argument to the type provided in Converter.fromType() before performing the actual conversion.

Author:
Lukas Eder

Field Summary
static Set<String> FALSE_VALUES
           
static Set<String> TRUE_VALUES
           
 
Method Summary
static
<T> List<T>
convert(List<?> list, Class<? extends T> type)
          Convert a list of objects to a list of T, using convert(Object, Class)
static
<U> List<U>
convert(List<?> list, Converter<?,U> converter)
          Convert a list of objects to a list of T, using convert(Object, Converter)
static
<T> T
convert(Object from, Class<? extends T> toClass)
          Convert an object to a type.
static
<U> U
convert(Object from, Converter<?,U> converter)
          Convert an object to a type.
static Object[] convertArray(Object[] from, 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(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()
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRUE_VALUES

public static final Set<String> TRUE_VALUES

FALSE_VALUES

public static final Set<String> FALSE_VALUES
Method Detail

convertArray

public static <U> U[] convertArray(Object[] from,
                                   Converter<?,U> converter)
                        throws DataTypeException
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()

Parameters:
from - The array to convert
converter - The data type converter
Returns:
A converted array
Throws:
DataTypeException - - When the conversion is not possible

convertArray

public static Object[] convertArray(Object[] from,
                                    Class<?> toClass)
                             throws DataTypeException
Convert an array into another one by these rules

Parameters:
from - The array to convert
toClass - The target array type
Returns:
A converted array
Throws:
DataTypeException - - When the conversion is not possible

convert

public static <U> U convert(Object from,
                            Converter<?,U> converter)
                 throws DataTypeException
Convert an object to a type.

Parameters:
from - The source object
converter - The data type converter
Returns:
The target type object
Throws:
DataTypeException - - When the conversion is not possible

convert

public static <T> T convert(Object from,
                            Class<? extends T> toClass)
                 throws DataTypeException
Convert an object to a type. These are the conversion rules:

Parameters:
from - The object to convert
toClass - The target type
Returns:
The converted object
Throws:
DataTypeException - - When the conversion is not possible

convert

public static <T> List<T> convert(List<?> list,
                                  Class<? extends T> type)
                       throws DataTypeException
Convert a list of objects to a list of T, using convert(Object, Class)

Parameters:
list - The list of objects
type - The target type
Returns:
The list of converted objects
Throws:
DataTypeException - - When the conversion is not possible
See Also:
convert(Object, Class)

convert

public static <U> List<U> convert(List<?> list,
                                  Converter<?,U> converter)
                       throws DataTypeException
Convert a list of objects to a list of T, using convert(Object, Converter)

Parameters:
list - The list of objects
converter - The data type converter
Returns:
The list of converted objects
Throws:
DataTypeException - - When the conversion is not possible
See Also:
convert(Object, Converter)


Copyright © 2012. All Rights Reserved.