Class Enums
java.lang.Object
com.google.common.base.Enums
Utility methods for working with
Enum instances.- Since:
- 9.0
- Author:
- Steve McKay
-
Method Summary
Modifier and TypeMethodDescriptionstatic FieldReturns theFieldin whichenumValueis defined.getIfPresent(Class<T> enumClass, String value) Returns an optional enum constant for the given type, usingEnum.valueOf(Class, String).stringConverter(Class<T> enumClass) Returns a serializable converter that converts between strings andenumvalues of typeenumClassusingEnum.valueOf(Class, String)andEnum.name().
-
Method Details
-
getField
-
getIfPresent
Returns an optional enum constant for the given type, usingEnum.valueOf(Class, String). If the constant does not exist,Optional.absent()is returned. A common use case is for parsing user input or falling back to a default enum constant. For example,Enums.getIfPresent(Country.class, countryInput).or(Country.DEFAULT);- Since:
- 12.0
-
stringConverter
Returns a serializable converter that converts between strings andenumvalues of typeenumClassusingEnum.valueOf(Class, String)andEnum.name(). The converter will throw anIllegalArgumentExceptionif the argument is not the name of any enum constant in the specified enum.- Since:
- 16.0
-