Class CastingUtil


  • public abstract class CastingUtil
    extends Object
    • Field Detail

      • specialNames

        public static final String[] specialNames
      • tensNames

        public static final String[] tensNames
      • numNames

        public static final String[] numNames
      • _ObjectClass

        public static final Class<?> _ObjectClass
      • _ClassClass

        public static final Class<?> _ClassClass
      • _StringClass

        public static final Class<?> _StringClass
      • _NumberClass

        public static final Class<?> _NumberClass
      • _BigDecimalClass

        public static final Class<?> _BigDecimalClass
      • _BigIntegerClass

        public static final Class<?> _BigIntegerClass
      • _BooleanClass

        public static final Class<?> _BooleanClass
      • _DateClass

        public static final Class<?> _DateClass
      • _LocaleClass

        public static final Class<?> _LocaleClass
      • _ShortClass

        public static final Class<?> _ShortClass
      • _ByteClass

        public static final Class<?> _ByteClass
      • _IntegerClass

        public static final Class<?> _IntegerClass
      • _LongClass

        public static final Class<?> _LongClass
      • _DoubleClass

        public static final Class<?> _DoubleClass
      • _FloatClass

        public static final Class<?> _FloatClass
      • _VoidClass

        public static final Class<?> _VoidClass
      • _CharacterClass

        public static final Class<?> _CharacterClass
      • _shortOff

        public static final Short _shortOff
      • _shortOn

        public static final Short _shortOn
      • _zeroShort

        public static final Short _zeroShort
      • _zeroInteger

        public static final Integer _zeroInteger
      • _zeroDobule

        public static final Double _zeroDobule
      • _zeroBigDecimal

        public static final BigDecimal _zeroBigDecimal
      • _zeroBigInteger

        public static final BigInteger _zeroBigInteger
    • Constructor Detail

      • CastingUtil

        public CastingUtil()
    • Method Detail

      • getTargetClass

        public static Class<?> getTargetClass​(Class<?> type)
        Find implement class from given class for create object
        Parameters:
        field -
        type -
        Returns:
        Class
      • getTargetClass

        public static Class<?> getTargetClass​(Method field,
                                              Class<?> type)
        Find implement class from given class for create object
        Parameters:
        field -
        type -
        Returns:
        Class
      • getTargetClass

        public static Class<?> getTargetClass​(Field field,
                                              Class<?> type)
        Find implement class from given class for create object
        Parameters:
        field -
        type -
        Returns:
        Class
      • defaultValue

        public static Object defaultValue​(Field field)
      • shortValue

        public static short shortValue​(Object v)
        Returns an short value for the given object. It follows this sequence:
        null = 0
        String - if length=0, returns 0.
        If the string contains a decimal point, parse as
        BigDecimal(s).shortValue() representation of the object.
        Parameters:
        v - - some value object, can be null
        Returns:
        the short value represented by the object
      • intValue

        public static int intValue​(Object v)
        Returns an float value for the given object. It follows this sequence:
        null = 0
        String - if length=0, returns 0.
        If the string contains a decimal point, parse as
        BigDecimal(s).intValue() representation of the object.
        Parameters:
        v - - some value object, can be null
        Returns:
        the int value represented by the object
      • longValue

        public static long longValue​(Object v)
        Returns an long value for the given object. It follows this sequence:
        null = 0
        String - if length=0, returns 0.
        If the string contains a decimal point, parse as
        BigDecimal(s).longValue() representation of the object.
        Parameters:
        v - - some value object, can be null
        Returns:
        the long value represented by the object
      • floatValue

        public static float floatValue​(Object v)
        Returns an float value for the given object. It follows this sequence:
        null = 0.0f
        String - if length=0, returns 0.0f.
        If the string contains a decimal point, parse as
        BigDecimal(s).floatValue() representation of the object.
        Parameters:
        v - - some value object, can be null
        Returns:
        the float value represented by the object
      • doubleValue

        public static double doubleValue​(Object v)
        Returns an float value for the given object. It follows this sequence:
        null = 0.0
        String - if length=0, returns 0.0.
        If the string contains a decimal point, parse as
        BigDecimal(s).doubleValue() representation of the object.
        Parameters:
        v - - some value object, can be null
        Returns:
        the double value represented by the object
      • boolValue

        public static boolean boolValue​(String s)
      • boolValue

        public static boolean boolValue​(Object v)
        Returns an boolean value for the given object.
        It follows this sequence:
        null = false
        String - if length=0, returns false.
        Parameters:
        v - - some value object, can be null
        Returns:
        the boolean value represented by the object
      • stringValue

        public static String stringValue​(Object _value)
        Returns a String representing the object. This has special processing for arrays, which are rendered using the stringValueForArray method.
        Parameters:
        _value - - value to convert to a String
        Returns:
        a String representing the object _value
      • stringValueForArray

        public static String stringValueForArray​(Object[] _array)

        This method will return string for the specified array.

        Parameters:
        _array -
        Returns:
        String value by appendin all the elements in a string.
        Since:
        Brijframework 1.0
      • dateValue

        public static Date dateValue​(Object _v,
                                     int _style,
                                     Locale _locale)
        Returns a java.util.Date for the given object. This method checks:
        • for null, which is returned as null
        • for Date, which is returned as-is
        • for java.util.Calendar, getTime() will be called and returned
        • for String's. Which will get parsed using the default DateFormat.
        • for Number's, which are treated like ms since 1970
        All other objects are checked for a 'dateValue' method, which is then called.
        Parameters:
        _v - - some object
        _style - the given formatting style. For example, SHORT for "M/d/yy" in the US locale.
        _locale - the given locale.
        Returns:
        a java.util.Date or null
      • dateValue

        public static Date dateValue​(Object _v)
        Returns a java.util.Date for the given object. This method checks:
        • for null, which is returned as null
        • for Date, which is returned as-is
        • for java.util.Calendar, getTime() will be called and returned
        • for String's. Which will get parsed using the default DateFormat.
        • for Number's, which are treated like ms since 1970
        All other objects are checked for a 'dateValue' method, which is then called.
        Parameters:
        _v - - some object
        Returns:
        a java.util.Date or null
      • timeStampValue

        public static Date timeStampValue​(Object _v)
      • valueInt

        public static int valueInt​(Object _value)
      • valueFloat

        public static float valueFloat​(Object _value)
      • castObject

        public static <T> T castObject​(Object _value,
                                       Class<?> type,
                                       Class<?> paramType)
      • toDecimal

        public static String toDecimal​(String value,
                                       int base)
        Convert from Binary/Octal/Hexadecimal format to Decimal format.
        Parameters:
        value - Binary/Octal/Hexadecimal input
        base - 2/8/16 input
        Returns:
        its equivalent Decimal value
        Throws:
        NumberFormatException - If value is not corresponding to base argument.
      • decimalToAnyNumber

        public static String decimalToAnyNumber​(String value,
                                                int base)
        Convert from Decimal format to Binary/Octal/Hexadecimal format.
        Parameters:
        value - Decimal value
        base - 2/8/16
        Returns:
        its equivalent Binary/Octal/Hexadecimal value
        Throws:
        NumberFormatException - If value is not corresponding to base argument.
      • binaryToOctal

        public static String binaryToOctal​(String binary)
        Convert from Binary format to Octal format.
        Parameters:
        binary - Binary Number
        Returns:
        its equivalent Octal value
        Throws:
        NumberFormatException - If binary not in correct format.
      • binaryToHexa

        public static String binaryToHexa​(String binary)
        Convert from Binary format to Hexadecimal format.
        Parameters:
        binary - Binary Number
        Returns:
        its equivalent Hexadecimal value
        Throws:
        NumberFormatException - If binary not in correct format.
      • octalToBinary

        public static String octalToBinary​(String octal)
        Convert from Octal format to Binary format.
        Parameters:
        octal - Octal Number
        Returns:
        its equivalent Binary value
        Throws:
        NumberFormatException - If octal not in correct format.
      • octalToHexa

        public static String octalToHexa​(String octal)
        Convert from Octal format to Hexadecimal format.
        Parameters:
        octal - Octal Number
        Returns:
        its equivalent Hexadecimal value
        Throws:
        NumberFormatException - If octal not in correct format.
      • hexaToBinary

        public static String hexaToBinary​(String hexa)
        Convert from Hexadecimal format to Binary format.
        Parameters:
        hexa - Hexadecimal Number
        Returns:
        its equivalent Binary value
        Throws:
        NumberFormatException - If hexa not in correct format.
      • hexaToOctal

        public static String hexaToOctal​(String hexa)
        Convert from Hexadecimal format to Octal format.
        Parameters:
        hexa - Hexadecimal Number
        Returns:
        its equivalent Octal value
        Throws:
        NumberFormatException - If hexa not in correct format.
      • getDoubleFromString

        public static Double getDoubleFromString​(String val1)
      • getIntforBoolean

        public static int getIntforBoolean​(boolean value)
      • getBooleanValue

        public static boolean getBooleanValue​(Integer i)
      • toRadix

        public static String toRadix​(String integer,
                                     int inRadix,
                                     int outRadix)
        Converts a positive integer from one radix into another
        Parameters:
        in - positive integer
        inRadix - input Radix
        outRadix - output Radix
        Returns:
        positive integer equivalent to outRadix
      • byteArrayToHex

        public static String byteArrayToHex​(byte[] a)
        convert byte to hex
        Parameters:
        Byte - array which need to convert into hex string
        Returns:
        Hex String
      • dayInWord

        public static String dayInWord​(int day)
        Converts number into day word
        Parameters:
        number -
        Returns:
        String day
      • numberInWord

        public static String numberInWord​(long number)
        Converts number into String word
        Parameters:
        number -
        Returns:
        String word
      • integerForInt

        public static Integer integerForInt​(int i)
        Converts int value to Integer
        Parameters:
        i -
        Returns:
      • dobuleTOshort

        public static Object dobuleTOshort​(Double d)
      • convertNumberOrBooleanIntoCompatibleValue

        public static Object convertNumberOrBooleanIntoCompatibleValue​(Object obj,
                                                                       Class<?> class1)
        Converts objects(Boolean or Number) into compatible Object
        Parameters:
        boolean1 - Boolean
        class1 - Class
        Returns:
        Number
      • convertBooleanIntoCompatibleNumberValue

        public static Number convertBooleanIntoCompatibleNumberValue​(Boolean boolean1,
                                                                     Class<?> class1)
        Converts Boolean into compatible Number value
        Parameters:
        boolean1 - Boolean
        class1 - Class
        Returns:
        Number
      • convertNumberIntoCompatibleValue

        public static Number convertNumberIntoCompatibleValue​(Number number,
                                                              Class<?> class1)
        Converts Number into compatible Number value
        Parameters:
        number - Number
        class1 - Class
        Returns:
        Number
      • compareNumbersOrBooleans

        public static int compareNumbersOrBooleans​(Object obj,
                                                   Object obj1)
        Compares two objects(Boolean or Number ) and returns 0 if equal , 1 if number is greater than number1 and -1 if number is less than number1
        Parameters:
        obj - first object(Boolean or Number) to be compared
        obj1 - second object(Boolean or Number) with which first object to be compared
        Returns:
        int
      • compareNumbers

        public static int compareNumbers​(Number number,
                                         Number number1)
        Compares two numbers and returns 0 if equal , 1 if number is greater than number1 and -1 if number is less than number1
        Parameters:
        number - first number to be compared
        number1 - second number with which first number to be compared
        Returns:
        int
      • intOrLongValue

        public static Number intOrLongValue​(Object v)
        Returns an 'Integer' object if the value in v is small enough to fit, otherwise a 'Long' object. Note: this downsizes Long objects!
        Parameters:
        v - - some value, usually a Number
        Returns:
        null, an Integer or a Long object
      • listOfIntsOrLongs

        public static List<Number> listOfIntsOrLongs​(Collection<?> _objs)
        Returns an 'Integer' object if the value in v is small enough to fit, otherwise a 'Long' object. Note: this downsizes Long objects! if string consisting of alphabets is provided then it returns 0.
        Parameters:
        _objs - - some values, usually a List<Number>
        Returns:
        null, or a List of Integer or Long objects