Package org.brijframework.util.casting
Class CastingUtil
- java.lang.Object
-
- org.brijframework.util.casting.CastingUtil
-
public abstract class CastingUtil extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static Class<?>_BigDecimalClassstatic Class<?>_BigIntegerClassstatic Class<?>_BooleanClassstatic Class<?>_ByteClassstatic Class<?>_CharacterClassstatic Class<?>_ClassClassstatic Class<?>_DateClassstatic Class<?>_DoubleClassstatic Class<?>_FloatClassstatic Class<?>_IntegerClassstatic Class<?>_LocaleClassstatic Class<?>_LongClassstatic Class<?>_NumberClassstatic Class<?>_ObjectClassstatic Class<?>_ShortClassstatic Short_shortOffstatic Short_shortOnstatic Class<?>_StringClassstatic Class<?>_VoidClassstatic BigDecimal_zeroBigDecimalstatic BigInteger_zeroBigIntegerstatic Double_zeroDobulestatic Integer_zeroIntegerstatic Short_zeroShortstatic String[]numNamesstatic String[]specialNamesstatic String[]tensNames
-
Constructor Summary
Constructors Constructor Description CastingUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringbinaryToHexa(String binary)Convert from Binary format to Hexadecimal format.static StringbinaryToOctal(String binary)Convert from Binary format to Octal format.static booleanboolValue(Object v)Returns an boolean value for the given object.static booleanboolValue(String s)static StringbyteArrayToHex(byte[] a)convert byte to hexstatic ObjectcastObject(Object _value, Class<?> type)static <T> TcastObject(Object _value, Class<?> type, Class<?> paramType)static ObjectcastObject(Object _value, Type type)static intcompareNumbers(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 number1static intcompareNumbersOrBooleans(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 number1static NumberconvertBooleanIntoCompatibleNumberValue(Boolean boolean1, Class<?> class1)static NumberconvertBooleanIntoNumberValue(Boolean boolean1)static BooleanconvertNumberIntoBooleanValue(Number number)static NumberconvertNumberIntoCompatibleValue(Number number, Class<?> class1)static ObjectconvertNumberOrBooleanIntoCompatibleValue(Object obj, Class<?> class1)Converts objects(Boolean or Number) into compatibleObjectstatic DatedateValue(Object _v)Returns a java.util.Date for the given object.static DatedateValue(Object _v, int _style, Locale _locale)Returns a java.util.Date for the given object.static StringdayInWord(int day)Converts number into day wordstatic StringdecimalToAnyNumber(String value, int base)Convert from Decimal format to Binary/Octal/Hexadecimal format.static ObjectdefaultValue(Field field)static ObjectdobuleTOshort(Double d)static doubledoubleValue(Object v)Returns an float value for the given object.static floatfloatValue(Object v)Returns an float value for the given object.static booleangetBooleanValue(Integer i)static DoublegetDoubleFromDict(Hashtable<?,?> hash, String key)static DoublegetDoubleFromString(String val1)static intgetIntforBoolean(boolean value)static Class<?>getTargetClass(Class<?> type)Find implement class from given class for create objectstatic Class<?>getTargetClass(Field field, Class<?> type)Find implement class from given class for create objectstatic Class<?>getTargetClass(Method field, Class<?> type)Find implement class from given class for create objectstatic StringhexaToBinary(String hexa)Convert from Hexadecimal format to Binary format.static StringhexaToOctal(String hexa)Convert from Hexadecimal format to Octal format.static IntegerintegerForInt(int i)Convertsintvalue toIntegerstatic NumberintOrLongValue(Object v)Returns an 'Integer' object if the value in v is small enough to fit, otherwise a 'Long' object.static intintValue(Object v)Returns an float value for the given object.static List<Number>listOfIntsOrLongs(Collection<?> _objs)Returns an 'Integer' object if the value in v is small enough to fit, otherwise a 'Long' object.static longlongValue(Object v)Returns an long value for the given object.static StringnumberInWord(long number)Converts number into String wordstatic StringoctalToBinary(String octal)Convert from Octal format to Binary format.static StringoctalToHexa(String octal)Convert from Octal format to Hexadecimal format.static shortshortValue(Object v)Returns an short value for the given object.static StringstringValue(Object _value)Returns a String representing the object.static StringstringValueForArray(Object[] _array)This method will return string for the specified array.static DatetimeStampValue(Object _v)static TimestamptimeStampValue(Object _v, int _style, Locale _locale)static StringtoDecimal(String value, int base)Convert from Binary/Octal/Hexadecimal format to Decimal format.static StringtoRadix(String integer, int inRadix, int outRadix)Converts a positive integer from one radix into anotherstatic floatvalueFloat(Object _value)static intvalueInt(Object _value)
-
-
-
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
-
-
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
-
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
- 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
- Parameters:
_v- - some object- Returns:
- a java.util.Date or null
-
valueInt
public static int valueInt(Object _value)
-
valueFloat
public static float valueFloat(Object _value)
-
toDecimal
public static String toDecimal(String value, int base)
Convert from Binary/Octal/Hexadecimal format to Decimal format.- Parameters:
value- Binary/Octal/Hexadecimal inputbase- 2/8/16 input- Returns:
- its equivalent Decimal value
- Throws:
NumberFormatException- Ifvalueis not corresponding tobaseargument.
-
decimalToAnyNumber
public static String decimalToAnyNumber(String value, int base)
Convert from Decimal format to Binary/Octal/Hexadecimal format.- Parameters:
value- Decimal valuebase- 2/8/16- Returns:
- its equivalent Binary/Octal/Hexadecimal value
- Throws:
NumberFormatException- Ifvalueis not corresponding tobaseargument.
-
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- Ifbinarynot 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- Ifbinarynot 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- Ifoctalnot 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- Ifoctalnot 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- Ifhexanot 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- Ifhexanot in correct format.
-
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 integerinRadix- input RadixoutRadix- 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)
Convertsintvalue toInteger- Parameters:
i-- Returns:
-
convertNumberOrBooleanIntoCompatibleValue
public static Object convertNumberOrBooleanIntoCompatibleValue(Object obj, Class<?> class1)
Converts objects(Boolean or Number) into compatibleObject
-
convertBooleanIntoCompatibleNumberValue
public static Number convertBooleanIntoCompatibleNumberValue(Boolean boolean1, Class<?> class1)
-
convertNumberIntoCompatibleValue
public static Number convertNumberIntoCompatibleValue(Number number, Class<?> class1)
-
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 comparedobj1- 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 comparednumber1- 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
-
-