Class ConvertUtil


  • public class ConvertUtil
    extends java.lang.Object
    This class offers utility conversion methods.
    Since:
    4.0.4
    Version:
    $Revision: 24221 $ $Date: 2020-11-09 20:23:09 -0300 (Mon, 09 Nov 2020) $
    • Constructor Summary

      Constructors 
      Constructor Description
      ConvertUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T,​R extends java.util.Collection<T>>
      java.util.Collection<T>
      convert​(java.lang.Class<T> valueType, java.lang.Iterable input, R output, java.util.Locale locale, java.lang.String pattern)  
      static <T> T convert​(java.lang.Class<T> type, java.lang.Object value, java.util.Locale locale, java.lang.String pattern)  
      static <T> java.util.List<T> convertAsList​(java.lang.Class<T> valueType, java.lang.Object value, java.util.Locale locale, java.lang.String pattern)
      Converts the given value as a list.
      If the given value is Iterable, then its inner elements will be converted to <T>, using convert(Class, Object, Locale, String), and then they will be added in a result List.
      If the given value is not Iterable, then it will be converted and then it will be added to a result List.
      The result list is Serializable and modifiable.
      static IConverter createConverter​(java.lang.Class type)
      Create the appropriated converter for the given type.
      static void deregister​(java.lang.Class type)  
      static void register​(java.lang.Class type, java.lang.Class<? extends IConverter> converterClass)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DELEGATE_TO_REGISTERED_CONVERTER

        public static final IConverter DELEGATE_TO_REGISTERED_CONVERTER
        A converter that delegates calls to it to a registered converter.
        Since:
        4.0.4
        See Also:
        DelegateToRegisteredConverter
    • Constructor Detail

      • ConvertUtil

        public ConvertUtil()
    • Method Detail

      • register

        public static void register​(java.lang.Class type,
                                    java.lang.Class<? extends IConverter> converterClass)
      • deregister

        public static void deregister​(java.lang.Class type)
      • createConverter

        public static IConverter createConverter​(java.lang.Class type)
                                          throws UnsupportedConversionTypeException
        Create the appropriated converter for the given type.
        Parameters:
        type - the type that needs to be converted.
        Returns:
        an instance of the appropriated converter for the given type.
        Throws:
        UnsupportedConversionTypeException - if the conversion is not supported.
        Since:
        6.0.0
      • convert

        public static <T> T convert​(java.lang.Class<T> type,
                                    java.lang.Object value,
                                    java.util.Locale locale,
                                    java.lang.String pattern)
      • convert

        public static <T,​R extends java.util.Collection<T>> java.util.Collection<T> convert​(java.lang.Class<T> valueType,
                                                                                                  java.lang.Iterable input,
                                                                                                  R output,
                                                                                                  java.util.Locale locale,
                                                                                                  java.lang.String pattern)
      • convertAsList

        public static <T> java.util.List<T> convertAsList​(java.lang.Class<T> valueType,
                                                          java.lang.Object value,
                                                          java.util.Locale locale,
                                                          java.lang.String pattern)
        Converts the given value as a list.
        If the given value is Iterable, then its inner elements will be converted to <T>, using convert(Class, Object, Locale, String), and then they will be added in a result List.
        If the given value is not Iterable, then it will be converted and then it will be added to a result List.
        The result list is Serializable and modifiable.
        Parameters:
        valueType - the value type class.
        value - the value itself, either a raw value or an iterable of raw values.
        locale - the locale.
        pattern - the pattern.
        Returns:
        the result list.
        Since:
        11.0.0