Package net.minidev.asm
Class DefaultConverter
- java.lang.Object
-
- net.minidev.asm.DefaultConverter
-
public class DefaultConverter extends java.lang.ObjectProvides utility methods to convert objects to different primitive types and their wrapper classes. It supports conversion fromNumberinstances andStringrepresentations of numbers to their corresponding primitive types or wrapper classes. Conversion from types that are not supported will result in aConvertException.
-
-
Constructor Summary
Constructors Constructor Description DefaultConverter()Default constructor
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanconvertTobool(java.lang.Object obj)Converts the given object to aboolean.static java.lang.BooleanconvertToBool(java.lang.Object obj)Converts the given object to aBoolean.static byteconvertTobyte(java.lang.Object obj)Converts the given object to abyte.static java.lang.ByteconvertToByte(java.lang.Object obj)Converts the given object to aByte.static charconvertTochar(java.lang.Object obj)Converts the given object to achar.static java.lang.CharacterconvertToChar(java.lang.Object obj)Converts the given object to aCharacter.static doubleconvertTodouble(java.lang.Object obj)Converts the given object to adouble.static java.lang.DoubleconvertToDouble(java.lang.Object obj)Converts the given object to aDouble.static floatconvertTofloat(java.lang.Object obj)Converts the given object to afloat.static java.lang.FloatconvertToFloat(java.lang.Object obj)Converts the given object to aByte.static intconvertToint(java.lang.Object obj)Converts the given object to anint.static java.lang.IntegerconvertToInt(java.lang.Object obj)Converts the given object to anInteger.static longconvertTolong(java.lang.Object obj)Converts the given object to along.static java.lang.LongconvertToLong(java.lang.Object obj)Converts the given object to aLong.static shortconvertToshort(java.lang.Object obj)Converts the given object to ashort.static java.lang.ShortconvertToShort(java.lang.Object obj)Converts the given object to ashort.
-
-
-
Method Detail
-
convertToint
public static int convertToint(java.lang.Object obj)
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
public static java.lang.Integer convertToInt(java.lang.Object obj)
Converts the given object to anInteger.- Parameters:
obj- the object to convert- Returns:
- the converted Integer, or
nullif the object isnull - 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 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
public static java.lang.Short convertToShort(java.lang.Object obj)
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
public static long convertTolong(java.lang.Object obj)
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
public static java.lang.Long convertToLong(java.lang.Object obj)
Converts the given object to aLong.- Parameters:
obj- the object to convert- Returns:
- the converted Long, or
nullif the object isnull - 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 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
public static java.lang.Byte convertToByte(java.lang.Object obj)
Converts the given object to aByte.- Parameters:
obj- the object to convert- Returns:
- the converted Byte, or
nullif the object isnull - 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 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
public static java.lang.Float convertToFloat(java.lang.Object obj)
Converts the given object to aByte.- Parameters:
obj- the object to convert- Returns:
- the converted Byte, or
nullif the object isnull - 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 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
public static java.lang.Double convertToDouble(java.lang.Object obj)
Converts the given object to aDouble.- Parameters:
obj- the object to convert- Returns:
- the converted Double, or
nullif the object isnull - 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 achar.- Parameters:
obj- the object to convert- Returns:
- the converted char value, or a space character if the object is
nullor 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 aCharacter.- Parameters:
obj- the object to convert- Returns:
- the converted Character, or
nullif the object isnull - 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 aboolean.- Parameters:
obj- the object to convert- Returns:
- the converted boolean value, false if the object is
nullor 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 aBoolean.- Parameters:
obj- the object to convert- Returns:
- the converted Boolean, or
nullif the object isnull - Throws:
ConvertException- if the object cannot be converted to a Boolean
-
-