public final class ValueConversionHelper extends Object
Number type (Integer, Character, Double, byte, etc.)StringBooleanCharacterIncompatibleTypeException| Constructor and Description |
|---|
ValueConversionHelper() |
| Modifier and Type | Method and Description |
|---|---|
static Set<Class<?>> |
collectCompatibleTargetTypes(Class<?> fromType) |
static @NotNull Set<Class<?>> |
collectRegisteredCompatibleTargetTypes(Class<?> fromType)
Determines to which types the specified value (its type) can be converted to.
|
static @NotNull Object[] |
convert(Object[] args,
Class<?>[] targetTypes,
boolean useOriginalValueWhenIncompatible)
Converts a list of values to their converted form, as indicated by the specified targetTypes.
|
static <T> T |
convert(@Nullable Object fromValue,
Class<T> targetType)
Converts a single value into a target output datatype.
|
static boolean |
isCommonType(Class<?> c) |
static boolean |
isPrimitiveNumber(Class<?> targetType)
Returns whether a
Class is a primitive number. |
static void |
registerValueConverter(ValueFunction<?,?> userConverter)
Registers a user-provided converter.
|
static void |
resetDefaultConverters() |
static boolean |
typesCompatible(Class<?> fromType,
Class<?> targetType) |
public static void resetDefaultConverters()
public static void registerValueConverter(ValueFunction<?,?> userConverter)
int,
double is automatically supported as well as common conversion.public static boolean isCommonType(Class<?> c)
@NotNull public static @NotNull Set<Class<?>> collectRegisteredCompatibleTargetTypes(Class<?> fromType)
Object.toString().fromType - The input type to find compatible conversion output types forpublic static boolean typesCompatible(Class<?> fromType, Class<?> targetType)
targetType can be derived from fromType.public static Set<Class<?>> collectCompatibleTargetTypes(Class<?> fromType)
@NotNull public static @NotNull Object[] convert(Object[] args, Class<?>[] targetTypes, boolean useOriginalValueWhenIncompatible) throws IncompatibleTypeException
args - The list with value to convert.targetTypes - The output types the specified values should be converted into.useOriginalValueWhenIncompatible - Indicates whether an exception should be thrown for inconvertible values or that the original
value should be used instead. Basically change mode to "convert what you can".IncompatibleTypeException - Thrown when unable to convert and not use the original value.@Nullable
public static <T> T convert(@Nullable
@Nullable Object fromValue,
Class<T> targetType)
throws IncompatibleTypeException
collectRegisteredCompatibleTargetTypes(Class).String (value.toString())fromValue - The value to convert.targetType - The target data type the value should be converted into.IncompatibleTypeException - Thrown by the various convert() methods used.Copyright © 2019. All rights reserved.