public class EnumTypeCoercions
extends java.lang.Object
Constructor and Description |
---|
EnumTypeCoercions() |
Modifier and Type | Method and Description |
---|---|
static <E extends java.lang.Enum<E>> |
stringToEnum(java.lang.Class<E> type,
E defaultValue)
Type coercion
function for enums . |
static <T> <any> |
stringToEnumUntyped(java.lang.Class<? super T> type,
T defaultValue) |
static <E extends java.lang.Enum<E>> |
tryCoerce(java.lang.String input,
java.lang.Class<E> targetType) |
static Maybe |
tryCoerceUntyped(java.lang.String input,
java.lang.Class targetType) |
public static <E extends java.lang.Enum<E>> <any> stringToEnum(java.lang.Class<E> type, @Nullable E defaultValue)
function
for enums
.
Tries to convert the string to CaseFormat#UPPER_UNDERSCORE
first,
handling all of the different format
possibilites. Failing
that, it tries a case-insensitive comparison with the valid enum values.
Returns defaultValue
if the string cannot be converted.
tryCoerce(String, Class)
,
Enum.valueOf(Class, String)
public static <T> <any> stringToEnumUntyped(java.lang.Class<? super T> type, @Nullable T defaultValue)
public static Maybe tryCoerceUntyped(java.lang.String input, java.lang.Class targetType)
public static <E extends java.lang.Enum<E>> Maybe<E> tryCoerce(java.lang.String input, java.lang.Class<E> targetType)