Class ObjectConverter


  • public class ObjectConverter
    extends Object
    Since:
    3.2.0
    Author:
    Gianmarco Laggia @ Larus B.A.
    • Method Detail

      • convert

        public static <T> T convert​(Object from,
                                    Class<T> to)
        Convert the given object value to the given class.
        Type Parameters:
        T - the destination type of the conversion
        Parameters:
        from - The object value to be converted.
        to - The type class which the given object should be converted to.
        Returns:
        The converted object value.
        Throws:
        NullPointerException - If 'to' is null.
        UnsupportedOperationException - If no suitable converter can be found.
        RuntimeException - If conversion failed somehow. This can be caused by at least an ExceptionInInitializerError, IllegalAccessException or InvocationTargetException.
      • anyToMap

        public static Map anyToMap​(Object value)
        Cast an object to a map
        Parameters:
        value - the object to convert
        Returns:
        the converted Map
      • integerToBoolean

        public static Boolean integerToBoolean​(Integer value)
        Converts Integer to Boolean. If integer value is 0, then return FALSE, else return TRUE.
        Parameters:
        value - The Integer to be converted.
        Returns:
        The converted Boolean value.
      • booleanToInteger

        public static Integer booleanToInteger​(Boolean value)
        Converts Boolean to Integer. If boolean value is TRUE, then return 1, else return 0.
        Parameters:
        value - The Boolean to be converted.
        Returns:
        The converted Integer value.
      • booleanToShort

        public static Short booleanToShort​(Boolean value)
        Converts Boolean to Short. If boolean value is TRUE, then return 1, else return 0.
        Parameters:
        value - The Boolean to be converted.
        Returns:
        The converted Short value.
      • booleanToDouble

        public static Double booleanToDouble​(Boolean value)
        Converts Boolean to Double. If boolean value is TRUE, then return 1, else return 0.
        Parameters:
        value - The Boolean to be converted.
        Returns:
        The converted Double value.
      • booleanToFloat

        public static Float booleanToFloat​(Boolean value)
        Converts Boolean to Float. If boolean value is TRUE, then return 1, else return 0.
        Parameters:
        value - The Boolean to be converted.
        Returns:
        The converted Float value.
      • booleanToLong

        public static Long booleanToLong​(Boolean value)
        Converts Boolean to Long. If boolean value is TRUE, then return 1, else return 0.
        Parameters:
        value - The Boolean to be converted.
        Returns:
        The converted Long value.
      • integerToString

        public static String integerToString​(Integer value)
        Converts Integer to String.
        Parameters:
        value - The Integer to be converted.
        Returns:
        The converted String value.
      • longToString

        public static String longToString​(Long value)
        Converts Long to String.
        Parameters:
        value - The Long to be converted.
        Returns:
        The converted String value.
      • stringToInteger

        public static Integer stringToInteger​(String value)
        Converts String to Integer.
        Parameters:
        value - The String to be converted.
        Returns:
        The converted Integer value.
      • stringToLong

        public static Long stringToLong​(String value)
        Converts String to Long.
        Parameters:
        value - The String to be converted.
        Returns:
        The converted Long value.
      • longToFloat

        public static Float longToFloat​(Long value)
        Converts Long to Float.
        Parameters:
        value - The Long to be converted.
        Returns:
        The converted Float value.
      • longToShort

        public static Short longToShort​(Long value)
        Converts Long to Short.
        Parameters:
        value - The Long to be converted.
        Returns:
        The converted Short value.
      • longToInteger

        public static Integer longToInteger​(Long value)
        Converts Long to Integer.
        Parameters:
        value - The Long to be converted.
        Returns:
        The converted Integer value.
      • stringToFloat

        public static Float stringToFloat​(String value)
        Converts String to Float.
        Parameters:
        value - The String to be converted.
        Returns:
        The converted Float value.
      • booleanToString

        public static String booleanToString​(Boolean value)
        Converts Boolean to String.
        Parameters:
        value - The Boolean to be converted.
        Returns:
        The converted String value.
      • stringToBoolean

        public static Boolean stringToBoolean​(String value)
        Converts String to Boolean.
        Parameters:
        value - The String to be converted.
        Returns:
        The converted Boolean value.
      • longToDouble

        public static Double longToDouble​(Long value)
        Converts Long to Double.
        Parameters:
        value - The Long to be converted.
        Returns:
        The converted Double value.
      • stringToDouble

        public static Double stringToDouble​(String value)
        Converts String to Double.
        Parameters:
        value - The String to be converted.
        Returns:
        The converted Double value.
      • stringToShort

        public static Short stringToShort​(String value)
        Converts String to Short.
        Parameters:
        value - The String to be converted.
        Returns:
        The converted Short value.