Class TypeConverter
java.lang.Object
com.flowlogix.util.TypeConverter
Converts from any String to any type dynamically,
using
static valueOf(String input)
method of the target type,
or other methods with equivalent functionality
Accepts database special values, such as inf, -inf, and nan
Examples:
int one = TypeConverter.valueOf("1", int.class);
TT convertedValue = TypeConverter.valueOf(input, cls);
CheckedValue<TT> checkedValue = TypeConverter.checkAndConvert(input, cls);
if (checkedValue.isValid()) {
// get and operate on a value in a type-safe way
TT value = checkedValue.getValue();
}
- Author:
- lprimak
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <TT> TypeConverter.CheckedValue
<TT> checkAndConvert
(@NonNull String value, @NonNull Class<TT> type) check if string representation of the converted value actually matches inputstatic <TT> boolean
Check if conversion will succeedstatic <TT> TT
static Object
Convert string to object given a type name
-
Constructor Details
-
TypeConverter
public TypeConverter()
-
-
Method Details
-
valueOf
-
valueOf
public static Object valueOf(@NonNull @NonNull String strValue, @NonNull @NonNull String type) throws IllegalArgumentException Convert string to object given a type name- Parameters:
strValue
-type
-- Returns:
- object after conversion
- Throws:
IllegalArgumentException
-
checkType
-
checkAndConvert
-