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> com.google.common.base.Function<java.lang.String,T> |
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 <T> Maybe<T> |
tryCoerceUntyped(java.lang.String input,
java.lang.Class<T> targetType) |
public static <E extends java.lang.Enum<E>> com.google.common.base.Function<java.lang.String,E> 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.
TypeCoercions#coerce(Object, Class)
,
Enum.valueOf(Class, String)
public static <T> com.google.common.base.Function<java.lang.String,T> stringToEnumUntyped(java.lang.Class<? super T> type, @Nullable T defaultValue)
public static <T> Maybe<T> tryCoerceUntyped(java.lang.String input, java.lang.Class<T> targetType)
public static <E extends java.lang.Enum<E>> Maybe<E> tryCoerce(java.lang.String input, java.lang.Class<E> targetType)