Package net.minidev.asm
Class DefaultConverter
java.lang.Object
net.minidev.asm.DefaultConverter
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
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
convertTobool
(Object obj) Converts the given object to aboolean
.static Boolean
convertToBool
(Object obj) Converts the given object to aBoolean
.static byte
convertTobyte
(Object obj) Converts the given object to abyte
.static Byte
convertToByte
(Object obj) Converts the given object to aByte
.static char
convertTochar
(Object obj) Converts the given object to achar
.static Character
convertToChar
(Object obj) Converts the given object to aCharacter
.static double
convertTodouble
(Object obj) Converts the given object to adouble
.static Double
convertToDouble
(Object obj) Converts the given object to aDouble
.static float
convertTofloat
(Object obj) Converts the given object to afloat
.static Float
convertToFloat
(Object obj) Converts the given object to aByte
.static int
convertToint
(Object obj) Converts the given object to anint
.static Integer
convertToInt
(Object obj) Converts the given object to anInteger
.static long
convertTolong
(Object obj) Converts the given object to along
.static Long
convertToLong
(Object obj) Converts the given object to aLong
.static short
convertToshort
(Object obj) Converts the given object to ashort
.static Short
convertToShort
(Object obj) Converts the given object to ashort
.
-
Constructor Details
-
DefaultConverter
public DefaultConverter()Default constructor
-
-
Method Details
-
convertToint
Converts the given object to anint
.- 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
Converts the given object to anInteger
.- Parameters:
obj
- the object to convert- Returns:
- the converted Integer, or
null
if the object isnull
- Throws:
ConvertException
- if the object cannot be converted to an Integer
-
convertToshort
Converts the given object to ashort
.- 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
Converts the given object to ashort
.- 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
Converts the given object to along
.- 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
Converts the given object to aLong
.- Parameters:
obj
- the object to convert- Returns:
- the converted Long, or
null
if the object isnull
- Throws:
ConvertException
- if the object cannot be converted to a Long
-
convertTobyte
Converts the given object to abyte
.- 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
Converts the given object to aByte
.- Parameters:
obj
- the object to convert- Returns:
- the converted Byte, or
null
if the object isnull
- Throws:
ConvertException
- if the object cannot be converted to a Byte
-
convertTofloat
Converts the given object to afloat
.- 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
Converts the given object to aByte
.- Parameters:
obj
- the object to convert- Returns:
- the converted Byte, or
null
if the object isnull
- Throws:
ConvertException
- if the object cannot be converted to a Byte
-
convertTodouble
Converts the given object to adouble
.- 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
Converts the given object to aDouble
.- Parameters:
obj
- the object to convert- Returns:
- the converted Double, or
null
if the object isnull
- Throws:
ConvertException
- if the object cannot be converted to a Double
-
convertTochar
Converts the given object to achar
.- 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
Converts the given object to aCharacter
.- Parameters:
obj
- the object to convert- Returns:
- the converted Character, or
null
if the object isnull
- Throws:
ConvertException
- if the object cannot be converted to a Character
-
convertTobool
Converts the given object to aboolean
.- 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
Converts the given object to aBoolean
.- Parameters:
obj
- the object to convert- Returns:
- the converted Boolean, or
null
if the object isnull
- Throws:
ConvertException
- if the object cannot be converted to a Boolean
-