Class DefaultConverter


  • public class DefaultConverter
    extends java.lang.Object
    Provides utility methods to convert objects to different primitive types and their wrapper classes. It supports conversion from Number instances and String representations of numbers to their corresponding primitive types or wrapper classes. Conversion from types that are not supported will result in a ConvertException.
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultConverter()
      Default constructor
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean convertTobool​(java.lang.Object obj)
      Converts the given object to a boolean.
      static java.lang.Boolean convertToBool​(java.lang.Object obj)
      Converts the given object to a Boolean.
      static byte convertTobyte​(java.lang.Object obj)
      Converts the given object to a byte.
      static java.lang.Byte convertToByte​(java.lang.Object obj)
      Converts the given object to a Byte.
      static char convertTochar​(java.lang.Object obj)
      Converts the given object to a char.
      static java.lang.Character convertToChar​(java.lang.Object obj)
      Converts the given object to a Character.
      static double convertTodouble​(java.lang.Object obj)
      Converts the given object to a double.
      static java.lang.Double convertToDouble​(java.lang.Object obj)
      Converts the given object to a Double.
      static float convertTofloat​(java.lang.Object obj)
      Converts the given object to a float.
      static java.lang.Float convertToFloat​(java.lang.Object obj)
      Converts the given object to a Byte.
      static int convertToint​(java.lang.Object obj)
      Converts the given object to an int.
      static java.lang.Integer convertToInt​(java.lang.Object obj)
      Converts the given object to an Integer.
      static long convertTolong​(java.lang.Object obj)
      Converts the given object to a long.
      static java.lang.Long convertToLong​(java.lang.Object obj)
      Converts the given object to a Long.
      static short convertToshort​(java.lang.Object obj)
      Converts the given object to a short.
      static java.lang.Short convertToShort​(java.lang.Object obj)
      Converts the given object to a short.
      • Methods inherited from class java.lang.Object

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

      • DefaultConverter

        public DefaultConverter()
        Default constructor
    • Method Detail

      • convertToint

        public static int convertToint​(java.lang.Object obj)
        Converts the given object to an int.
        Parameters:
        obj - the object to convert
        Returns:
        the converted int value, or 0 if the object is null
        Throws:
        ConvertException - if the object cannot be converted to an int
      • convertToInt

        public static java.lang.Integer convertToInt​(java.lang.Object obj)
        Converts the given object to an Integer.
        Parameters:
        obj - the object to convert
        Returns:
        the converted Integer, or null if the object is null
        Throws:
        ConvertException - if the object cannot be converted to an Integer
      • convertToshort

        public static short convertToshort​(java.lang.Object obj)
        Converts the given object to a short.
        Parameters:
        obj - the object to convert
        Returns:
        the converted short value, or 0 if the object is null
        Throws:
        ConvertException - if the object cannot be converted to a short
      • convertToShort

        public static java.lang.Short convertToShort​(java.lang.Object obj)
        Converts the given object to a short.
        Parameters:
        obj - the object to convert
        Returns:
        the converted short value, or 0 if the object is null
        Throws:
        ConvertException - if the object cannot be converted to a short
      • convertTolong

        public static long convertTolong​(java.lang.Object obj)
        Converts the given object to a long.
        Parameters:
        obj - the object to convert
        Returns:
        the converted long value, or 0 if the object is null
        Throws:
        ConvertException - if the object cannot be converted to a long
      • convertToLong

        public static java.lang.Long convertToLong​(java.lang.Object obj)
        Converts the given object to a Long.
        Parameters:
        obj - the object to convert
        Returns:
        the converted Long, or null if the object is null
        Throws:
        ConvertException - if the object cannot be converted to a Long
      • convertTobyte

        public static byte convertTobyte​(java.lang.Object obj)
        Converts the given object to a byte.
        Parameters:
        obj - the object to convert
        Returns:
        the converted byte value, or 0 if the object is null
        Throws:
        ConvertException - if the object cannot be converted to a byte
      • convertToByte

        public static java.lang.Byte convertToByte​(java.lang.Object obj)
        Converts the given object to a Byte.
        Parameters:
        obj - the object to convert
        Returns:
        the converted Byte, or null if the object is null
        Throws:
        ConvertException - if the object cannot be converted to a Byte
      • convertTofloat

        public static float convertTofloat​(java.lang.Object obj)
        Converts the given object to a float.
        Parameters:
        obj - the object to convert
        Returns:
        the converted float value, or 0f if the object is null
        Throws:
        ConvertException - if the object cannot be converted to a float
      • convertToFloat

        public static java.lang.Float convertToFloat​(java.lang.Object obj)
        Converts the given object to a Byte.
        Parameters:
        obj - the object to convert
        Returns:
        the converted Byte, or null if the object is null
        Throws:
        ConvertException - if the object cannot be converted to a Byte
      • convertTodouble

        public static double convertTodouble​(java.lang.Object obj)
        Converts the given object to a double.
        Parameters:
        obj - the object to convert
        Returns:
        the converted double value, or 0.0 if the object is null
        Throws:
        ConvertException - if the object cannot be converted to a double
      • convertToDouble

        public static java.lang.Double convertToDouble​(java.lang.Object obj)
        Converts the given object to a Double.
        Parameters:
        obj - the object to convert
        Returns:
        the converted Double, or null if the object is null
        Throws:
        ConvertException - if the object cannot be converted to a Double
      • convertTochar

        public static char convertTochar​(java.lang.Object obj)
        Converts the given object to a char.
        Parameters:
        obj - the object to convert
        Returns:
        the converted char value, or a space character if the object is null or the string is empty
        Throws:
        ConvertException - if the object cannot be converted to a char
      • convertToChar

        public static java.lang.Character convertToChar​(java.lang.Object obj)
        Converts the given object to a Character.
        Parameters:
        obj - the object to convert
        Returns:
        the converted Character, or null if the object is null
        Throws:
        ConvertException - if the object cannot be converted to a Character
      • convertTobool

        public static boolean convertTobool​(java.lang.Object obj)
        Converts the given object to a boolean.
        Parameters:
        obj - the object to convert
        Returns:
        the converted boolean value, false if the object is null or represents the numeric value 0
        Throws:
        ConvertException - if the object cannot be converted to a boolean
      • convertToBool

        public static java.lang.Boolean convertToBool​(java.lang.Object obj)
        Converts the given object to a Boolean.
        Parameters:
        obj - the object to convert
        Returns:
        the converted Boolean, or null if the object is null
        Throws:
        ConvertException - if the object cannot be converted to a Boolean