Package com.hotels.beans.conversion
Interface Converter
- All Known Implementing Classes:
ConverterImpl
public interface Converter
It allows to convert any primitive type into another.
-
Method Summary
Modifier and Type Method Description <T, K> K
convertValue(T valueToConvert, Class<K> targetClass)
Converts a given primitive value into the given primitive type.Optional<Function<Object,Object>>
getConversionFunction(Class<?> sourceClass, Class<?> targetClass)
It provides a conversion function for the given primitive type into the other.
-
Method Details
-
getConversionFunction
Optional<Function<Object,Object>> getConversionFunction(Class<?> sourceClass, Class<?> targetClass)It provides a conversion function for the given primitive type into the other.- Parameters:
sourceClass
- source field classtargetClass
- the destination field class- Returns:
- an
Optional
containing the conversion function (if exists)
-
convertValue
Converts a given primitive value into the given primitive type.- Type Parameters:
T
- the value to convert typeK
- the target object type- Parameters:
valueToConvert
- the value to be convertedtargetClass
- the destination field class- Returns:
- the converted value
- Throws:
TypeConversionException
- in case there is no converter for the given classIllegalArgumentException
- in case the destination field type is null.
-