Package com.helger.commons.typeconvert
Class TypeConverter
java.lang.Object
com.helger.commons.typeconvert.TypeConverter
- All Implemented Interfaces:
IHasConditionalLogger
Helper class for converting base types likes "boolean" to object types like
"Boolean".
Uses
Uses
TypeConverterRegistry.getFuzzyConverter(Class, Class) for
retrieving a registered converter. If no converter is found, it is checked
whether a mapping from a primitive type to an object type exists.- Author:
- Philip Helger
-
Method Summary
Modifier and TypeMethodDescriptionstatic <DSTTYPE> DSTTYPEstatic <DSTTYPE> DSTTYPEstatic <DSTTYPE> DSTTYPEstatic <DSTTYPE> DSTTYPEstatic <DSTTYPE> DSTTYPEstatic <DSTTYPE> DSTTYPEstatic <DSTTYPE> DSTTYPEstatic <DSTTYPE> DSTTYPEstatic <DSTTYPE> DSTTYPEconvert(ITypeConverterProvider aTypeConverterProvider, Object aSrcValue, Class<DSTTYPE> aDstClass) Convert the passed source value to the destination class, if a conversion is necessary.static <DSTTYPE> DSTTYPEconvert(ITypeConverterProvider aTypeConverterProvider, Object aSrcValue, Class<DSTTYPE> aDstClass, DSTTYPE aDefault) Convert the passed source value to the destination class, if a conversion is necessary.static <DSTTYPE> DSTTYPEConvert the passed source value to the destination class using the best match type converter provider, if a conversion is necessary.static <DSTTYPE> DSTTYPEConvert the passed source value to the destination class using the best match type converter provider, if a conversion is necessary.static booleanconvertToBoolean(Object aSrcValue) Convert the passed source value to booleanstatic booleanconvertToBoolean(Object aSrcValue, boolean bDefault) Convert the passed source value to booleanstatic byteconvertToByte(Object aSrcValue) Convert the passed source value to bytestatic byteconvertToByte(Object aSrcValue, byte nDefault) Convert the passed source value to bytestatic charconvertToChar(Object aSrcValue) Convert the passed source value to charstatic charconvertToChar(Object aSrcValue, char cDefault) Convert the passed source value to charstatic doubleconvertToDouble(Object aSrcValue) Convert the passed source value to doublestatic doubleconvertToDouble(Object aSrcValue, double dDefault) Convert the passed source value to doublestatic floatconvertToFloat(Object aSrcValue) Convert the passed source value to floatstatic floatconvertToFloat(Object aSrcValue, float fDefault) Convert the passed source value to floatstatic intconvertToInt(Object aSrcValue) Convert the passed source value to intstatic intconvertToInt(Object aSrcValue, int nDefault) Convert the passed source value to intstatic longconvertToLong(Object aSrcValue) Convert the passed source value to longstatic longconvertToLong(Object aSrcValue, long nDefault) Convert the passed source value to longstatic shortconvertToShort(Object aSrcValue) Convert the passed source value to shortstatic shortconvertToShort(Object aSrcValue, short nDefault) Convert the passed source value to shortstatic booleanstatic booleansetSilentMode(boolean bSilentMode) Enable or disable certain regular log messages.
-
Method Details
-
isSilentMode
public static boolean isSilentMode()- Returns:
trueif logging is disabled,falseif it is enabled.- Since:
- 9.4.0
-
setSilentMode
public static boolean setSilentMode(boolean bSilentMode) Enable or disable certain regular log messages.- Parameters:
bSilentMode-trueto disable logging,falseto enable logging- Returns:
- The previous value of the silent mode.
- Since:
- 9.4.0
-
convert
-
convert
-
convert
-
convert
-
convert
-
convert
-
convert
-
convert
-
convertToBoolean
Convert the passed source value to boolean- Parameters:
aSrcValue- The source value. May not benull.- Returns:
- The converted value.
- Throws:
TypeConverterException- if the source value isnullor if no converter was found or if the converter returned anullobject.RuntimeException- If the converter itself throws an exception- See Also:
-
convertToBoolean
Convert the passed source value to boolean- Parameters:
aSrcValue- The source value. May benull.bDefault- The default value to be returned if an error occurs during type conversion.- Returns:
nullif the source value wasnull.- Throws:
RuntimeException- If the converter itself throws an exception- See Also:
-
convertToByte
Convert the passed source value to byte- Parameters:
aSrcValue- The source value. May not benull.- Returns:
- The converted value.
- Throws:
TypeConverterException- if the source value isnullor if no converter was found or if the converter returned anullobject.RuntimeException- If the converter itself throws an exception- See Also:
-
convertToByte
Convert the passed source value to byte- Parameters:
aSrcValue- The source value. May benull.nDefault- The default value to be returned if an error occurs during type conversion.- Returns:
- The converted value.
- Throws:
RuntimeException- If the converter itself throws an exception- See Also:
-
convertToChar
Convert the passed source value to char- Parameters:
aSrcValue- The source value. May not benull.- Returns:
- The converted value.
- Throws:
TypeConverterException- if the source value isnullor if no converter was found or if the converter returned anullobject.RuntimeException- If the converter itself throws an exception- See Also:
-
convertToChar
Convert the passed source value to char- Parameters:
aSrcValue- The source value. May benull.cDefault- The default value to be returned if an error occurs during type conversion.- Returns:
- The converted value.
- Throws:
RuntimeException- If the converter itself throws an exception- See Also:
-
convertToDouble
Convert the passed source value to double- Parameters:
aSrcValue- The source value. May not benull.- Returns:
- The converted value.
- Throws:
TypeConverterException- if the source value isnullor if no converter was found or if the converter returned anullobject.RuntimeException- If the converter itself throws an exception- See Also:
-
convertToDouble
Convert the passed source value to double- Parameters:
aSrcValue- The source value. May benull.dDefault- The default value to be returned if an error occurs during type conversion.- Returns:
- The converted value.
- Throws:
RuntimeException- If the converter itself throws an exception- See Also:
-
convertToFloat
Convert the passed source value to float- Parameters:
aSrcValue- The source value. May not benull.- Returns:
- The converted value.
- Throws:
TypeConverterException- if the source value isnullor if no converter was found or if the converter returned anullobject.RuntimeException- If the converter itself throws an exception- See Also:
-
convertToFloat
Convert the passed source value to float- Parameters:
aSrcValue- The source value. May benull.fDefault- The default value to be returned if an error occurs during type conversion.- Returns:
- The converted value.
- Throws:
RuntimeException- If the converter itself throws an exception- See Also:
-
convertToInt
Convert the passed source value to int- Parameters:
aSrcValue- The source value. May not benull.- Returns:
- The converted value.
- Throws:
TypeConverterException- if the source value isnullor if no converter was found or if the converter returned anullobject.RuntimeException- If the converter itself throws an exception- See Also:
-
convertToInt
Convert the passed source value to int- Parameters:
aSrcValue- The source value. May benull.nDefault- The default value to be returned if an error occurs during type conversion.- Returns:
- The converted value.
- Throws:
RuntimeException- If the converter itself throws an exception- See Also:
-
convertToLong
Convert the passed source value to long- Parameters:
aSrcValue- The source value. May not benull.- Returns:
- The converted value.
- Throws:
TypeConverterException- if the source value isnullor if no converter was found or if the converter returned anullobject.RuntimeException- If the converter itself throws an exception- See Also:
-
convertToLong
Convert the passed source value to long- Parameters:
aSrcValue- The source value. May benull.nDefault- The default value to be returned if an error occurs during type conversion.- Returns:
- The converted value.
- Throws:
RuntimeException- If the converter itself throws an exception- See Also:
-
convertToShort
Convert the passed source value to short- Parameters:
aSrcValue- The source value. May not benull.- Returns:
- The converted value.
- Throws:
TypeConverterException- if the source value isnullor if no converter was found or if the converter returned anullobject.RuntimeException- If the converter itself throws an exception- See Also:
-
convertToShort
Convert the passed source value to short- Parameters:
aSrcValue- The source value. May benull.nDefault- The default value to be returned if an error occurs during type conversion.- Returns:
- The converted value.
- Throws:
RuntimeException- If the converter itself throws an exception- See Also:
-
convert
@Nullable public static <DSTTYPE> DSTTYPE convert(@Nullable Object aSrcValue, @Nonnull Class<DSTTYPE> aDstClass) Convert the passed source value to the destination class using the best match type converter provider, if a conversion is necessary.- Type Parameters:
DSTTYPE- The destination type.- Parameters:
aSrcValue- The source value. May benull.aDstClass- The destination class to use.- Returns:
nullif the source value wasnull.- Throws:
TypeConverterException- If no converter was found or if the converter returned anullobject.RuntimeException- If the converter itself throws an exception- See Also:
-
convert
@Nullable public static <DSTTYPE> DSTTYPE convert(@Nonnull ITypeConverterProvider aTypeConverterProvider, @Nullable Object aSrcValue, @Nonnull Class<DSTTYPE> aDstClass) Convert the passed source value to the destination class, if a conversion is necessary.- Type Parameters:
DSTTYPE- The destination type.- Parameters:
aTypeConverterProvider- The type converter provider. May not benull.aSrcValue- The source value. May benull.aDstClass- The destination class to use.- Returns:
nullif the source value wasnull.- Throws:
TypeConverterException- If no converter was found or if the converter returned anullobject.RuntimeException- If the converter itself throws an exception
-
convert
@Nullable public static <DSTTYPE> DSTTYPE convert(@Nullable Object aSrcValue, @Nonnull Class<DSTTYPE> aDstClass, @Nullable DSTTYPE aDefault) Convert the passed source value to the destination class using the best match type converter provider, if a conversion is necessary.- Type Parameters:
DSTTYPE- The destination type.- Parameters:
aSrcValue- The source value. May benull.aDstClass- The destination class to use.aDefault- The default value to be returned, if anTypeConverterExceptionoccurs.- Returns:
nullif the source value wasnullor the default value isnull.- Throws:
RuntimeException- If the converter itself throws an exception- See Also:
-
convert
@Nullable public static <DSTTYPE> DSTTYPE convert(@Nonnull ITypeConverterProvider aTypeConverterProvider, @Nullable Object aSrcValue, @Nonnull Class<DSTTYPE> aDstClass, @Nullable DSTTYPE aDefault) Convert the passed source value to the destination class, if a conversion is necessary.- Type Parameters:
DSTTYPE- The destination type.- Parameters:
aTypeConverterProvider- The type converter provider. May not benull.aSrcValue- The source value. May benull.aDstClass- The destination class to use.aDefault- The default value to be returned, if anTypeConverterExceptionoccurs.- Returns:
nullif the source value wasnullor the default value isnull.- Throws:
RuntimeException- If the converter itself throws an exception
-