Package com.google.common.base
Class Enums
java.lang.Object
com.google.common.base.Enums
Utility methods for working with
Enum instances.- Since:
- 9.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classEnums.StringConverter<T extends Enum<T>> -
Field Summary
FieldsModifier and TypeFieldDescription -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static <T extends Enum<T>>
Map<String,WeakReference<? extends Enum<?>>> getEnumConstants(Class<T> enumClass) static FieldReturns theFieldin whichenumValueis defined.getIfPresent(Class<T> enumClass, String value) Returns an optional enum constant for the given type, usingEnum.valueOf(java.lang.Class<T>, java.lang.String).private static <T extends Enum<T>>
Map<String,WeakReference<? extends Enum<?>>> populateCache(Class<T> enumClass) stringConverter(Class<T> enumClass) Returns a converter that converts between strings andenumvalues of typeenumClassusingEnum.valueOf(Class, String)andEnum.name().
-
Field Details
-
enumConstantCache
-
-
Constructor Details
-
Enums
private Enums()
-
-
Method Details
-
getField
Returns theFieldin whichenumValueis defined. For example, to get theDescriptionannotation on theGOLFconstant of enumSport, useEnums.getField(Sport.GOLF).getAnnotation(Description.class).- Since:
- 12.0
-
getIfPresent
Returns an optional enum constant for the given type, usingEnum.valueOf(java.lang.Class<T>, java.lang.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
-
populateCache
-
getEnumConstants
-
stringConverter
Returns a 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
-