Package org.keycloak.models.map.common
Class CastUtils
- java.lang.Object
-
- org.keycloak.models.map.common.CastUtils
-
public class CastUtils extends Object
This class contains utility classes for type conversion.- Author:
- hmlnarik
-
-
Constructor Summary
Constructors Constructor Description CastUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T
cast(Object value, Class<T> toClass)
Converts value to destination class (if it can).static <E extends Enum<E>>
Function<?,?>getCastFunc(Class<?> fromClass, Class<?> toClass)
Provides a function to convert value of a given class to destination class (if it can).
-
-
-
Method Detail
-
cast
public static <T> T cast(Object value, Class<T> toClass)
Converts value to destination class (if it can).- Parameters:
value
- Value to converttoClass
- Class to convert value to- Returns:
- Value converted to the given class
- Throws:
IllegalStateException
- if the value cannot be converted to the requested class
-
getCastFunc
public static <E extends Enum<E>> Function<?,?> getCastFunc(Class<?> fromClass, Class<?> toClass)
Provides a function to convert value of a given class to destination class (if it can).- Parameters:
fromClass
- Class to convert value fromtoClass
- Class to convert value to- Returns:
- Function
fromClass -> toClass
converting values from thefromClass
to thetoClass
- Throws:
IllegalStateException
- if the value cannot be converted to the requested class
-
-