@Immutable public final class TypeConverter extends Object
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.| Modifier and Type | Method and Description |
|---|---|
static <DSTTYPE> DSTTYPE |
convert(boolean aSrcValue,
Class<DSTTYPE> aDstClass) |
static <DSTTYPE> DSTTYPE |
convert(byte aSrcValue,
Class<DSTTYPE> aDstClass) |
static <DSTTYPE> DSTTYPE |
convert(char aSrcValue,
Class<DSTTYPE> aDstClass) |
static <DSTTYPE> DSTTYPE |
convert(double aSrcValue,
Class<DSTTYPE> aDstClass) |
static <DSTTYPE> DSTTYPE |
convert(float aSrcValue,
Class<DSTTYPE> aDstClass) |
static <DSTTYPE> DSTTYPE |
convert(int aSrcValue,
Class<DSTTYPE> aDstClass) |
static <DSTTYPE> DSTTYPE |
convert(ITypeConverterProvider aTypeConverterProvider,
Object aSrcValue,
Class<DSTTYPE> aDstClass)
Convert the passed source value to the destination class, if a conversion
is necessary.
|
static <DSTTYPE> DSTTYPE |
convert(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> DSTTYPE |
convert(long aSrcValue,
Class<DSTTYPE> aDstClass) |
static <DSTTYPE> DSTTYPE |
convert(Object aSrcValue,
Class<DSTTYPE> aDstClass)
Convert the passed source value to the destination class using the best
match type converter provider, if a conversion is necessary.
|
static <DSTTYPE> DSTTYPE |
convert(Object aSrcValue,
Class<DSTTYPE> aDstClass,
DSTTYPE aDefault)
Convert the passed source value to the destination class using the best
match type converter provider, if a conversion is necessary.
|
static <DSTTYPE> DSTTYPE |
convert(short aSrcValue,
Class<DSTTYPE> aDstClass) |
static boolean |
convertToBoolean(Object aSrcValue)
Convert the passed source value to boolean
|
static boolean |
convertToBoolean(Object aSrcValue,
boolean bDefault)
Convert the passed source value to boolean
|
static byte |
convertToByte(Object aSrcValue)
Convert the passed source value to byte
|
static byte |
convertToByte(Object aSrcValue,
byte nDefault)
Convert the passed source value to byte
|
static char |
convertToChar(Object aSrcValue)
Convert the passed source value to char
|
static char |
convertToChar(Object aSrcValue,
char cDefault)
Convert the passed source value to char
|
static double |
convertToDouble(Object aSrcValue)
Convert the passed source value to double
|
static double |
convertToDouble(Object aSrcValue,
double dDefault)
Convert the passed source value to double
|
static float |
convertToFloat(Object aSrcValue)
Convert the passed source value to float
|
static float |
convertToFloat(Object aSrcValue,
float fDefault)
Convert the passed source value to float
|
static int |
convertToInt(Object aSrcValue)
Convert the passed source value to int
|
static int |
convertToInt(Object aSrcValue,
int nDefault)
Convert the passed source value to int
|
static long |
convertToLong(Object aSrcValue)
Convert the passed source value to long
|
static long |
convertToLong(Object aSrcValue,
long nDefault)
Convert the passed source value to long
|
static short |
convertToShort(Object aSrcValue)
Convert the passed source value to short
|
static short |
convertToShort(Object aSrcValue,
short nDefault)
Convert the passed source value to short
|
static boolean |
isSilentMode() |
static boolean |
setSilentMode(boolean bSilentMode)
Enable or disable certain regular log messages.
|
public static boolean isSilentMode()
true if logging is disabled, false if it
is enabled.public static boolean setSilentMode(boolean bSilentMode)
bSilentMode - true to disable logging, false to enable
logging@Nullable public static <DSTTYPE> DSTTYPE convert(boolean aSrcValue, @Nonnull Class<DSTTYPE> aDstClass)
@Nullable public static <DSTTYPE> DSTTYPE convert(byte aSrcValue, @Nonnull Class<DSTTYPE> aDstClass)
@Nullable public static <DSTTYPE> DSTTYPE convert(char aSrcValue, @Nonnull Class<DSTTYPE> aDstClass)
@Nullable public static <DSTTYPE> DSTTYPE convert(double aSrcValue, @Nonnull Class<DSTTYPE> aDstClass)
@Nullable public static <DSTTYPE> DSTTYPE convert(float aSrcValue, @Nonnull Class<DSTTYPE> aDstClass)
@Nullable public static <DSTTYPE> DSTTYPE convert(int aSrcValue, @Nonnull Class<DSTTYPE> aDstClass)
@Nullable public static <DSTTYPE> DSTTYPE convert(long aSrcValue, @Nonnull Class<DSTTYPE> aDstClass)
@Nullable public static <DSTTYPE> DSTTYPE convert(short aSrcValue, @Nonnull Class<DSTTYPE> aDstClass)
public static boolean convertToBoolean(@Nonnull Object aSrcValue)
aSrcValue - The source value. May not be null.TypeConverterException - if the source value is null or if no converter was
found or if the converter returned a null object.RuntimeException - If the converter itself throws an exceptionTypeConverterProviderBestMatchpublic static boolean convertToBoolean(@Nullable Object aSrcValue, boolean bDefault)
aSrcValue - The source value. May be null.bDefault - The default value to be returned if an error occurs during type
conversion.null if the source value was null.RuntimeException - If the converter itself throws an exceptionTypeConverterProviderBestMatchpublic static byte convertToByte(@Nonnull Object aSrcValue)
aSrcValue - The source value. May not be null.TypeConverterException - if the source value is null or if no converter was
found or if the converter returned a null object.RuntimeException - If the converter itself throws an exceptionTypeConverterProviderBestMatchpublic static byte convertToByte(@Nullable Object aSrcValue, byte nDefault)
aSrcValue - The source value. May be null.nDefault - The default value to be returned if an error occurs during type
conversion.RuntimeException - If the converter itself throws an exceptionTypeConverterProviderBestMatchpublic static char convertToChar(@Nonnull Object aSrcValue)
aSrcValue - The source value. May not be null.TypeConverterException - if the source value is null or if no converter was
found or if the converter returned a null object.RuntimeException - If the converter itself throws an exceptionTypeConverterProviderBestMatchpublic static char convertToChar(@Nullable Object aSrcValue, char cDefault)
aSrcValue - The source value. May be null.cDefault - The default value to be returned if an error occurs during type
conversion.RuntimeException - If the converter itself throws an exceptionTypeConverterProviderBestMatchpublic static double convertToDouble(@Nonnull Object aSrcValue)
aSrcValue - The source value. May not be null.TypeConverterException - if the source value is null or if no converter was
found or if the converter returned a null object.RuntimeException - If the converter itself throws an exceptionTypeConverterProviderBestMatchpublic static double convertToDouble(@Nullable Object aSrcValue, double dDefault)
aSrcValue - The source value. May be null.dDefault - The default value to be returned if an error occurs during type
conversion.RuntimeException - If the converter itself throws an exceptionTypeConverterProviderBestMatchpublic static float convertToFloat(@Nonnull Object aSrcValue)
aSrcValue - The source value. May not be null.TypeConverterException - if the source value is null or if no converter was
found or if the converter returned a null object.RuntimeException - If the converter itself throws an exceptionTypeConverterProviderBestMatchpublic static float convertToFloat(@Nullable Object aSrcValue, float fDefault)
aSrcValue - The source value. May be null.fDefault - The default value to be returned if an error occurs during type
conversion.RuntimeException - If the converter itself throws an exceptionTypeConverterProviderBestMatchpublic static int convertToInt(@Nonnull Object aSrcValue)
aSrcValue - The source value. May not be null.TypeConverterException - if the source value is null or if no converter was
found or if the converter returned a null object.RuntimeException - If the converter itself throws an exceptionTypeConverterProviderBestMatchpublic static int convertToInt(@Nullable Object aSrcValue, int nDefault)
aSrcValue - The source value. May be null.nDefault - The default value to be returned if an error occurs during type
conversion.RuntimeException - If the converter itself throws an exceptionTypeConverterProviderBestMatchpublic static long convertToLong(@Nonnull Object aSrcValue)
aSrcValue - The source value. May not be null.TypeConverterException - if the source value is null or if no converter was
found or if the converter returned a null object.RuntimeException - If the converter itself throws an exceptionTypeConverterProviderBestMatchpublic static long convertToLong(@Nullable Object aSrcValue, long nDefault)
aSrcValue - The source value. May be null.nDefault - The default value to be returned if an error occurs during type
conversion.RuntimeException - If the converter itself throws an exceptionTypeConverterProviderBestMatchpublic static short convertToShort(@Nonnull Object aSrcValue)
aSrcValue - The source value. May not be null.TypeConverterException - if the source value is null or if no converter was
found or if the converter returned a null object.RuntimeException - If the converter itself throws an exceptionTypeConverterProviderBestMatchpublic static short convertToShort(@Nullable Object aSrcValue, short nDefault)
aSrcValue - The source value. May be null.nDefault - The default value to be returned if an error occurs during type
conversion.RuntimeException - If the converter itself throws an exceptionTypeConverterProviderBestMatch@Nullable public static <DSTTYPE> DSTTYPE convert(@Nullable Object aSrcValue, @Nonnull Class<DSTTYPE> aDstClass)
DSTTYPE - The destination type.aSrcValue - The source value. May be null.aDstClass - The destination class to use.null if the source value was null.TypeConverterException - If no converter was found or if the converter returned a
null object.RuntimeException - If the converter itself throws an exceptionTypeConverterProviderBestMatch@Nullable public static <DSTTYPE> DSTTYPE convert(@Nonnull ITypeConverterProvider aTypeConverterProvider, @Nullable Object aSrcValue, @Nonnull Class<DSTTYPE> aDstClass)
DSTTYPE - The destination type.aTypeConverterProvider - The type converter provider. May not be null.aSrcValue - The source value. May be null.aDstClass - The destination class to use.null if the source value was null.TypeConverterException - If no converter was found or if the converter returned a
null object.RuntimeException - If the converter itself throws an exception@Nullable public static <DSTTYPE> DSTTYPE convert(@Nullable Object aSrcValue, @Nonnull Class<DSTTYPE> aDstClass, @Nullable DSTTYPE aDefault)
DSTTYPE - The destination type.aSrcValue - The source value. May be null.aDstClass - The destination class to use.aDefault - The default value to be returned, if an
TypeConverterException occurs.null if the source value was null or the
default value is null.RuntimeException - If the converter itself throws an exceptionTypeConverterProviderBestMatch@Nullable public static <DSTTYPE> DSTTYPE convert(@Nonnull ITypeConverterProvider aTypeConverterProvider, @Nullable Object aSrcValue, @Nonnull Class<DSTTYPE> aDstClass, @Nullable DSTTYPE aDefault)
DSTTYPE - The destination type.aTypeConverterProvider - The type converter provider. May not be null.aSrcValue - The source value. May be null.aDstClass - The destination class to use.aDefault - The default value to be returned, if an
TypeConverterException occurs.null if the source value was null or the
default value is null.RuntimeException - If the converter itself throws an exceptionCopyright © 2014–2020 Philip Helger. All rights reserved.